Is there a way to have left-, center-, and right-aligned text on the same line with HTML/CSS, under the following conditions?
The obvious solution of using 3 divs with the two of them floating left and right works pretty well, except that the center piece of text is not centered exactly (for example, if the left piece of text is longer than the right, the center appears centered just right of the absolute center).
I only need a solution that works on WebKit. Any ideas?
Edit - This is what I have so far...
HTML:
<div id="left">Left</div>
<div id="center">Center text</div>
<div id="right">Right</div>
CSS:
#left {
float: left;
text-align: left;
padding-right: 10px;
}
#center {
text-align: center;
}
#right {
float: right;
text-align: right;
padding-left: 10px;
}
Applying separate right and left alignment to the same line of text is impossible in Word; the format goes with the entire line. Usually, when you need that kind of arrangement, you might insert a table with two or more cells and apply the alignments to the cells.
solution with clear divs
https://jsfiddle.net/LaL92q88/1/
<div style="float: left">Left Text</div>
<div style="float: right">Right Text</div>
<div style="margin: 0 auto; width: 100px;">Centered Text</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With