Html 右侧固定宽度div,左侧填充剩余宽度div
我正在寻找一种方法,将两个div作为列,其中右侧的div具有固定宽度,左侧的div填充剩余空间 有人知道这是否可以做到吗 我的尝试(在block1下呈现block2):Html 右侧固定宽度div,左侧填充剩余宽度div,html,css,Html,Css,我正在寻找一种方法,将两个div作为列,其中右侧的div具有固定宽度,左侧的div填充剩余空间 有人知道这是否可以做到吗 我的尝试(在block1下呈现block2): <style> .block1 { width: auto; height: 200px; background-color: green; } .block2 { float: right; height: 200px; width: 200px; background
<style>
.block1 {
width: auto;
height: 200px;
background-color: green;
}
.block2 {
float: right;
height: 200px;
width: 200px;
background-color: red;
}
</style>
<div class="block1">test1</div>
<div class="block2">test2</div>
<div class="right">right</div>
<div class="left">left</div>
.left{
background:red;
}
.right{
float:right;
width:200px;
background:green
}
.区块1{
宽度:自动;
高度:200px;
背景颜色:绿色;
}
.区块2{
浮动:对;
高度:200px;
宽度:200px;
背景色:红色;
}
测试1
测试2
您可以这样做:
HTML:
<style>
.block1 {
width: auto;
height: 200px;
background-color: green;
}
.block2 {
float: right;
height: 200px;
width: 200px;
background-color: red;
}
</style>
<div class="block1">test1</div>
<div class="block2">test2</div>
<div class="right">right</div>
<div class="left">left</div>
.left{
background:red;
}
.right{
float:right;
width:200px;
background:green
}
选中此实时示例将两个元素向左浮动:
<style>
.block1 {
width: auto;
height: 200px;
float: left;
background-color: green;
}
.block2 {
float: left;
height: 200px;
width: 200px;
background-color: red;
}
</style>
<div class="block1">test1</div>
<div class="block2">test2</div>
从一个容器开始(#container
),该容器同时容纳左右两侧的
。向右浮动一个
,并给它一个特定的宽度(在我的示例中为320px)。然后给另一个
一个绝对位置,从绝对左侧(0px)开始,到右侧
的左边缘(320px)结束
如果调整
#容器的宽度
,右侧的
将保持固定在320px,而左侧的
将扩展以填充剩余区域。这是我的解决方案,没有浮动。唯一需要注意的是我需要用包装纸。因此,如果所需的HTML是
parent (has a border, margin, padding,...)
left (fixed width)
right (variable width, fill the entire space)
我必须把它改写成英文
parent (has a border, margin, padding,...)
wrapper (has no styling)
left (fixed width)
right (variable eidthm, fill the entire space)
我的HTML是
<div style="border:1px solid black; background:red; margin:10px; padding:10px;" >
<div style="">
<div style="display:table-cell; padding:10px; min-width:100px; max-width:100px;background:green;">Left</div>
<div style="display:table-cell; padding:10px; width:100%; background:yellow;">Main content</div>
</div>
</div>
左边
主要内容
这里的要点是:
- 不使用display:table,因为这样我们无法设置边框
- 最小宽度、最大宽度的使用
- 宽度的使用:100%
溢出:隐藏添加到左侧,以便让它为我工作。Kyle,你确定这段代码在chrome中工作吗?:)对我来说,绿色不会填充剩余宽度对不起,我犯了一个小错误,检查我答案的编辑部分,这肯定会使绿色填充剩余宽度。啊,谢谢,第二个肯定有效。我喜欢:)升级投票和接受总是受欢迎的,除非你更喜欢SAndeep的另一种方法,然后保持他的标记为接受。我同样喜欢你的两个答案,但我先阅读了另一个1,对不起,我不会让我升级投票,但我会尽快获得足够的代表点。如果你离开,它也会起作用,因此,空div已过时: