Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the width of a label in HTML?

Tags:

html

css

I'm using the following HTML code to create a form but the width of the "phone" label seems to be ignored no matter what I set it to. I've set it explicitly to 50px.

enter image description here

<div name="VGroup968" style="position:absolute;left:36px;top:54px;width:380px;height:166px;">
    <div style="padding-bottom:6px"><div name="HGroup568" style="width:180px;height:23px;">
        <div style="display:inline;padding-right:2px"><label name="Label589" style="position:relative;vertical-align: middle;width:50px;height:12px;font-family:Arial;font-size:12px;">Phone</label></div>
        <div style="display:inline;"><input type="input" name="TextInput547" style="width:120px;height:22px;font-family:Arial;font-size:12px;padding:0;border:1px solid #696969;"/></div>
    </div></div>
    <div style="padding-bottom:6px"><div name="HGroup616" style="width:180px;height:23px;">
        <div style="display:inline;padding-right:2px"><label name="Label665" style="position:relative;vertical-align: middle;width:50px;height:12px;font-family:Arial;font-size:12px;">Message</label></div>
        <div style="display:inline;"><input type="input" name="TextInput554" style="width:120px;height:22px;font-family:Arial;font-size:12px;padding:0;border:1px solid #696969;"/></div>
    </div></div>

Is there something I'm missing? http://jsfiddle.net/EsdQB/1/

like image 746
1.21 gigawatts Avatar asked Oct 07 '13 22:10

1.21 gigawatts


1 Answers

The width property does not apply to non-replaced inline elements (such as label).

Add display: inline-block and it will work.

FIDDLE

From the w3c spec on the width property:

Applies to: all elements but non-replaced inline elements, table rows, and row groups

Also, see this answer which roughly sums up that non-replaced inline elements - means:

inline elements that can contain text like <a>, <span> <label> etc.

like image 116
Danield Avatar answered Nov 15 '22 07:11

Danield