Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS not getting applied to <label>

Tags:

html

css

I am developing a form and setting a size for the label and aligning it right so as to look decent. However the CSS is not getting applied. Here is my code:

label{
    width: 50%;
    text-align: right;
}

Fiddle

How do I get this working?

like image 749
Rahul Desai Avatar asked Jan 17 '26 18:01

Rahul Desai


2 Answers

try (i test in your fiddle)

display:inline-block;

fiddle demo

like image 66
saman khademi Avatar answered Jan 19 '26 15:01

saman khademi


You could make it an inline-block element:

UPDATED EXAMPLE HERE

label{
    width: 50%;
    text-align: right;
    display:inline-block;
}

You need to do this because a label is an inline element, and the following applies to it:

10 Visual formatting model details - 10.2 Content width: the 'width' property

This [width] property does not apply to non-replaced inline elements. The content width of a non-replaced inline element's boxes is that of the rendered content within them (before any relative offset of children). Recall that inline boxes flow into line boxes. The width of line boxes is given by the their containing block, but may be shorted by the presence of floats

like image 41
Josh Crozier Avatar answered Jan 19 '26 14:01

Josh Crozier



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!