我的布局包含高度相同的响应式框。它们有box-shadow
但底部阴影不会出现。
我认为这是因为overflow:hidden
的{{1}}被设置为使箱子的高度与One True Layout Method中推荐的相同。
HTML代码:
div#latest
CSS代码:
<div id="latest">
<div id="section-header"><h4>NEWS</h4></div>
<div class="row">
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/74aBLNQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/m0D77HS.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/995osiQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/JI7P0ZJ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
</div>
</div>
<div id="latest">
<div id="section-header"><h4>MOST READ</h4></div>
<div class="row">
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/74aBLNQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/m0D77HS.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/995osiQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
<div id="article-container" class="col-md-3 col-sm-3">
<div id="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/JI7P0ZJ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div id="meta" class="row">
<div id="meta-category" class="col-md-9"><a href="#">CATEGORY</a></div>
<div id="meta-view" class="col-md-2 col-md-offset-1">124</div>
</div>
</div>
</div>
</div>
</div>
P.S。我正在使用Bootstrap 3.
答案 0 :(得分:2)
首先,ID是唯一并且您正在复制ID,所以请改用类。
由于您使用的是bootstrap,因此缺少.container
和.row
包装的col-*-*
。
然后,为了拥有相同的height
而不是那个黑客,您可以使用新的灵活布局,flexbox
,然后box-shadow
将显示
body {
background: #ebebeb;
}
.row {
display: flex
}
.article-container {
padding: 1em;
background: #ddd;
display: flex
}
.article {
padding: 0;
background: #FFF;
height: auto;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .2)
}
.article figure {
max-width: 100%;
height: auto;
}
.article figure img {
/*height: 30%;*/
}
.article h4 {
padding: 1em;
}
.article h4 a {
text-decoration: none;
color: #000;
}
.article h4 a:hover {
text-decoration: underline;
}
.meta {
color: #ccc;
width: 100%;
padding-left: 1em;
}
.meta a {
text-decoration: none;
color: #ccc;
}
.meta a:hover {
text-decoration: underline;
}
.section-header {
height: 40px;
width: 100%;
background: #FFF;
display: table;
border-left: 5px #FFC640 solid;
margin-left: 0;
margin-top: 2em;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .2)
}
.section-header h4 {
padding-left: 1em;
vertical-align: middle;
display: table-cell;
}
<div class="latest container">
<div class="section-header">
<h4>NEWS</h4>
</div>
<div class="row">
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/74aBLNQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/m0D77HS.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/995osiQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/JI7P0ZJ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class=c lass="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
</div>
</div>
<div class="latest container">
<div class="section-header">
<h4>MOST READ</h4>
</div>
<div class="row">
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/74aBLNQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class=c lass="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/m0D77HS.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/995osiQ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 article-container">
<div class="article">
<figure>
<img class="img-responsive" src="http://i.imgur.com/JI7P0ZJ.jpg" />
</figure>
<h4><a href="#">About surviving despite of everything</a></h4>
<div class="row meta">
<div class="col-md-9 meta-category"><a href="#">CATEGORY</a>
</div>
<div class="col-md-2 col-md-offset-1 meta-view">124</div>
</div>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
那不是因为overflow:hidden
中的#latest
,而是在article
中添加了大量的边距和填充,更改如下,然后设置它的高度和相应的宽度,
#article {
padding: 0;
background: #FFF;
height: auto;
box-shadow: 0px 5px 3px 1px rgba(0,0,0,.2)
}