gpt4 book ai didi

css - 保持右浮动元素与 block 在同一行

转载 作者:行者123 更新时间:2023-11-28 12:21:55 24 4
gpt4 key购买 nike

我有两个宽度未知的元素,一个向左浮动,一个向右浮动。在它们之间我有一个扩展 block 以适应容器宽度。

我想要实现的布局是这样的:

+---------------------------------------------+
| [Left] [Expanded ] [Right] |
+---------------------------------------------+

但是右浮动的元素被清除到下一行:

+---------------------------------------------+
| [Left] [Expanded ] |
| [Right] |
+---------------------------------------------+

如果元素在 HTML 中按以下顺序排列,则效果很好:左、右、展开。但是为了更加语义化,我需要这样的顺序:Left, Expanded, Right

查看此 jsFiddle .

这可能吗?即使需要包装器...

最佳答案

您可以使用 display: table 来做到这一点:http://jsfiddle.net/thirtydot/GpL5A/3/

HTML:

<div class="expandoooo">
<span class="left">Left</span>
<span class="expanded">Expanded</span>
<span class="right">Right</span>
</div>​

CSS:

.expandoooo {
background-color: lightgray;
display: table;
}
.expandoooo > span {
display: table-cell;
}

.left {
color: red;
}
.expanded {
background-color: black;
color: white;
width: 100%;
}
.right {
color: blue;
}

这种技术的一个小缺点是垂死的浏览器 IE7 does not support display: table , 虽然有一个 JavaScript fix .

关于css - 保持右浮动元素与 block 在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13299928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com