-1
来填充div的背景我想用一张类似于你使用CSS background-size cover的方式填充div的背景,但在这种情况下,它需要是img,因为这是页面内容,最终将来自我们的CMS。 这是我到目前为止有:http://codepen.io/anon/pen/XmBRPR?editors=110#0 这就是我想要的样子,但我不希望使用CSS背景:http://codepen.io/anon/pen/GpBmYz?editors=110 我没有使用少,我的HTML比setting an image to fill the background of a div用一个<img>
更基本的<aside class="row cross-link">
<div class="col-xs-12">
<a class="cross-link-item" href="#"><h5 class="cross-link-text">Local Events</h5><img class="hero" src="http://ridebike.ws/images/heros/Trance-27.5-003x300.jpg"alt=""/></a>
<a class="cross-link-item" href="#"><h5 class="cross-link-text">Local Events</h5><img class="hero" src="http://ridebike.ws/images/heros/Trance-27.5-003x300.jpg"alt=""/></a>
<a class="cross-link-item" href="#"><h5 class="cross-link-text">Local Events</h5><img class="hero" src="http://ridebike.ws/images/heros/Trance-27.5-003x300.jpg"alt=""/></a>
</div>
</aside>
和
.cross-link {
background-color: #7bafd0;
padding-right: 4%;
padding-left: 4%;
text-align: center;
}
a.cross-link-item {
margin: 10px;
padding: 0;
display: inline-block;
width: 200px;
height: 200px;
background-color: #1f26ab;
background-size: cover;
}
.cross-link-text {
margin: 8px;
padding: 2px;
background-color: rgba(0, 0, 0, 0.59);
color: #FFF;
}
它从你的CMS来了吗?为什么它需要成为一个'img'?为什么你不能只是吐出以下内容:'
' – Adam同意,你可以像使用CMS一样容易地在HTML中填充CSS。 –
也许,但这将最终成为页面内容的一部分,如果用户想要这样做,我希望它能够打印,并且我试图让CSS保持我的HTML。 –