css top and bottom not working on element - html

I'm trying to position an image text overlay just above the image when it is hovered. top & bottom are not doing the trick.
Here's the code -
.projects {
padding-top: 50px;
}
.desktop-image {
position: relative;
}
.desktop-image:hover img {
-webkit-filter: blur(5px);
filter: blur(5px);
cursor: e-resize;
}
.desktop-image > img {
width: 700px;
}
.img_description {
position: absolute;
top: -13%;
bottom: 0;
left: 0;
right: 0;
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity .7s, visibility .7s;
font-family: inherit;
}
.desktop-image > a:hover .img_description {
visibility: visible;
opacity: 1;
}
<div class="projects">
<div class="desktop-image">
<a class="desktop-image" href="https://www.stellamccartney.com/gb" target="_blank">
<img src="https://www.thesun.co.uk/wp-content/uploads/2017/08/nintchdbpict000342472436.jpg?strip=all&w=960&quality=100">
<p class="img_description">
An event directory that I<br> founded. Development, design &<br> content by me.
</p>
</a>
</div>
</div>

Use the position and width settings on .img-description as shown below. And since you use opacity 0 and 1, you can erase the visibility settings (or vice versa) The text centering is of course optional, as is the white text color (which does improve the visibility, though).
.projects {
padding-top: 50px;
}
.desktop-image {
position: relative;
}
.desktop-image:hover img {
-webkit-filter: blur(5px);
filter: blur(5px);
cursor: e-resize;
}
.desktop-image > img {
width: 700px;
}
.img_description {
position: absolute;
bottom: 13%;
left: 0;
right: 0;
width: 100%;
text-align: center;
color: #fff;
opacity: 0;
transition: opacity .7s, visibility .7s;
font-family: inherit;
}
.desktop-image > a:hover .img_description {
opacity: 1;
}
<div class="projects">
<div class="desktop-image">
<a class="desktop-image" href="https://www.stellamccartney.com/gb" target="_blank">
<img src="https://www.thesun.co.uk/wp-content/uploads/2017/08/nintchdbpict000342472436.jpg?strip=all&w=960&quality=100">
<p class="img_description">
An event directory that I<br> founded. Development, design &<br> content by me.
</p>
</a>
</div>
</div>

Like this?
The a tag was not taking the full height of the image tag because it was set to display:inline which does not have height and width, hence I changed it to display:inline-block so that it will have block properties too, then the element which had position:absolute was getting positioned as usual!
.projects {
padding-top: 50px;
}
.desktop-image {
position: relative;
display: inline-block;
}
.desktop-image:hover img {
-webkit-filter: blur(5px);
filter: blur(5px);
cursor: e-resize;
}
.desktop-image > img {
width: 700px;
}
.img_description {
position: absolute;
top: -13%;
bottom: 0;
left: 0;
right: 0;
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity .7s, visibility .7s;
font-family: inherit;
}
.desktop-image > a:hover .img_description {
visibility: visible;
opacity: 1;
}
<div class="projects">
<div class="desktop-image">
<a class="desktop-image" href="https://www.stellamccartney.com/gb" target="_blank">
<img src="https://www.thesun.co.uk/wp-content/uploads/2017/08/nintchdbpict000342472436.jpg?strip=all&w=960&quality=100">
<p class="img_description">
An event directory that I<br> founded. Development, design &<br> content by me.
</p>
</a>
</div>
</div>
References:
Inline height and width

I agree with #Naren's answer. Just wanted to show the change when I edited the style in Devtools:
Few more changes to .image-description would give you the desired o/p:
remove top property
set bottom: 100%
set padding-bottom: 0 if you want image to be strictly aligned with top of image

Related

Make a paragraph appear inside a picture on picture hover

basically all i want to do is: Have a picture and when someone hovers over it i want some text to appear in its position(in the middle to be exact). What I have done so far is make the picture disappear on hover but i cannot get the text to be appeared..
Html:
<div class="container">
<img id="atp "class="atp" src="atp.jpg">
<div class="center">Some text</div>
</div>
Css:
atp{
display:block;
margin-left:auto;
margin-right:auto;
width:27%;
height:50%;}
container{
position: relative;
text-align: center;
}
.center{
position: absolute;
top:50%;
left:50%;
opacity: 0;
}
So basically, what i seek to be done is .atp:hover{opacity:0;} and what I also want is on atp's hover the .center{opacity:1;] So is there a way to put the opacity of center's to 1 when I am in the atp:hover{} code block?
Hope everything looks fine, thanks in advance!
Here is the code. Hope it will help you. if any changes please let me know.
/********* Simple or original overlay *******/
/* Main container */
.overlay-image {
position: relative;
width: 100%;
}
/* Original image */
.overlay-image .image {
display: block;
width: 100%;
height: auto;
}
/* Original text overlay */
.overlay-image .text {
color: #fff;
font-size: 30px;
line-height: 1.5em;
text-shadow: 2px 2px 2px #000;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
/********* Overlay on hover *******/
/* New overlay on hover */
.overlay-image .hover {
position: absolute;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
/* New overlay appearance on hover */
.overlay-image:hover .hover {
opacity: 1;
}
/********* Background and text only overlay on hover *******/
.overlay-image .normal {
transition: .5s ease;
}
.overlay-image:hover .normal {
opacity: 0;
}
.overlay-image .hover {
background-color: rgba(0,0,0,0.5);
}
<div class="overlay-image">
<a href="LINK_URL">
<div class="normal">
<div class="text">Image + text ORIGINAL</div>
</div>
<div class="hover">
<img class="image" src="https://dummyimage.com/200x150/00ccff/fff.png" alt="Alt text hover" />
</div>
</a>
</div>
#atp {
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
width: 27%;
height: 50%;
z-index: 50;
}
.container {
position: relative;
text-align: center;
}
.center {
position: absolute;
top: 50%;
left: 50%;
z-index: 30;
}
#atp:hover {
opacity: 0;
}
try this, using z-index. It worked with me :)

