By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,318 Members | 2,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,318 IT Pros & Developers. It's quick & easy.

Cannot control the width of the label control

P: n/a
Hi There,

I am trying to get some fields to align on a web page, like this,

To:
From:
Subject:

Each of the fields above have a corresponding asp:Textbox control next
to it that I cannot get to lign up. I have this code,

<asp:Label Runat="server" Width="100px" ID="Label6">To: </
asp:Label>
<asp:TextBox ID="Textbox1" Runat="server" Width="200px" />
<asp:Label Runat="server" ID="Label7" ForeColor=red Width="5px">*</
asp:Label>

So that means I have tried to tell it that I want the asp:label
control to be 100 pixels wide, but it seems to shrink the label width
to fit the text.

Please help.

Sep 3 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I once had that problem too, and I found that the problem is that the
element must also be a block element. To solve your problem, add the
following attribute:

style="display:inline-block;"

This will solve your problem. I add this attribute to many of my Label
controls when creating input forms, because it is more efficient than making
a table if you only have a few fields (not to mention specifying the
dimensions of table cells has given me more frustration than any other
layout aspect). Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"BobLaughland" <pe*************@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
Hi There,

I am trying to get some fields to align on a web page, like this,

To:
From:
Subject:

Each of the fields above have a corresponding asp:Textbox control next
to it that I cannot get to lign up. I have this code,

<asp:Label Runat="server" Width="100px" ID="Label6">To: </
asp:Label>
<asp:TextBox ID="Textbox1" Runat="server" Width="200px" />
<asp:Label Runat="server" ID="Label7" ForeColor=red Width="5px">*</
asp:Label>

So that means I have tried to tell it that I want the asp:label
control to be 100 pixels wide, but it seems to shrink the label width
to fit the text.

Please help.

Sep 3 '07 #2

P: n/a
On Sep 4, 11:38 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I once had that problem too, and I found that the problem is that the
element must also be a block element. To solve your problem, add the
following attribute:

style="display:inline-block;"

This will solve your problem. I add this attribute to many of my Label
controls when creating input forms, because it is more efficient than making
a table if you only have a few fields (not to mention specifying the
dimensions of table cells has given me more frustration than any other
layout aspect). Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

"BobLaughland" <peter.mcclym...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegro ups.com...
Hi There,
I am trying to get some fields to align on a web page, like this,
To:
From:
Subject:
Each of the fields above have a corresponding asp:Textbox control next
to it that I cannot get to lign up. I have this code,
<asp:Label Runat="server" Width="100px" ID="Label6">To: </
asp:Label>
<asp:TextBox ID="Textbox1" Runat="server" Width="200px" />
<asp:Label Runat="server" ID="Label7" ForeColor=red Width="5px">*</
asp:Label>
So that means I have tried to tell it that I want the asp:label
control to be 100 pixels wide, but it seems to shrink the label width
to fit the text.
Please help.- Hide quoted text -

- Show quoted text -
Great, you are on the money.

I have a CSS file which I want to put it into. How do I do that?

The label I want to control is wrapped in side a div.

<div class="EmailEntry">
<asp:Label Runat="server" ID="Label1" >To: </asp:Label>
<asp:TextBox ID="ToField" Runat="server" Width=80% />
..............
.............
</div>

So if I put this into my css why does it not work?

div.emailentry label
{
display: inline-block; /* or inline block, which ever one you
think looks better */
width: 80px;
}

I have also tried 'div.emailentry label1' but that didn't work either.

Sep 4 '07 #3

P: n/a
On 4 , 03:27, BobLaughland <peter.mcclym...@gmail.comwrote:
On Sep 4, 11:38 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I once had that problem too, and I found that the problem is that the
element must also be a block element. To solve your problem, add the
following attribute:
style="display:inline-block;"
This will solve your problem. I add this attribute to many of my Label
controls when creating input forms, because it is more efficient than making
a table if you only have a few fields (not to mention specifying the
dimensions of table cells has given me more frustration than any other
layout aspect). Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/
"BobLaughland" <peter.mcclym...@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
Hi There,
I am trying to get some fields to align on a web page, like this,
To:
From:
Subject:
Each of the fields above have a corresponding asp:Textbox control next
to it that I cannot get to lign up. I have this code,
<asp:Label Runat="server" Width="100px" ID="Label6">To: </
asp:Label>
<asp:TextBox ID="Textbox1" Runat="server" Width="200px" />
<asp:Label Runat="server" ID="Label7" ForeColor=red Width="5px">*</
asp:Label>
So that means I have tried to tell it that I want the asp:label
control to be 100 pixels wide, but it seems to shrink the label width
to fit the text.
Please help.- Hide quoted text -
- Show quoted text -

Great, you are on the money.

I have a CSS file which I want to put it into. How do I do that?

