简体   繁体   中英

Image overlay text not responsive Bootstrap

I'm well aware that this is a recurring question. I've checked my code but as far as I can see it should work. It should work without using media queries or vw.(I think)

The intention: Having an image and when I hover over it a text appears.
The problem: The text appears, but it is not responsive.

Please let me know what should I do differently.

Thank you for your time.

HTML:

<section id="recent-news"> 
<div class="container">
        <div class="center wow fadeInDown">
            <h2>Recent News</h2>
            <h3 class="lead">The latest news about the school, research, students and more.</h3>
        </div>
        <div class="row">
            <div class="col-xs-4 col-sm-4 col-md-3">
                <div class="recent-news-wrap">
                    <img class="img-responsive" src="images/portfolio/recent/item1.png" alt="">
                    <div class="overlay">
                        <div class="recent-news-inner">
                            <h3 class = "text-center"><a href="#">Mobile Development</a> </h3>
                            <p>We lead the field. Read more about the latest updates in this field.</p>
                            <a class="preview" href="images/portfolio/full/item1.png" rel="prettyPhoto"><i class="fa fa-eye"></i> View</a>
                        </div> 
                    </div>
                </div>
            </div>  

CSS:

#recent-news .col-xs-4.col-sm-4.col-md-3{
  padding: 8px;
}

#recent-news{
    padding-bottom: 70px;
}

.recent-news-wrap {
  position: relative;
}

.recent-news-wrap img{
  width: 100%;
}

.recent-news-wrap .recent-news-inner{
  top: 0;
  background: transparent;
  opacity: .8;
  width: 100%;
  border-radius: 0;
  margin-bottom: 0;
}

.recent-news-wrap .recent-news-inner h3{
  margin: 10px 0;
}

.recent-news-wrap .recent-news-inner h3 a{
  font-size: 24px;
  color: #fff;
}

.recent-news-wrap .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border-radius: 0;
  background: #3579DC;
  color: #fff;
  vertical-align: middle;
  -webkit-transition: opacity 500ms;
  -moz-transition: opacity 500ms;
  -o-transition: opacity 500ms;
  transition: opacity 500ms;  
  padding: 30px;
  text-align: center;
}

.recent-news-wrap .overlay .preview {
  bottom: 0;
  display: inline-block;
  height: 35px;
  line-height: 35px;
  border-radius: 0;
  background: transparent;
  text-align: center;
  color: #fff;
}

.recent-news-wrap:hover .overlay {
  opacity: 1;
}

By responsive I am guessing you want the overlay to fit on the page.

Use width: calc() inside of .recent-news-wrap .overlay {} like this:

.recent-news-wrap .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% - 60px);
  height: 100%;
  opacity: 0;
  border-radius: 0;
  background: #3579DC;
  color: #fff;
  vertical-align: middle;
  -webkit-transition: opacity 500ms;
  -moz-transition: opacity 500ms;
  -o-transition: opacity 500ms;
  transition: opacity 500ms;  
  padding: 30px;
  text-align: center;
}

See fiddle: https://jsfiddle.net/DIRTY_SMITH/2xzj4dqo/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM