<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 7 年前。
标签 html css css-selectors
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 7 年前。
基本上我在所有“行”div 的底部都有一个边距。在最后一个 div 上有 margin-bottom: 0,但它似乎不起作用。我正在使用 HTML 和 SCSS。
body {
margin: 0;
padding: 0;
font-family: sans-serif; }
.left-sidebar {
width: 100px;
position: fixed;
top: 0;
left: 0;
height: 100%;
background-color: red; }
.main-body {
margin-left: 100px;
background-color: blue;
padding: 50px; }
.main-body a {
margin-bottom: 50px; }
.main-body a .row {
max-width: 100%;
height: 700px;
margin-bottom: 50px; }
.main-body a .row.one {
border: 10px solid red; }
.main-body a .row.two {
border: 10px solid red; }
.main-body a .row.three {
border: 10px solid red; }
<div class="left-sidebar">
</div>
<div class="main-body">
<a href="#"><div class="row one"></div></a>
<a href="#"><div class="row two"></div></a>
<a href="#"><div class="row three"></div></a>
</div>
最佳答案
首先,有<div>
里面<a>
将瓶子放入水中,我的意思是,在内联元素中包含 block 级元素是一种犯罪行为。
您已经定义了margin
.您应该添加以下 CSS:
.main-body a .row.three {
margin-bottom: -50px; }
或者,您需要这样的东西:
.main-body a:last-child {
margin-bottom: 0; }
片段
body {
margin: 0;
padding: 0;
font-family: sans-serif; }
.left-sidebar {
width: 100px;
position: fixed;
top: 0;
left: 0;
height: 100%;
background-color: red; }
.main-body {
margin-left: 100px;
background-color: blue;
padding: 50px; }
.main-body a {
margin-bottom: 50px; }
.main-body a .row {
max-width: 100%;
height: 700px;
margin-bottom: 50px; }
.main-body a .row.one {
border: 10px solid red; }
.main-body a .row.two {
border: 10px solid red; }
.main-body a .row.three {
border: 10px solid red; }
.main-body a:last-child, .main-body a .row.three {
margin-bottom: 0; }
<div class="left-sidebar">
</div>
<div class="main-body">
<a href="#"><div class="row one"></div></a>
<a href="#"><div class="row two"></div></a>
<a href="#"><div class="row three"></div></a>
</div>
您需要注意您的 .main-body
还有一个padding
的 50px
.如果你需要减少它,你也可以添加这个:
.main-body {
padding-bottom: 0;
}
关于html - Last-Child Margin-Bottom 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32810433/