Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay Image with text with Bootstrap 4

I'm very new to web development so have mercy with your responses.

I have a grid of images that I want to modify. When the mouse hovers over an image, I want an overlay with text to appear over the image (this may require the cell in the grid to expand to contain all the text).

When the image with the overlay is clicked, it should open a modal (I already have this working) with the full text and info inside.

All changes need to look smooth with transitions (overlay shouldn't just be there when the mouse touches, it should animate in, etc.) when they enter/exit.

I'm not sure what the right terminology is for this, so I'm struggling to find info searching on Google. So, if you could provide me with some resources to learn this, or provide some examples, it'd be much appreciated. Thanks in advance :)

Edit: Here's close to what I want to happen There will be an image, like this:an image in a grid

After the mouse hover over this image, an overlay should animate in to look like this: overlay showing over top of image in grid

The difference between this and what I want, is I want to show text instead of an icon, and I also want the cell in the grid upon which the mouse is hovering to expand to more pleasantly present the text that will be shown on the overlay.

like image 200
loganrussell48 Avatar asked Mar 19 '18 02:03

loganrussell48


People also ask

How do I overlay text on an image in bootstrap 4?

I can say after your <img> tag add the <p class="carousel-caption">Some text here </p> Your text will appear on your image !. Long story , short . Add class=carousel-caption to the HTML tag which contains your text which needs to be positioned over your image !. (And then if you wish add custom css top:xyz% to your .

How do I overlay images in bootstrap?

Image Overlay: Image overlay generally refers to the image being a background image and inserting texts, and links inside of that image. It can be done using the 'card-img-overlay' property that is present in bootstrap. Also, we can do it with normal CSS along with a bootstrap theme.

How do I add text overlay to an image?

One of the simplest ways to add image or text overlay is using CSS properties and pseudo-elements. In short, CSS overlay effects are achieved by using the following: background-image and background CSS properties to add image and linear-gradient overlay effect.

How do I put text and images side by side in bootstrap?

To create image and text side by side use the grid system property of bootstrap and create 2 columns of span 6-6. Put your image in one column and your text in another. On smaller devices, it will automatically align vertically.


2 Answers

You can do this with just css first you need to wrap your image in a div and set the position to relative. Then place the image and the overlay inside of it. Then you can use css transitions to achieve the desired effect. You will set the original opacity of the overlay to 0 and set the hover opacity to 1. Below is an example. Since you haven't posted any code I can't tell what your markup will be so I just made an example.

.img-container{
  position:relative;
  display:inline-block;
}
.img-container .overlay{
  position:absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
  background:rgb(0,170,170);
  opacity:0;
  transition:opacity 500ms ease-in-out;
}
.img-container:hover .overlay{
  opacity:1;
}
.overlay span{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  color:#fff;
}
<div class="img-container">
  <img src="https://placehold.it/300x300">
  <div class="overlay">
    <span>overlay content</span>
  </div>
</div>
like image 138
Steve K Avatar answered Sep 20 '22 09:09

Steve K


Set image as "block"

.img-container{
  position:relative;
  display:inline-block;
}
.img-container img{
display:block
 }
.img-container .overlay{
  position:absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
  background:rgb(0,170,170);
  opacity:0;
  transition:opacity 500ms ease-in-out;
}
.img-container:hover .overlay{
  opacity:1;
}
.overlay span{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  color:#fff;
}
<div class="img-container">
  <img src="https://placehold.it/300x300">
  <div class="overlay">
    <span>overlay content</span>
  </div>
</div>
like image 25
Montaycabe Avatar answered Sep 18 '22 09:09

Montaycabe