Make the text to be in the middle of the image when mouse hovers over the image

I wanted to add a heading(bold) and a subheading(not bold) on all the images on a webpage when mouse hovers over it. I already have the effect where the image fades/changes color upon hovering. Following is the image: https://imgur.com/a/xLXSUkx
Here's the HTML code for it:
<div class="JA-linkWrap JA-Notprojects JA-NotObjects floatleft" style="width:300px;">
<a href="https://canadacouncil.ca/initiatives/venice-biennale"
class="JA-projectPageLink">
<img src="images/GRID/111%20jpeg%20grid.jpg" alt="" class="JA-
newsmediaImage">
<h2 class = "img_head"> The Octa. </h2>
<p class = "img_description"> Arch. </p>
</a>
</div>
This is the CSS for .JA-linkWrap:
.JA-linkWrap {
float: left;
margin: 12px;
}
More CSS:
* {
margin: 0;
padding: 0;
border: 0;
}
.JA-linkWrap img:hover {
-webkit-filter: brightness(90%);
}
.img_head{
position: absolute;
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity.2s, visibility .2s;
}
.img_description{
position:inherit;
color:#000;
visibility: hidden;
opacity: 0;
transition: opacity.2s, visibility .2s;
}
.JA-linkWrap:hover .img_description{
visibility: visible;
opacity: 1;
}
.JA-linkWrap:hover .img_head{
visibility: visible;
opacity: 1;
}
Here's the outcome of my attempt when I hover the mouse over the image: https://imgur.com/a/Fkuf0eE As you can see the heading and description of the image are both under the image. I want them to be in the center of the image. Please be specific, I am new to this.
You should add a wrapper to the title elements, and then set the size of the wrapper like the box of the image. Then use flexbox to vertically align titles inside the wrapper. Also, remove inline styles for width: 300px
.JA-linkWrap {
float: left;
margin: 12px;
position: relative;
}
* {
margin: 0;
padding: 0;
border: 0;
}
.JA-linkWrap:hover img {
-webkit-filter: brightness(90%);
}
.img_head{
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity.2s, visibility .2s;
}
.img_description{
color:#000;
visibility: hidden;
opacity: 0;
transition: opacity.2s, visibility .2s;
}
.JA-linkWrap:hover .img_description, .JA-linkWrap:hover .img_head {
visibility: visible;
opacity: 1;
}
.title-wrapper {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
flex-wrap: wrap;
}
.title-wrapper .img_head, .title-wrapper .img_description {
background-color: white;
}
<div class="JA-linkWrap JA-Notprojects JA-NotObjects floatleft">
<a href="https://canadacouncil.ca/initiatives/venice-biennale"
class="JA-projectPageLink">
<img src="https://picsum.photos/id/237/500/300" alt="" class="JA-
newsmediaImage">
<div class="title-wrapper">
<h2 class = "img_head"> The Octa. </h2>
<p class = "img_description"> Arch. </p>
</div>
</a>
</div>

Div taking up full width of page

