views:

50

answers:

3

Cross-browser CSS that works to allow both left and right align of text on the same line?

Example (where each text quote should be aligned as far left or right as possible, respectively):

stuff on the right                                              stuff on the left
  • No float's answer's please.. unless there is a way to make the text not break out of the parent div/container in a multicolumn css page...
+2  A: 

float:left for the one on the left, and float:right for the one on the right. Or absolute/relative positioning. Pretty sure both work across the main browers.

BobTurbo
that breaks the text out of its container though..
ina
no it doesn't. If puts the text to the far left or far right of the container.
BobTurbo
nope, it forces the text out if you are using a multicolumn css layout.. which is most pages nowadays.
ina
+3  A: 

With container tags:

<div>
  <p style="float: left">stuff on the left</p>
  <p style="float: right">Tstuff on the right </p>
</div>

With inline tags:

<div>
  <span style="float: left">stuff on the left</span>
  <span style="float: right">Tstuff on the right</span>
</div>
barrylloyd
that breaks the text out of its container though..
ina
@ina: I dont understand. The two bits of text will have to be in separate 'containers' if you want to apply different styling/layout to them
barrylloyd
@barrylloyd - Just added an additional example. I hope you don't mind.
Gert G
@ina - You can style the text from the DIV in either example.
Gert G
@ina: I'm not sure what you mean, but you could try adding `<hr style="display:none; clear: both" />` to the end of the container div.
tomp
Had thought span's only did local formatting - btw are span's safer than div's in this case - before I put the ` ` into my layout, the entire thing went astray (totally went out of containers)...
ina
+1  A: 

Let's assume this is the HTML code:

<div>
  <div id="left" style="float: left">stuff on the left</div>
  <div id="right" style="float: right">Tstuff on the right </div>
</div>

What you can do is use JQuery to find the highest div, then set the #left, #right divs with the highest div. Here's a sample code:

if ($('#left').height()<$('#right').height()) {
  $('#left').height($('#right').height());
} else {
  $('#right').height($('#left').height());
}

Or you can Google with "equal heights jquery" for other solutions.

Tuong Le