skip to Main Content

I’m trying to display a caption when someone hovers over images. But I couldn’t find a way to get this done.

I’m using Twitter Bootstrap.

Here is my HTML for one of the images. I don’t know how to put the content into it, so that it only displays when someone goes with the mouse over it.

  <div class="col-lg-2 col-md-3 col-sm-4 col-xs-12 thumb">
        <a class="thumbnail caption-style-1 model-thumbnail " href="#">
          <img class="img-responsive" src="http://placehold.it/245x347" alt>
        </a>
  </div>

enter image description here

Bootply

2

Answers


  1. div {width: 245px; height: 245px;}
    a {position: relative; display: inline-block;}
    a + span {display: none; position: absolute; top: 0; left: 0; bottom: 0; right: 0;  background: rgba(0,0,0,0.5);}
    a:hover + span {display: block; pointer-events: none;}
    <div class="col-lg-2 col-md-3 col-sm-4 col-xs-12 thumb">
      <a class="thumbnail caption-style-1 model-thumbnail " href="#">
        <img class="img-responsive" src="http://placehold.it/245x347" alt>
      </a>
      <span>Text</span>
    </div>
    Login or Signup to reply.
  2. Here is a cool example inspired of this website.

    ul.img-list {
      text-align: center;
    }
    
    ul.img-list li {
      display: inline-block;
      height: 150px;
      position: relative;
      width: 150px;
    }
    
    span.text-content span {
      display: table-cell;
      text-align: center;
      vertical-align: middle;
    }
    
    span.text-content {
      background: rgba(0,0,0,0.5);
      color: white;
      display: table;
      height: 150px;
      left: 0;
      position: absolute;
      top: 0;
      width: 150px;
      opacity: 0;
    }
    
    ul.img-list li:hover span.text-content {
      opacity: 1;
    }
    <ul class="img-list">
      <li>
          <img src="http://placehold.it/150x150"/>
          <span class="text-content"><span>1st image</span></span>
      </li>
        <li>
          <img src="http://placehold.it/150x150"/>
          <span class="text-content"><span>2nd image</span></span>
      </li>
        <li>
          <img src="http://placehold.it/150x150"/>
          <span class="text-content"><span>3rd image</span></span>
      </li>
    </ul>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search