2

我有一个液体布局。我需要 2 个 div 水平相邻并占据整个可用宽度。第二个 div 需要是其内容的宽度,所以第一个 div 应该占据其余的空间。

这是我的尝试:http: //jsfiddle.net/jamesbrighton/N2prR/2/

它的工作原理是#other 的背景延伸到#button 后面。我的实际站点#other 的右侧也设置了背景图像。这意味着我需要背景颜色和图像只能扩展到#button,而不是超出它。谢谢

4

2 回答 2

1

两个 div 中的第一个应该是浮动的。(如果不是,它们存在于不同的“层”和重叠中)

至于自动宽度的事情,我不认为你可以用 html 轻松做到这一点。根据我的经验,使用 div 设置宽度/高度总是更好。

如果您愿意,可以使用 2 td 表(一个设置为 100% 宽度,另一个设置宽度 - 例如 200px)

祝你好运

于 2012-05-22T11:53:24.020 回答
1
<style>
#other {
    background-color: blue;
width: 40%;
}
#button {
   background-color: gold;
   float: right;
   border-radius: 10px;
   width: 60%; 
}
.clear{
   clear: both;
}

<div id="父">
 <div id="按钮">
    提交 提交 提交 提交 提交 提交 提交 提交 提交
 </div>
 <div id="其他">
   其他一些内容
 </div>
<div class="clear"></div>
</div>

你必须给第一个 <div> 一些固定的百分比。第二个中的文本将自动换行。

于 2012-05-22T12:12:41.617 回答