[英]Can Bootstrap 4 Cards Have Tiled Background Images
I am trying to get a card to have a tiled background image.我正在尝试获得一张具有平铺背景图像的卡片。 To get a single image background I use:
要获得单个图像背景,我使用:
<div class="card img-fluid">
<img class="card-img-top" src="images/backcard-brushedmetal.jpg">
<div class="card-img-overlay">
<div class="card-body text-justify">
<h3 class="articleh3"><a href="#">xxxDescriptionxxx</a></h3>
<p>
<a href="#"><img src="images/xxxImagexxx.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;float: left" /></a>
xxxSomeTextHerexxx
</p>
</div>
</div>
</div>
My problem is that I use cards of different sizes and right now my image size is governing the size of my card;我的问题是我使用不同尺寸的卡片,现在我的图像大小决定了卡片的大小; I guess I want it the other way round (the card to govern the size of the displayed background).
我想我想要反过来(控制显示背景大小的卡片)。 So I wondered if it was possible to tile a background image so it just fills the background and then it shouldn't matter what size the card or image is.
所以我想知道是否可以平铺背景图像,以便它只填充背景,然后卡片或图像的大小就无关紧要了。
For all I know, this may not even be possible and if not, that's fine, I'll look for another way to do something like :)据我所知,这甚至可能是不可能的,如果不是,那很好,我会寻找另一种方法来做类似的事情:)
Anyway, thanks for any advice :)无论如何,感谢您的任何建议:)
James詹姆士
If the only purpose of using img
element is as a background - use background-image
CSS property which sets background image on an element.如果使用
img
元素的唯一目的是作为背景 - 使用background-image
CSS 属性在元素上设置背景图像。
Edit per comments: Obviously the float
part cause some "problems" on the given markup, BUT there is something more out there... Can't figure myself why this not working - so i remove BS4 (added 2 examples):编辑每个评论:显然
float
部分会导致给定标记上的一些“问题”,但是还有更多的东西......我无法弄清楚为什么这不起作用 - 所以我删除了 BS4(添加了 2 个例子):
.card.img-fluid { background: url(http://www.rocksquad.co.uk/images/backcard-brushedmetal.jpg) no-repeat; background-position: center; background-size: cover; }
<div class="card img-fluid"> <div class="card-img-overlay"> <div class="card-body text-justify"> <h3 class="articleh3"><a href="#">xxxDescriptionxxx</a></h3> <p> <a href="#"><img src="http://www.rocksquad.co.uk/images/backcard-brushedmetal.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;" /></a> xxxSomeTextHerexxx<br>xxxSomeTextHerexxx </p> </div> </div> </div> <hr> <div class="card img-fluid"> <div class="card-img-overlay"> <div class="card-body text-justify"> <h3 class="articleh3"><a href="#">xxxDescriptionxxx</a></h3> <p> <a href="#"><img src="http://www.rocksquad.co.uk/images/backcard-brushedmetal.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;" /></a> xxxSomeTextHerexxx<br>xxxSomeTextHerexxx<br> xxxSomeTextHerexxx<br>xxxSomeTextHerexxx<br> xxxSomeTextHerexxx<br>xxxSomeTextHerexxx<br> xxxSomeTextHerexxx<br> </p> </div> </div> </div>
This question need some "bootstrap 4 expert" to answer on - clearly this is not me (:这个问题需要一些“引导程序 4 专家”来回答 - 显然这不是我(:
Old (not working) answer:旧(不工作)答案:
In your case, since you want the image would cover the element, you can do something like that:在您的情况下,由于您希望图像覆盖元素,您可以执行以下操作:
<style>
.card.img-fluid {
background: url(images/backcard-brushedmetal.jpg) no-repeat;
background-position: center;
background-size: cover;
}
</style>
<div class="card img-fluid">
<div class="card-img-overlay">
<div class="card-body text-justify">
<h3 class="articleh3"><a href="#">xxxDescriptionxxx</a></h3>
<p>
<a href="#"><img src="images/xxxImagexxx.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;float: left" /></a>
xxxSomeTextHerexxx
</p>
</div>
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.