我希望有一个内部div,它位于不同大小的容器div中,并从固定的左侧位置开始,然后有一个宽度填充容器的其余部分.我在下面包含了一些示例css,试图明白这一点.
我必须使用绝对定位,所以不能只是向右浮动并设置左边距.有关如何使用绝对定位工作的任何想法?我也尝试过宽度:自动和一些不同的盒子大小选项.
为了澄清,这种棘手的方法是必须修复左边框,左边框必须与容器的右边框相对.我不能使用position:relative和javascript,但我可能最终会在执行此操作之前使用硬编码宽度制作.inner1和.inner2 div.但希望避免这种情况.
.container1 {
position: relative;
width: 400px;
height: 300px;
}
.container2 {
position: relative;
width: 500px;
height: 300px;
}
.inner {
position: absolute;
top: 0px;
left: 200px;
height: 100%;
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

ani*_*son 60
只要指定所有的top,left,bottom,和right属性和框将扩大到在所有这些点.
.container {
position: relative;
width: 400px;
height: 300px;
}
.inner {
position: absolute;
top: 0;
left: 200px;
bottom: 0;
right: 0;
}
Run Code Online (Sandbox Code Playgroud)