2015-11-03 63 views
-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; 
} 
+0

它从你的CMS来了吗?为什么它需要成为一个'img'?为什么你不能只是吐出以下内容:'

' – Adam

+0

同意,你可以像使用CMS一样容易地在HTML中填充CSS。 –

+0

也许,但这将最终成为页面内容的一部分,如果用户想要这样做,我希望它能够打印,并且我试图让CSS保持我的HTML。 –

回答

0

通过定位文本和相对于DIV图像并指定对DIV期望的效果的宽度和高度都可以实现。

退房代码笔:http://mbs.red/postion

相关问题