Reputation: 32853
I have an HTML form [here][1]. I am setting label's display to inline
and width
to 200px
but it does not get the width. How can I give width so that it takes it?
Here is my form
<form>
<div>
<label>Name</label>
<input type="text" />
<label>Organization</label>
<input type="text" />
</div>
<div>
<label>E-mail</label>
<input type="text" />
<label>Phone</label>
<input type="text" />
</div>
</form>
And the CSS:
label {
display: inline;
width: 200px;
}
Upvotes: 2
Views: 672
Reputation: 37179
You cannot give a width
to an inline
element. You have to set its display
to inline-block
if you want it to be inline and have a width.
Changing your CSS to
label {
display: inline-block;
width: 200px;
}
makes it work.
live demo: http://dabblet.com/gist/3149758
Upvotes: 5
Reputation: 4275
Anyways label is already a inline elements so there is no use of setting style to display:inline;
.
if you want to add width first make the element a block element. you can do this by using display:inline-block
or use display:block; & float:left;
Fiddle demo: http://jsfiddle.net/surendraVsingh/eZH5C/1/
Upvotes: 0
Reputation: 49
Please use this.
label {
width: 200px ;
display:inline;
float:left;
}
input[type="text"]{
float:left;
}
Upvotes: 0
Reputation: 21882
The inline property won't read width. You need to use display: block;
or display: inline-block;
for the width to be read.
Upvotes: 1
Reputation: 943561
The width property does not apply to inline, non-replaced elements.
Don't set the display to inline. You might like inline-block instead.
Upvotes: 2