我有默认的jumbotron (在容器中)
<div class="jumbotron">
<h1>Example Page</h1>
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class="btn btn-primary btn-lg">Learn more</a></p>
</div>我怎么才能在这台巨型加速器里有背景图像呢?
当我添加
background: url('a.jpg') no-repeat center center;添加到.jumbotron css类,那么我就得不到跨宽度的图像。我希望它能扩展,但至少能填满巨型加速器。
这是完整的风格
.jumbotron {
color: white;
text-shadow: #444 0 1px 1px;
background:transparent;
background: url('a.jpg') no-repeat center center;
}发布于 2015-03-03 00:54:39
你应该试着把巨型加速器放在容器外面。
<div class="jumbotron"></div>
<div class="container"></div>发布于 2018-01-31 12:41:28
巨型加速器可以在容器内,但仍然是全宽的。将此规则添加到CSS中的背景图像规则下:
background-size: cover;如果它仍然不是全宽的,你可以在上面的规则下面添加:
width:100%;巨型加速器可能会有圆角。如果是这样,并且您希望删除它们,请添加以下规则:
border-radius:0;试试这个:
.jumbotron {
color: white;
text-shadow: #444 0 1px 1px;
background:transparent;
background: url('a.jpg') no-repeat center center;
background-size: cover;
width:100%; // may not need
border-radius: 0; // override rounded corners if applicable
}发布于 2019-07-29 21:16:37
你可以使用
background: url('a.jpg') 50% /cover;它是以下的简写
background-image: url('a.jpg');
background-position-x: 50%;
background-position-y: center;
background-size: cover;在background速记中,background-size的值必须紧跟在background-position的值之后,并以/为前缀。
请注意,您不需要速记形式的center center。您可以使用center (解析为center center )或50% (解析为50% center,与center center相同,但更短)。
请注意,如果没有background-position值,background-size将无法以简写形式工作。
还要注意,这里不需要no-repeat (= background-repeat:no-repeat),因为带有background-size:cover的元素不能重复背景,因为它的大小同时适合元素的宽度和高度,其中一个元素被裁剪(除非您的元素与图像的比例完全相同-在这种情况下,没有任何元素被裁剪)。
https://stackoverflow.com/questions/26563180
复制相似问题