浮动 两个并排 一个流体 一个固定
这就是困境。
<div id="lists-container>
<ul id="list-one"></ul>
<ul id="list-two"></ul>
</div>
我需要列表一中的内容来扩展父 div(列表容器)的 100%,如果列表二有内容,我希望两个列表都是 50% 宽度 - 并排浮动。
发生的情况是列表二最终清除列表一,而不是向右浮动。有人可以帮忙吗? 这就是我所拥有的:
#list-container{width:600px}
ul#list-one{display:inline; float:left}
ul#list-two{display:inline; float:right; width:50%}
Here's the dilemma.
<div id="lists-container>
<ul id="list-one"></ul>
<ul id="list-two"></ul>
</div>
I need content in list-one to expand 100% of parent div (list-container), if list-two has content, I want both lists to be 50% widths -floating side by side.
What happens is that list-two ends up clearing list-one, rather than floating to the right. Can anyone please help?
This is what I have:
#list-container{width:600px}
ul#list-one{display:inline; float:left}
ul#list-two{display:inline; float:right; width:50%}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
display:table
。还放入一些隐藏的 Internet Explorer 标记。其中一些是一起运行的,因为如果您没有在内容后面关闭标签,IE 会添加空格。这为您提供了良好的、可预测的、类似表格的行为,但仍然使用语义标记。它适用于 IE 6+ 和 EOMB。
注意:我前段时间在网上读到过这一点。我认为这是一个博客。如果有人能找到并注明来源,我将不胜感激。我找不到它!
如果您不想使用
display:table
,这里有一些代码可以让您接近。应用的宽度是父容器的 50% + border + padding + margin,所以这在不同的宽度下会有不同的表现,但这种方法是有效的。Use
display:table
. Also put in some hidden Internet Explorer markup. Some of it is run together because IE will add white space if you don't close the tags right after content.This gives you nice, predictable, table-like behavior but still uses semantic markup. It works in IE 6+ and EOMB.
Note: I read about this somewhere online some time ago. I think it was a blog. If anybody can find and credit the source, I'd appreciate it. I can't find it!
If you don't want to use
display:table
, here is some code that will get you close. The applied width is 50% of the parent container + border + padding + margin, so this will behave differently at different widths, but this kind of works.我一直在开发一个 div,我需要一个以 300 像素浮动的 twitter feed 块,然后在左侧浮动一个流体内容块。我一直想保持移动友好,因此希望当浏览窗口缩小时这些块能够换行到下一行。
这对我有用:
I've been working on a div that I need a twitter feed block floating right at 300px and then a fluid content block on the left. I always wanted to stay mobile friendly so hoped for the blocks to wrap to the next lines when the browse window was shrunk.
This worked for me: