I have a site with a portfolio image, when the image is hovered on, an overlay appears.
I have implemented this in such a way that it means when the code is multiplied (for 3 different portfolio items) the overlay is always only over the first image, rather than on each different image being rolled-over.
Can anyone help?
Live link is here
The code used to make the image overlay:
CSS:
.image {
position: relative;
height: 240px;
}
.hoverimage {
position: absolute;
top: 5px;
left: 25px;
display: none;
}
.image:hover .hoverimage {
display: block;
}
HTML:
<img src="images/portfolio_image_1.png" class="captionme"
title="I am the only son" alt="Porfolio detail" />
<img src="images/portfolio_image_1.png" class="captionme"
title="I am the only son" alt="Porfolio detail" />
<img src="images/portfolio_image_1.png" class="captionme"
title="I am the only son" alt="Porfolio detail" />
To overlay on each different image being rolled-over, you'll have to make some changes in your HTML and CSS files. In your HTML file search for <div class="image"> and put each <img class="hoverimage"> element inside <div class=""imgpost">:
<div class="image">
<div class="imgpost">
<img src="images/portfolio_image_1.png" class="captionme" title="I am the only son" alt="Porfolio detail">
<div class="thecaption">I am the only son</div>
<img class="hoverimage" src="images/portfolio_overlay.png" alt="">
</div>
<div class="imgpost">
<img src="images/portfolio_image_1.png" class="captionme" title="I am the only son" alt="Porfolio detail">
<div class="thecaption">I am the only son</div>
<img class="hoverimage" src="images/portfolio_overlay.png" alt="">
</div>
<div class="imgpost">
<img src="images/portfolio_image_1.png" class="captionme" title="I am the only son" alt="Porfolio detail">
<div class="thecaption">I am the only son</div>
<img class="hoverimage" src="images/portfolio_overlay.png" alt="">
</div>
</div>
Then in your CSS add/modify the folowing styles:
.hoverimage { position: absolute; top: 1px; left: 1px; display: none;}
.imgpost .hoverimage {
border: none;
background: none;
}
.imgpost:hover .hoverimage {
display: block;
}
Then delete this style:
.image:hover .hoverimage { display: block; }
Related
I have a wordpress site and I am using the spacious theme. And what I want to archive is just a green box under de image slider. So the code of the image slider is like this:
<section id="featured-slider">
<div class="slider-cycle" style="height: 465.922px;">
<nav id="controllers" class="clearfix">
<a class="active"/>
<a class=""/>
<a class=""/>
<a class=""/>
<a class=""/>
</nav>
<div class="slides displayblock cycle-slide cycle-slide-active" style="position: absolute; top: 0px; left: 0px; z-index: 99; opacity: 1; display: block; visibility: visible;">
<figure>
<img class="lazy loaded" width="1500" height="655" alt="" src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/slide-1-meeuwen-1500-655-slider-2.png" data-src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/slide-1-meeuwen-1500-655-slider-2.png" data-was-processed="true">
</figure>
<div class="entry-container">
<div class="clearfix"/>
<a class="slider-read-more-button" href="https://www.nieuwdenhaag.nl/doe-mee-2/" title="">Doe mee</a>
</div>
</div>
<div class="slides displaynone cycle-slide" style="position: absolute; top: 0px; left: 0px; z-index: 97; visibility: hidden; opacity: 0; display: block;">
<figure>
<img class="lazy loaded" width="4950" height="2162" alt="" src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/Mensen-in-het-park-Den-Haag.png" data-src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/Mensen-in-het-park-Den-Haag.png" data-was-processed="true">
</figure>
<div class="entry-container">
<div class="clearfix"/>
<a class="slider-read-more-button" href="https://www.nieuwdenhaag.nl/steun-ons/" title="">Steun ons</a>
</div>
</div>
<div class="slides displaynone cycle-slide" style="position: absolute; top: 0px; left: 0px; z-index: 96; visibility: hidden; opacity: 0; display: block;">
<figure>
<img class="lazy loaded" width="4350" height="1899" alt="" src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/slide-3-zomer-Den-Haag-kinderen-spelen-slider.png" data-src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/slide-3-zomer-Den-Haag-kinderen-spelen-slider.png" data-was-processed="true">
</figure>
<div class="entry-container">
<div class="clearfix"/>
<a class="slider-read-more-button" href="https://www.nieuwdenhaag.nl/verbind-op-locatie-of-thema/" title="">Verbind op locatie of thema</a>
</div>
</div>
<div class="slides displaynone cycle-slide" style="position: absolute; top: 0px; left: 0px; z-index: 95; visibility: hidden; opacity: 0; display: block;">
<figure>
<img class="lazy loaded" width="4799" height="2095" alt="" src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/terras-vol-Den-Haag-blur-TEST-5250-2095-TEST.png" data-src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/terras-vol-Den-Haag-blur-TEST-5250-2095-TEST.png" data-was-processed="true">
</figure>
<div class="entry-container">
<div class="clearfix"/>
<a class="slider-read-more-button" href="https://www.nieuwdenhaag.nl/word-lid/" title="">Word lid en één van ons</a>
</div>
</div>
<div class="slides displaynone cycle-slide" style="position: absolute; top: 0px; left: 0px; z-index: 100; visibility: hidden; opacity: 0; display: block;">
<figure>
<img class="lazy loaded" width="4200" height="1834" alt="" src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/surfers-strand-test-4200-1834-ICARUS-2.png" data-src="https://www.nieuwdenhaag.nl/wp-content/uploads/2022/07/surfers-strand-test-4200-1834-ICARUS-2.png" data-was-processed="true">
</figure>
<div class="entry-container">
<div class="clearfix"/>
<a class="slider-read-more-button" href="https://www.nieuwdenhaag.nl/evenementen/" title="">Evenementen >>> agenda</a>
</div>
</div>
</div>
</section>
And I try it with css like this:
#featured-slider img {
border-bottom: 70px solid #72BF44;
width: 1067x;
height: 466px;
}
But this is not the correct way. Because the images are transforming. And also the greenbox takes space from the images.
And I also want to have some text in the green box.
So I have added a image how it have to look like.
With the text in the green box. And I am using the Guttenberg layout for editing the pages.
if I do it with the option: "Custom HTML" in the Gutenberg page.
It already looks better. But how to make this full width. Like the images above?
There is a class inner-wrap:
<div class="inner-wrap">
<div id="primary">
<div id="content" class="clearfix">
<div style="background:#72BF44;height:70px;width: 100%;"></div>
</div>
with the css:
.inner-wrap {
width: 94%;
}
.inner-wrap {
margin: 0 auto;
max-width: 1218px;
}
So how to overrule the inner-wrap, so that the greenbox has the full widht of the images?
Add an "Custom HTML" block with this content:
<div style="background:#72BF44;height:70px"></div>
I'm trying to put an link below an image and for whatever reason, the link just keeps going to the side (right) of the picture. The image displays fine and the link works, but I just need it underneath the picture.
Any ideas?
HTML:
<div class="images">
<img src="imgs/2.jpeg" width="280" height="350" alt="Exterior" />
<a class="link1" href="https://www.google.com">Test</a>
</div>
CSS:
.images {
position: absolute;
left:10px;
top: 200px;
font-size: 120%;
}
I'm new to HTML/CSS so if anyone can explain in easy terms, I would really appreciate it. I have tried lots of different things such as span, align etc and it just won't work!
If I use a p statement instead of a ULR (h ref) the text does go below the image, so I'm baffled!
Images are by default inline-element 8though treated as inline-block). All you need to do, is to set the image as block-level element with : img { display: block; }
img {
display: block;
}
<div class="images">
<img src="https://via.placeholder.com/100.jpg" width="280" height="350" alt="Exterior" />
<a class="link1" href="https://www.google.com">Test </a>
</div>
You can use display flex to make this a column.
Explanation: https://www.w3schools.com/css/css3_flexbox_container.asp
.images {
position: absolute;
left: 10px;
top: 200px;
font-size: 120%;
display: flex;
flex-direction: column;
}
<div class="images">
<img src="imgs/2.jpeg" width="280" height="350" alt="Exterior" />
<a class="link1" href="https://www.google.com">Test </a>
</div>
You could add the break line tag below the image tag.
<div class = "images">
<img src="imgs/2.jpeg" width="280" height="350" alt="Exterior" />
<br>
<a class="link1" href = "https://www.google.com" >Test </a>
</div>
The text representing each image is currently located to the right of the image. I want the text to be centered underneath its corresponding image, how do I achieve this?
Please note that I applied display: inline-bock on the list items, so they are in a row.
#footer1 {
float: left;
width: 100%;
border: 10px solid #e3e3e3;
}
#footer1>ul>li {
padding: 0 8px;
display: inline-block;
}
#footer1 a:hover img {
border: 1px solid #5cadff;
text-decoration: none;
box-shadow: 5px 5px 2px 2px #5cadff;
}
#footer1 img {
border: 1px solid transparent;
margin-left: 110px;
}
<div id="footer1">
<h2> SOURCES </h2>
<ul>
<li>
<a href="https://www.wikipedea.com" title="wikipedia">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
w
</li>
<li>
<a href="https://www.google.com" title="google">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Google
</li>
<li>
<a href="https://www.youtube.com" title="youtube">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Youtube
</li>
<li>
<a href="https://www.nlm.nih.gov/" title="Nih.gov">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Nih
</li>
<li>
<a href="https://www.medindia.net" title="MedIndia.net">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
MedIndia
</li>
</ul>
</div>
I was able to do this without any changes to your existing HTML by doing this:
li{
display:inline-block;
text-align:center;
width:70px;
}
li img{
margin:0 10px;
}
The text-align centers all text and child elements inside the li. The width needs to be large enough that no caption will be too large to fit in that width. (If a caption won't fit in the allotted width, then the centering is wrecked.)
I added the left and right margin to the image for a little bit of future-proofing in case you later want to include a very short caption in your list. With that margin, even a very short caption will be forced to the next line (instead of next to the image) since 50 px image width + 10 margin on each side leaves no room for text.
Edited for float, keeps these inline and overflows if doesn't fit on page.
<style>
.container {
clear: both;
}
ul li {
width: 50px;
float: left;
text-align: center
}
ul li a {
text-decoration: none;
}
</style>
<div class="container">
<ul>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
</ul>
</div>
Please try this
HTML:
<div id="footer1">
<h2> SOURCES </h2>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
</div>
CSS:
div.item {
vertical-align: top;
display: inline-block;
text-align: center;
width: 120px;
}
img {
width: 100px;
height: 100px;
background-color: grey;
}
.caption {
display: block;
}
DEMO
Hey I'm working on a portfolio page (just using HTML and CSS) and I created a grid of images. My plan is that the one image that is hovered over gets transparent (0.2 transparency or so) and a description text appears at this field.
I created following code, but this makes my description text transparent as well.
How can I get the text to stay fully visible?
HTML:
<div id="imagelist">
<a href="">
<img src="img/img1.jpg" width="200px" height="200px" alt="Image 1" />
<p class="imgtext">This is the description text.
</p>
</a>
</div>
Can you help me with the CSS part?
I just worked on it
Made some changes try it out
<style>
#imagelist a {position: relative;display: inline-block;}
#imagelist a p{display: none;}
#imagelist a:hover p{position: absolute;width: 100%;height: 100%;background: #000;opacity: 0.8;top: 0;left: 0;margin: 0;display: block;}
#imagelist a p span{display: inline-table;width: 100%;height: 100%;text-align: center;color:#fff;}
#imagelist a p span span{display: table-cell;vertical-align: middle;}
</style>
<div id="imagelist">
<a href="">
<img src="img/img1.jpg" width="200px" height="200px" alt="Image 1" />
<p class="imgtext">
<span>
<span>This is the description text.</span>
</span>
</p>
</a>
</div>
It looks quite simple just added some few extra tags with it. Try it out and let me know the feedback
When the div is in a hover state target the Image element to change opacity and change the display property for the description.
#imagelist:hover img {
opacity: .2;
}
#imagelist:hover .imgtext {
display: block;
}
.imgtext {display: none;}
<div id="imagelist">
<a href="">
<img src="img/img1.jpg"
width="200px"
height="200px"
alt="Image 1"/>
<p class="imgtext">This is the description text.
</p>
</a>
</div>
Do you mean the text should appear behind the transparent picture? Also, are all thumbnails 200px by 200px?
If yes, you could do it like this:
#imagelist a {
width: 200px;
height: 200px;
position: relative;
display: block;
}
#imagelist img {
position: absolute;
left: 0;
top: 0;
bottom: 100%;
height: 100%;
z-index: 1;
}
#imagelist img:hover {
opacity: 0.2;
}
<div id="imagelist">
<a href="">
<img src="http://s0.geograph.org.uk/geophotos/03/97/06/3970600_94c29e78.jpg" />
<p class="imgtext">This is the description text.
</p>
</a>
</div>
My image gallery works fine when rolling over, although in the section where the images enlarge to, i'd like the first image in the gallery to automatically appear in there, at the moment it just displays a blank box until you hover over the image.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css.css"/>
<title>Welcome!</title>
</head>
<div id="wrapper">
<body>
<div id="header">
<div id ="logo">
<embed src="Media/Images/logo.svg" type="image/svg+xml" />
</div>
<div id="icons">
<img src="Media/Images/EnvelopeIcon.png" alt="Envelope Icon" height="25" width="30">
<p>M015734a#student.staffs.ac.uk</p>
<div class="clear">
</div>
<img src="Media/Images/PhoneIcon.png" alt="Envelope Icon" height="25" width="30" />
<p> 07904921417</p>
<div class="clear">
</div>
<img src="Media/Images/HouseIcon.png" alt="Envelope Icon" height="25" width="30">
<p>Stafford, UK</p>
<div class="clear">
</div>
<div class="clear">
</div>
</div>
</div>
<nav>
<div id ="NavBar">
<div id="Nav1">
<div id="Triangle1"></div>
<h2>About Me</h2>
</div>
<div id="Nav2">
<div id="Triangle2"></div>
<h2>Education</h2>
</div>
<div id="Nav3">
<div id="Triangle3"></div>
<h2>Portfolio</h2>
</div>
<div id="Nav4">
<div id="Triangle4"></div>
<h2>Interests</h2>
</div>
<div id="Nav5">
<div id="Triangle5"></div>
<h2>Contact Me</h2>
</div>
</div>
</nav>
<article>
<section id = "content">
<h1>Portfolio Work</h1>
<div class="gallerycontainer">
<a class="thumbnail"><img src="Media/Images/Tardis.bmp" width="225px" height="125px" border="0" /><span><img src="Media/Images/Tardis.bmp" width="750px" height="450px"/><br />3DS Tardis Model.</span></a>
<br />
<a class="thumbnail"><img src="Media/Images/Main Station.png" width="225px" height="125px" border="0" /><span><img src="Media/Images/Main Station.png" width="750px" height="450px" /><br /></span></a>
<br />
<a class="thumbnail"><img src="Media/Images/Claymation1.JPG" width="225px" height="125px" border="0" /><span><img src="Media/Images/Claymation1.JPG" width="750px" height="450px"/><br />Sushi for dinner anyone?</span></a>
<br/>
<a class="thumbnail"><img src="Media/Images/DSC_0245.jpg" width="175px" height="125px" border="0" /><span><img src="Media/Images/DSC_0245.jpg" width="500px" height="450px"/><br />Run wild with horses.</span></a>
<br />
<a class="thumbnail"><img src="Media/Images/DSC_0043 (3).JPG" width="225px" text-align="center" height="125px" border="0" /><span><img src="Media/Images/DSC_0043 (3).JPG" width="750px" height="450px"/><br />Run wild with horses.</span></a>
</div>
</section>
</section>
</article>
</div>
<footer>
</footer>
</body>
</html>
.gallerycontainer{
position: relative;
height: 250px;
/*Add a height attribute and set to largest image's height to prevent overlaying*/
}
.thumbnail img{
border: 1px solid white;
margin: 0 5px 5px 0;
}
.thumbnail:hover{
background-color: transparent;
}
.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: lightyellow;
padding: 5px;
left: -1000px;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{ /*CSS for enlarged image*/
padding: 2px;
}
.thumbnail:hover span{ /*CSS for enlarged image*/
background-color: #333;
visibility: visible;
top: 0;
left: 250px; /*position where enlarged image should offset horizontally */
z-index: 50;
}
I would not hide the first image but give it a low z-index so the other images float over it. This will only work though if the images are the same dimensions.
HTML
<div class="gallerycontainer">
<a class="thumbnail"><img src="Media/Images/Tardis.bmp" width="225px" height="125px" border="0" /><span class="first"><img src="Media/Images/Tardis.bmp" width="750px" height="450px"/><br />3DS Tardis Model.</span></a>
<br />
<a class="thumbnail"><img src="Media/Images/Main Station.png" width="225px" height="125px" border="0" /><span><img src="Media/Images/Main Station.png" width="750px" height="450px" /><br /></span></a>
<br />
CSS
.thumbnail:hover span, .thumbnail span.first{ /*CSS for enlarged image*/
background-color: #FFF;
visibility: visible;
top: 0;
left: 250px; /*position where enlarged image should offset horizontally */
z-index: 50;
}
.thumbnail span.first
{
z-index: 10 !important; /*Lower z-index for first one so others appear above it */
}
UPDATE
From the code in your fiddle you've missed 2 important things in the implementing this:
Note the two selectors here (first line of my CSS code snippet): .thumbnail:hover span, .thumbnail span.first. You only have your original selector. -- this applies the same style to the "first" span as the "hovered" span
The leading "." is missing in your code for .thumbnail span.first -- this adjusts the z-index for the "first" span so the others will appear above it.
Update 2
The span needs a background colour to mask the text of the first image. Also if the image has transparency, without the background color the first image will show though. The update fiddle shows this.
Example Fiddle