The label I want to control is wrapped in side a div.

<div class="EmailEntry">
<asp:Label Runat="server" ID="Label1" >To: </asp:Label>
<asp:TextBox ID="ToField" Runat="server" Width=80% />
.............
............
</div>

So if I put this into my css why does it not work?

div.emailentry label
{
display: inline-block; /* or inline block, which ever one you
think looks better */
width: 80px;

}

I have also tried 'div.emailentry label1' but that didn't work either.
Try this:

<style>
div.EmailEntry span
{
width: 80px;
float:left;
}
div.EmailEntry input
{
margin-left: 100px; /*indent from left side*/
display:block;
width: 80%;
}
</style>

Mykola
http://marss.co.ua

Sep 4 '07 #4

P: n/a
<asp:labeldoes not generate a <label(for which there is no asp.net
control) but rather a <span>.

-- bruce (sqlwork.com)

BobLaughland wrote:
On Sep 4, 11:38 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
>I once had that problem too, and I found that the problem is that the
element must also be a block element. To solve your problem, add the
following attribute:

style="display:inline-block;"

This will solve your problem. I add this attribute to many of my Label
controls when creating input forms, because it is more efficient than making
a table if you only have a few fields (not to mention specifying the
dimensions of table cells has given me more frustration than any other
layout aspect). Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

"BobLaughland" <peter.mcclym...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegr oups.com...
>>Hi There,
I am trying to get some fields to align on a web page, like this,
To:
From:
Subject:
Each of the fields above have a corresponding asp:Textbox control next
to it that I cannot get to lign up. I have this code,
<asp:Label Runat="server" Width="100px" ID="Label6">To: </
asp:Label>
<asp:TextBox ID="Textbox1" Runat="server" Width="200px" />
<asp:Label Runat="server" ID="Label7" ForeColor=red Width="5px">*</
asp:Label>
So that means I have tried to tell it that I want the asp:label
control to be 100 pixels wide, but it seems to shrink the label width
to fit the text.
Please help.- Hide quoted text -
- Show quoted text -

Great, you are on the money.

I have a CSS file which I want to put it into. How do I do that?

The label I want to control is wrapped in side a div.

<div class="EmailEntry">
<asp:Label Runat="server" ID="Label1" >To: </asp:Label>
<asp:TextBox ID="ToField" Runat="server" Width=80% />
.............
............
</div>

So if I put this into my css why does it not work?

div.emailentry label
{
display: inline-block; /* or inline block, which ever one you
think looks better */
width: 80px;
}

I have also tried 'div.emailentry label1' but that didn't work either.
Sep 4 '07 #5

P: n/a
My recommendation would be to use a CSS class, like the following:

..FixedWidthLabel{display:inline-block;}

And then apply that class to each of the Label controls you want by using
the CssClass property, such as:

<asp:Label Runat="server" Width="100px" ID="Label6" Text="To:"
CssClass="FixedWidthLabel"/>

If you would like to place the width in the CSS class as well, you may want
to do that as well, since it sounds like you want them all to be the same
width, but that is obviously your choice. Hopefully this helps. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"BobLaughland" <pe*************@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
On Sep 4, 11:38 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
>I once had that problem too, and I found that the problem is that the
element must also be a block element. To solve your problem, add the
following attribute:

style="display:inline-block;"

This will solve your problem. I add this attribute to many of my Label
controls when creating input forms, because it is more efficient than
making
a table if you only have a few fields (not to mention specifying the
dimensions of table cells has given me more frustration than any other
layout aspect). Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

"BobLaughland" <peter.mcclym...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegr oups.com...
Hi There,
I am trying to get some fields to align on a web page, like this,
To:
From:
Subject:
Each of the fields above have a corresponding asp:Textbox control next
to it that I cannot get to lign up. I have this code,
<asp:Label Runat="server" Width="100px" ID="Label6">To: </
asp:Label>
<asp:TextBox ID="Textbox1" Runat="server" Width="200px" />
<asp:Label Runat="server" ID="Label7" ForeColor=red Width="5px">*</
asp:Label>
So that means I have tried to tell it that I want the asp:label
control to be 100 pixels wide, but it seems to shrink the label width
to fit the text.
Please help.- Hide quoted text -

- Show quoted text -

Great, you are on the money.

I have a CSS file which I want to put it into. How do I do that?

The label I want to control is wrapped in side a div.

<div class="EmailEntry">
<asp:Label Runat="server" ID="Label1" >To: </asp:Label>
<asp:TextBox ID="ToField" Runat="server" Width=80% />
.............
............
</div>

So if I put this into my css why does it not work?

div.emailentry label
{
display: inline-block; /* or inline block, which ever one you
think looks better */
width: 80px;
}

I have also tried 'div.emailentry label1' but that didn't work either.

Sep 4 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.