I've implemented a hover state that overlays text when a div is hovered.
Here is the code -
.desktop-image {
position: relative;
}
.img_description {
position: absolute;
top: -13%;
bottom: 0;
left: 0;
right: 0;
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity .7s, visibility .7s;
}
.desktop-image:hover .img_description {
visibility: visible;
opacity: 1;
}
<div id="images" class="misma">
<div class="desktop-image">
<img src="http://via.placeholder.com/200x200">
<p class="img_description">This image looks super neat.</p>
</div>
<div class="mobile-image-misma">
<img src="http://via.placeholder.com/100x100">
</div>
</div>
The problem
When I inspect the page I notice that the div .desktop-image is taking up the full width of the screen (see pic).
Question
How can I make this div wrap to the size of the actual image, so that the hover state is ONLY implemented when that image is hovered, as opposed to when anywhere within the blue section is hovered.
Thanks
By default div's are defined with display: block, meaning that they will take the entire available width.
You can specify that .desktop-image will be display: inline-block; and you will get the wanted result.
My suggestion to you is to use semantic HTML, there are 2 element that are dedicated to what you trying to achieve figure & figcaption.
Added an example with them.
.desktop-image {
position: relative;
display: inline-block;
}
.desktop-image img {
vertical-align: middle;
}
.img_description {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity .7s, visibility .7s;
}
.desktop-image:hover .img_description {
visibility: visible;
opacity: 1;
}
<div id="images" class="misma">
<div class="desktop-image">
<img src="http://via.placeholder.com/200x200">
<p class="img_description">This image looks super neat.</p>
</div>
<div class="mobile-image-misma">
<img src="http://via.placeholder.com/100x100">
</div>
<figure class="desktop-image">
<img src="http://via.placeholder.com/200x200">
<figcaption class="img_description">This image looks super neat.</figcaption>
</figure>
</div>
Please see this.
.desktop-image {
position: relative;
display: inline-block;
}
.img_description {
position: absolute;
top: -13%;
bottom: 0;
left: 0;
color: #000;
visibility: hidden;
opacity: 0;
transition: opacity .7s, visibility .7s;
right:0;
}
.desktop-image:hover .img_description {
visibility: visible;
opacity: 1;
}
<div id="images" class="misma">
<div class="desktop-image">
<img src="http://via.placeholder.com/200x200">
<p class="img_description">This image looks super neat.</p>
</div>
<div class="mobile-image-misma">
<img src="http://via.placeholder.com/100x100">
</div>
</div>
By default div tag has a default display property display: block
In your code
<div class="desktop-image"> div appear full width of the display
set a width: and a min-height: property to solve the problem
.desktop-image {
position: relative;
width: 200px; /*new*/
height: 200px; /*new*/
}
Add CSS property clear: both to the div with the class desktop-image.
Specify the width of the .desktop-image class in percentage like .desktop-image{width:70%;} or whatever percentage suit the page design.
By doing that image will remain in this .desktop-image div.

hover appearing and disappearing

Right now I have an image that has another image absolutely positioned on top of the first one. Both images are inside an a tag.
I am trying to get it so that when I hover on any part of the first image, both the first image goes from .5 opacity to full, and the 2nd image goes from 0 opacity to full.
I've been able to make the hover work for the image but the 2nd image only activates it's opacity when I hover directly on it, rather than highlighting both when I'm on either of them.
<div class="of-volume image-column">
<a href="http://www.greatlengthshair.co.uk/hair-extensions/">
<img src="img/artistry-1-bg.jpg" alt="artisans of volume link" class="image-link">
<img src="img/artistry-1-icon.png" alt="" class="artisan-icon">
</a>
</div>
/*//////////////////////////////////////
IMAGE NAV
//////////////////////////////////////*/
.image-column {
background-color: black;
float: left;
width: 33.3333%;
position: relative;
margin-bottom: -3px;
}
.image-column a {
opacity: .5;
}
.image-column a:hover {
opacity: 1;
}
.artisan-icon {
position: absolute;
margin-right: auto;
margin-left: auto;
right: 0;
left: 0;
bottom: 25px;
}
You have mixed up most of your CSS rules. Just attach the desired effects to the correct hover state:
.image-link { opacity: 0.5; }
.artisan-icon { opacity: 0; }
a:hover .image-link { opacity: 1; }
a:hover .artistan-icon { opacity: 1; }
I put both absolute images inside a relative div, then did set the :hover selector on this container.
body {
width: 100%;
height: 100%;
margin: 0px;
}
#container {
position:relative;
width:100%;
height:200px;
}
img {
position:absolute;
top: 0px;
left:0px;
width:100%;
height:200px;
-webkit-transition: opacity 1s; /* Safari */
transition: opacity 1s;
}
#pic1 {
opacity:0.0;
}
#pic2 {
opacity:0.5;
}
#container:hover #pic1, #container:hover #pic2 {
opacity: 1;
}
<div id=container>
<img id=pic1 class=picture src="http://i.imgur.com/tMVGqP6.jpg" alt=img>
<img id=pic2 class=picture src="http://i.imgur.com/Goy7oBy.gif" alt=img>
</div>

Higher z-index does not change stacking order

What I am trying to do is, when the user hover on the image the image should reposition along the x-axis and it should reveal the .content. i have set z-index: 10 to image and z-index: 1 to .content to make .content to be underneath the image. but .content still remains on top of the image. Please help me..
Here is my code:
html
<div class="holder">
<img src="http://placehold.it/350x150" />
<div class="content">
<h3>hello there</h3>
view more
<div/>
</div>
css
.holder {
margin-top: 130px;
position: relative;
}
img {
display: block;
transition: -webkit-transform 0.5s;
transition: -moz-transform 0.5s;
z-index: 10;
}
.content {
background: blue;
height: 100%;
color: white;
z-index: 1;
position: absolute;
top: auto;
bottom: 0;
}
a {
color: white;
background: red;
padding: 10px;
}
.holder:hover img {
-webkit-transform: translateX(90px);
-moz-transform: translateX(90px);
}
Here I corrected issue of my code thanks to Jones G. Drange. As he pointed out in his comment
"z-index can only be modified in elements with a position other than static. Your img has position: static by default"
jsfiddle
img {
position: relative;
}