-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。 –