I would like to add an overlay effect to all images, with text overlaying the image. I tried tutorials but could not get it to work. All the images are located in main.js.
const petsData = [{
name: "Purrsloud",
species: "Cat",
favFoods: ["wet food", "dry food", "<strong>any</strong> food"],
birthYear: 2016,
brick: "brick",
photo: "https://learnwebcode.github.io/json-example/images/cat-2.jpg"
},
{
name: "Barksalot",
species: "Dog",
birthYear: 2008,
photo: "https://learnwebcode.github.io/json-example/images/dog-1.jpg"
},
{
name: "Meowsalot",
species: "Cat",
favFoods: ["tuna", "catnip", "celery"],
birthYear: 2012,
photo: "https://learnwebcode.github.io/json-example/images/cat-1.jpg"
}
];
function petTemplate(pet) {
return `
<div class="animal">
<img class="pet-photo" src="${pet.photo}">
<h2 class="pet-name">${pet.name} <span class="species">(${pet.species})</span></h2>
</div>
`;
}
document.getElementById("app").innerHTML = `
<h1 class="app-title">Pets (${petsData.length} results)</h1>
${petsData.map(petTemplate).join("")}
`;
.img {
max-width: 400px;
position: relative;
}
.app-title {
text-align: center;
font-weight: normal;
font-size: 2.6rem;
}
.animal {
max-width: 650px;
padding: 20px;
margin: 30px auto;
background-color: #fff;
box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.animal h4 {
margin: 0 0 6px 0;
}
.pet-photo {
float: left;
width: 100%;
display: block;
transition: all linear 0.7s;
margin-right: 15px;
position: relative;
}
.pet-name {
font-size: 2rem;
font-weight: normal;
margin: 0 0 1rem 0;
}
.species {
font-size: 0.9rem;
color: #888;
vertical-align: middle;
}
<div id="app"></div>
<script src="main.js"></script>
Thank you.
Edit - Want it to look something like this https://www.youtube.com/watch?v=exb2ab72Xhs&t=475s need to show the text on hover with a black overlay appearing on the back of the text (when hovered on)