我花了很多时间操纵位置,z-index等来尝试让bootstrap在图像上工作。这是我最干净的代码尝试。
img {
display: block;
max-width: 100%;
width: 100%;
height: 100%;
}
.link a {
border: 0;
border-radius: 0;
padding: 20px 35px;
background-color: black;
color: white;
font-size: 14px;
text-transform: uppercase;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row wrapper">
<img class="img-responsive something-img" src="http://placehold.it/900x100"/>
<div class="container">
<div class="row overlay">
<div class="col-sm-9">
<h2>here are some words about stuff</h2>
</div>
<div class="col-sm-3 link">
<a href="/place">view this thing</a>
</div>
</div>
</div>
</div>
</div>
&#13;
我已尝试将位置相对置于叠加和绝对位置。尝试使用叠加上的z-index为2和图像上的z-index为1。我甚至在图像上放置了绝对位置,但它导致它覆盖了下一段代码。不知所措。有什么提示吗?
答案 0 :(得分:2)
您需要提供包装器position:relative
和覆盖行pposition:absolute
img {
display: block;
max-width: 100%;
height: auto;
}
.link a {
border: 0;
border-radius: 0;
padding: 20px 35px;
background-color: black;
color: white;
font-size: 14px;
text-transform: uppercase;
}
.wrapper {
position: relative;
}
.wrapper .container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
text-align: center
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row wrapper">
<img class="img-responsive something-img" src="http://placehold.it/900x400" />
<div class="container">
<div class="row overlay">
<div class="col-sm-9">
<h2>here are some words about stuff</h2>
</div>
<div class="col-sm-3 link">
<a href="/place">view this thing</a>
</div>
</div>
</div>
</div>