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>
Related
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>
I'm trying to centre two buttons but having no luck!
It also has a header image above the buttons within the HTML.
Here's my current HTML:
HTML:
<div>
<img src=".jpg" style="width:700px;display:block;margin-left:auto;margin-right:auto;" alt=""><div class="nav3" style="height:705px;">
<span class="icons"><a href="https://twitter.com/" class="icons">
<img src=".png" style="width:100px;display:block;margin-left:auto;margin-right:auto;" alt=""></a>
</span>
<a href="https://www.amazon.co.uk/" class="icons">
<img src=".png" style="width:100px;display:block;margin-left:auto;margin-right:auto;" alt=""></a>
</div>
I revised your code and separate it the inline style from your html code.
div {
text-align: center;
width: 700px;
}
div img{
width:700px;
margin-bottom: 20px;
}
.nav3 img {
width: 100px;
display: inline;
}
<div>
<img src="http://placehold.it/700x260" alt="">
<div class="nav3">
<img src="http://placehold.it/640x260" alt="">
<img src="http://placehold.it/640x260" alt="">
</div>
</div>
Currently, I set the width of div to width: 700px; and the place holder also contains the same width. Modify these width to suit your needs.
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
I have the following markup:
<div class="photo" style="float: left; margin: 2px;">
<a href="#">
<img src="images/image.jpg" alt="My Image" height="240" width="240" />
</a>
</div>
How can I create a layer on top of the image where I can write some text? The layer should have transparency, be aligned to bottom and having a size of 240x60?
Thanks!
Why not make the image a background?
<div class="photo" style="float:left; margin:2px">
<a href="#" style="background:url('images/image.jpg');
width:240px; height:240px; display:inline-block;">Your text here</a>
</div>
The display:inline-block allows you to apply width and height to an otherwise inline element, but here you might even want to just use display:block since it's the only child of the container.
EDIT: You can even put more containers in it, something like this:
<div class="photo" style="float:left; margin:2px">
<a href="#" style="background:url('images/image.jpg'); position:relative;
width:240px; height:240px; display:block;">
<span style="display:block;position:absolute;bottom:0;left:0;right:0;
background:white;background:rgba(255,255,255,0.25);">Your text here</span>
</a>
</div>
Text blocks over images. Website and demo as follows:
http://css-tricks.com/text-blocks-over-image/
I'll do it like with an image container like that :
Html
<div class="image-container">
<img src="path/to/image" />
<p class="caption">My text</p>
</div>
CSS
.image-container {
position:relative;
}
.caption {
width:100%;
background:rgba(0,0,0,0.5);
color:#ffffff;
position:absolute;
top:0;
}
See fiddle !
Markup
<div class="figure-container">
<img src="http://ipadwallsdepot.com/detail/solid-color_00015061.jpg" width="250" height="250" />
<span class="figure-label">FIG 1.1: Caption Text Here</span>
</div>
<div class="figure-container">
<img src="http://ipadwallsdepot.com/detail/solid-color_00015061.jpg" width="250" height="250" />
<span class="figure-label">FIG 1.2: Another Caption Here</span>
</div>
Stylesheet
.figure-container
{
position: relative;
display: inline-block;
}
.figure-label
{
position: absolute;
bottom: 10px;
right: 10px;
color: White
}
I created a JSFiddle here http://jsfiddle.net/AbBKx/ showing how to absolutely position a child element (label) relative to a parent container.
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; }