【发布时间】:2018-11-10 16:59:31
【问题描述】:
在我的网页中,我有一个左右部分,但它们不在同一个嵌套中。我希望左侧部分填充页面的 25%,右侧部分填充其余宽度。
简单地设置 75% 对我来说并不合适,因为右边的部分也需要 30px 的右边margin。正确的 padding 不起作用,因为我的内容和 background-color 会溢出。
你知道如何解决这个问题吗?
.left(蓝色)和.right(黄色)div 应该总是完美地相遇,.right 需要保持 30px 正确margin。
body {
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
overflow: hidden;
}
.main {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
overflow: hidden;
background-color: grey;
}
.left {
position: absolute;
top: 0;
bottom: 0;
padding-top: 0;
padding-bottom: 0;
left: 0;
width: 25%;
border-right: 1px solid #eeeeee;
background-color: lightblue;
}
.right {
position: absolute;
width: 75%;
right: 0px;
top: 45px;
bottom: 0;
/*padding-right: 30px;*/
margin-right: 30px;
background-color: yellow;
}
<body>
<div class="main">
<div class="left">TEST</div>
</div>
<div class="right">TEST</div>
</body>
【问题讨论】: