首先,看看这个:http://jsfiddle.net/muncherelli/1kkus9bd/1/
我的HTML / CSS存在两个问题:
需要考虑的一件事:我使用的是bootstrap框架,我不确定是否正在影响或帮助或伤害这种情况。
(不确定我是否需要在这里提出两个问题,但它们似乎有关系)。
这是我正在使用的HTML / CSS:
HTML:
<br />
<div class="container">
<div class="row">
<div class="hidden-xs hidden-sm col-md-1 col-lg-1"></div>
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-10 nopadding">
<div class="blog-post-feature-overlay-container roundy">
<a href="http://munchimages.com/blog/session-stories/2015/4th-of-july-shoot-with-teresa-diane">
<img src="http://cache.blog.munchimages.com/blog/wp-content/uploads/2015/07/MI_73-Feature-1200x620.jpg" class="img-responsive roundy blog-post-feature-image" />
</a>
<div class="blog-post-feature-overlay-content">
<div class="blog-post-feature-overlay-content-top text-right">
<a href="http://munchimages.com/blog/session-stories/2015/4th-of-july-shoot-with-teresa-diane" class="blog-category-box general-font-title-serif transition-color-ease-500">Latest Post</a>
<a href="http://munchimages.com/blog/session-stories/" class="blog-category-box general-font-title-serif transition-color-ease-500">Session Stories</a>
</div>
<div class="blog-post-feature-overlay-content-bottom">
<h1 class="general-font-title-serif">
<a href="http://munchimages.com/blog/session-stories/2015/4th-of-july-shoot-with-teresa-diane" class="blog-post-feature-overlay-content-title color-white transition-color-ease-500">
4th of July
</a>
</h1>
</div>
</div>
</div>
</div>
<div class="hidden-xs hidden-sm col-md-1 col-lg-1"></div>
</div>
</div>
CSS:
.general-font-title-serif {
font-family:'Cinzel', serif;
}
.nopadding {
margin: 0 !important;
padding: 0 !important;
}
.blog-post-feature-image:hover {
opacity: 0.9;
}
.color-white {
color: white;
}
.roundy {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
.transition-color-ease-500 {
-moz-transition: background-color 500ms, color 500ms ease-out;
-ms-transition: background-color 500ms, color 500ms ease-out;
-o-transition: background-color 500ms, color 500ms ease-out;
-webkit-transition: background-color 500ms, color 500ms ease-out;
transition: background-color 500ms, color 500ms ease-out;
}
div.blog-post-feature-overlay-container {
background-color: #000;
position: relative;
}
div.blog-post-feature-overlay-content {
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
div.blog-post-feature-overlay-content-top {
position: absolute;
right: 20px;
top: 20px;
}
div.blog-post-feature-overlay-content-bottom {
position: absolute;
bottom: 20px;
left: 20px;
}
a.blog-category-box {
background-color: #ccc;
background-color: rgba(0, 0, 0, 0.4);
color: #fff;
font-size: 13px;
padding: 5px 15px;
text-transform: uppercase;
}
a.blog-category-box:hover {
background-color: rgba(0, 0, 0, 0.6);
text-decoration: none;
}
a.blog-post-feature-overlay-content-title {
text-shadow: 1px 1px #000;
}
a.blog-post-feature-overlay-content-title:hover {
color: #ddd;
text-decoration: none;
}
@media (max-width: 768px) {
.roundy {
-moz-border-radius: 0;
-webkit-border-radius: 0;
border-radius: 0;
}
h1 {
font-size: 30px;
}
}
谢谢!
答案 0 :(得分:1)
从position:absolute
div.blog-post-feature-overlay-content
div.blog-post-feature-overlay-content {
height: 100%;
width: 100%;
}
当在此元素上使用position: absolute;
时,它会将其从文档流中取出,top:0
和left:0
将元素 - 尽管是不可见的 - 相对于其父{{1}覆盖它的全部因为设置了100%高度和100%宽度。
通过删除blog-post-feature-overlay-container
,元素保留在文档流中并位于链接后面(因为它们位于:绝对位置),因为它位于包含文档树中链接的元素之前