Label we use to define some labels mostly in our forms but label is not only restricted to use in forms for xhtml you can use them anywhere to label anything. Like if you have an image you want to add caption of image and you want to use label for this you can use this is standard of XHTML.
As you may know h1, h2, h3, h4, h5, h6, p, ul, li, td, div, table and some more tags have 100% width by default but some tags like strong, span, label, and some more tags do not occupy 100% width by default they occupy width only what content inside them covers that.
So as you know label do not cover 100% width which means <label>Email:</label> this code will cover only space where Email can adjust, but if you use <p>Email:</p> This will cover 100% width in that row and will not leave space for any other things after </p> in same row. Inside <p> we can align text easily cause we have much space available inside <p> tag which is 100% so according to that width <p> tag align its text to center, right or left whatever CSS you define text-align:right; or whatever. But this way <p> will not leave space for any element still. Cause you have to make <p> tag to a specific width and float it to somewhere.
XHTML Label text align right
Suppose you have a <label>Email:</label> inside a <td width=”150px” now as you know your <td’s width is 150px and your label hardly occupy 30px width and aligning left inside this table data column you want to align label right or center how you can do this?
Well if you define CSS for label saying text-align:center; text-align:right; this will not work cause label already full with its default width. You can float label to right and margin it auto this will adjust according to its wrapper td’s width this is the way how you can align your label. Just float label to left or right , and margin auto for center that’s it.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?