Cross-browser CSS for left align and right align on the same line

断了今生、忘了曾经 提交于 2019-12-01 23:23:10
barrylloyd

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>

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.

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.

Without floats:

<div class=container style='width: 100%;'>
  <div class=left-side style='display: inline-block; width: 50%'>
    Stuff on the left
  </div>
  <div class=right-side style='display: inline-block; width: 50%; text-align: right'>
    Stuff on the right
  </div>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!