Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put a <label> over a textbox control in ASP.Net using CSS?

Tags:

html

css

asp.net

I'm trying to create one row with some text boxes with label's over them like this:

enter image description here

How do I align the labels up with the text boxes?

        <label>Student ID</label>
        <asp:TextBox ID="txtStudentID" runat="server"></asp:TextBox>
        <label>Student Last Name</label>
        <asp:TextBox ID="txtStuLastName" runat="server"></asp:TextBox>
        <label>Student First Name</label>
        <asp:TextBox ID="txtStuFirstName" runat="server"></asp:TextBox>

Here's my current CSS.

.boxround label {
    display: block;        
    float: left;
}

This is what I current get:

enter image description here

Thank you.

like image 534
JM1 Avatar asked Oct 23 '25 03:10

JM1


1 Answers

It would be better if you enclosed each group inside a div.

For example:

<div class="form-group">
   <label>Student ID</label>
   <asp:TextBox ID="txtStudentID" runat="server"></asp:TextBox>
</div>

And apply the following CSS for class 'form-group':

.form-group{
   display: inline-block;
   margin-right: 10px;
   float:left;
}

.form-group label{
   display: block;
}
<div class="form-group">
  <label>Student ID</label>
  <input type="text">
</div>
<div class="form-group">
  <label>Student ID</label>
  <input type="text">
</div>
<div class="form-group">
  <label>Student ID</label>
  <input type="text">
</div>

Alternatively, you could also make use of display: flex-box (there's a comprehensive guide here).

Hope that helped!

like image 146
demitinay Avatar answered Oct 25 '25 19:10

demitinay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!