简体   繁体   English

IE7和float:right

[英]IE7 and float:right

I have two sibling divs: #label and #value. 我有两个同级div:#label和#value。 I want #value div to be aligned to the right side of parent's div. 我希望#value div与父级div的右侧对齐。 I set float:right . 我设置float:right But in IE7 #value div is displayed under #label div, not on the same line. 但是在IE7中,#value div显示在#label div下,而不是同一行。 One solution I know is to switch the order of #label and #value divs in HTML, but it is quite counterintuitive looking. 我知道的一种解决方案是在HTML中切换#label和#value div的顺序,但这看起来很违反直觉。

Is there any other ways to accomplish this task? 还有其他方法可以完成此任务吗?

PS Please do not tell me 'stop supporting IE7'. PS:请不要告诉我“停止支持IE7”。 I have visitors who still use IE7 and do not see any serious reason why I have to drop them from my website. 我的访问者仍在使用IE7,却没有看到我必须将其从网站上删除的任何严重原因。

The first div takes up the whole width of the parent element. 第一个div占用父元素的整个宽度。

You can float the first element to the left, and the second to the right, then use overflow on the parent element to make it contain the children: 您可以将第一个元素向左浮动,第二个元素向右浮动,然后在父元素上使用overflow使其包含子元素:

 #Item { overflow: hidden; border: 1px solid #ccc; } #label { float: left; } #value { float: right; } 
 <div id="Item"> <div id="label">Label</div> <div id="value">Value</div> </div> 

Try this: 尝试这个:

<div></div>
<div></div>
css: div{display:inline-block}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM