我用4个网格元素和bootstrap 3创建了这一行。
Demosite can be seen here
网格中的中间框是600x410px
(请参见演示)。我真的很想有一个白色的文字出现时,一个人徘徊在那个中间框。有可能吗?我不太确定这是不是一个容器内的覆盖有必要使用?
#front .row {
padding-bottom: 0px!important;
}
body {
background-color: #f5f5f5;
}
/* Set width between grid elements */
.small-padding.top {
padding-top: 10px;
}
.small-padding.bottom {
padding-bottom: 10px;
}
.small-padding.left {
padding-left: 5px;
}
.small-padding.right {
padding-right: 5px;
}
.margin_bottom {
margin-bottom: 10px;
}
.row [class*="col-"] {
padding-right: 5px;
padding-left: 5px;
}
.row {
margin-left: -5px;
margin-right: -5px;
}
.img-responsive {
height: 100%;
}
/* Position of buttons/text in a single grid element */
.inner-wrapper {
background: none;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.bottom-right {
position: absolute;
bottom: 8px;
right: 16px;
}
.bottom-left {
position: absolute;
bottom: 2%;
left: 6%;
}
/* Position text on full width banner */
.header-container {
color: white;
margin: 0 5%;
}
.banner-text {
position: absolute;
bottom: 16%;
left: 6%;
}
/* Color on text */
.dark-font {
color: #333;
}
.light-font {
color: #fff;
text-transform: uppercase;
}
/* Set full width on columns */
@media (max-width: 768px) {
.img-responsive {
width: 100%;
height: auto;
}
/* Maybe delete btn-success: */
.btn-success {
width: fit-content;
}
}
@media (max-width: 991px) {
h3 {
font-size: 1.2em;
}
}
.image-overlay {
position:relative;
}
.overlay {
position:absolute;
transition:all .3s ease;
opacity:0;
transition:1.9s;
background: #00b1bab8;
}
.image-overlay:hover .overlay {
opacity:1;
}
.overlayFade {
background: rgba(27, 27, 27, 0.5);
top: 0;
/* Like this */
bottom: 0;
left: 0;
right: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>FINAL WORKING</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-3 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade"></div>
<img src="https://koed.dk/Static/Cms/1bfc7495-1445-4642-815e-0a20ab652ed5.jpg" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper centered">
<h3 class="light-font">Har du et værksted eller en reservedelsbutik?</h3>
<span class="light-font">Så se de mange fordele her</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
<div class="col-sm-6 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade"></div>
<!-- Middle box -->
<img src="http://placehold.it/600x410" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper bottom-left">
<h3 class="light-font">Looking for having a good time</h3>
<span class="light-font">Here is where you should look</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
<div class="col-sm-3">
<div class="row">
<div class="col-xs-6 col-sm-12 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade"></div>
<img src="http://placehold.it/300x200" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper bottom-left">
<h5 class="light-font">Looking for having a good time</h5>
<span class="light-font">Here is where you should look</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
<div class="col-xs-6 col-sm-12 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade"></div>
<img src="http://placehold.it/300x200" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper bottom-left">
<h5 class="light-font">Looking for having a good time</h5>
<span class="light-font">Here is where you should look</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
最佳答案
#front .row {
padding-bottom: 0px!important;
}
body {
background-color: #f5f5f5;
}
/* Set width between grid elements */
.small-padding.top {
padding-top: 10px;
}
.small-padding.bottom {
padding-bottom: 10px;
}
.small-padding.left {
padding-left: 5px;
}
.small-padding.right {
padding-right: 5px;
}
.margin_bottom {
margin-bottom: 10px;
}
.row [class*="col-"] {
padding-right: 5px;
padding-left: 5px;
}
.row {
margin-left: -5px;
margin-right: -5px;
}
.img-responsive {
height: 100%;
}
/* Position of buttons/text in a single grid element */
.inner-wrapper {
background: none;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.bottom-right {
position: absolute;
bottom: 8px;
right: 16px;
}
.bottom-left {
position: absolute;
bottom: 2%;
left: 6%;
}
/* Position text on full width banner */
.header-container {
color: white;
margin: 0 5%;
}
.banner-text {
position: absolute;
bottom: 16%;
left: 6%;
}
/* Color on text */
.dark-font {
color: #333;
}
.light-font {
color: #fff;
text-transform: uppercase;
}
/* Set full width on columns */
@media (max-width: 768px) {
.img-responsive {
width: 100%;
height: auto;
}
/* Maybe delete btn-success: */
.btn-success {
width: fit-content;
}
}
@media (max-width: 991px) {
h3 {
font-size: 1.2em;
}
}
.image-overlay {
position:relative;
}
.overlay {
position:absolute;
transition:all .3s ease;
opacity:0;
transition:1.9s;
background: #00b1bab8;
}
.image-overlay:hover .overlay {
opacity:1;
}
.overlayFade {
background: rgba(27, 27, 27, 0.5);
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #fff;
font-size: 15px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>FINAL WORKING</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-3 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade">
</div>
<img src="https://koed.dk/Static/Cms/1bfc7495-1445-4642-815e-0a20ab652ed5.jpg" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper centered">
<h3 class="light-font">Har du et værksted eller en reservedelsbutik?</h3>
<span class="light-font">Så se de mange fordele her</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
<div class="col-sm-6 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade">Dymmy Text</div>
<img src="http://placehold.it/600x410" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper bottom-left">
<h3 class="light-font">Looking for having a good time</h3>
<span class="light-font">Here is where you should look</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
<div class="col-sm-3">
<div class="row">
<div class="col-xs-6 col-sm-12 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade"></div>
<img src="http://placehold.it/300x200" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper bottom-left">
<h5 class="light-font">Looking for having a good time</h5>
<span class="light-font">Here is where you should look</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
<div class="col-xs-6 col-sm-12 margin_bottom">
<a href="#">
<div class="image-overlay">
<div class="overlay overlayFade"></div>
<img src="http://placehold.it/300x200" alt="John Doe" class="img-responsive"></img>
<div class="inner-wrapper bottom-left">
<h5 class="light-font">Looking for having a good time</h5>
<span class="light-font">Here is where you should look</span>
<!--<button class="btn btn-success btn-lg">Read More</button>-->
</div>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
关于html - 是否可以在悬停叠加层上设置文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51664920/