I'm working on a template using Bootstrap. I have a little problem with my CSS hover. I just make a hover on div inside div.
This fiddle show my problem: https://jsfiddle.net/iklas/q5Lm7cLe/
When I hover on thumbnail the hover is showing on all parent div product-box.
I want when I hover on product-box the hover showing on just thumbnail div.
How can I solve this problem?
Just add position: relative; to .thumbnail
Updated fiddle
When You hover on thumbnail the hover is showing on all parent beacause you haven't give the css property Position:relative to .thumbnail.
.product-box a {
color: #666;
}
.product-box a:hover {
color: #666;
text-decoration: none;
}
.thumbnail {
position: relative;
}
.thumbnail:hover:before {
background-color: #000;
width: 100%;
height: 100%;
display: block;
position: absolute;
content: "";
top: 0px;
right: 0;
bottom: 0;
left: 0;
margin: auto;
opacity: 0.5;
-webkit-transition: all 0.1s ease;
-moz-transition: all 0.1s ease;
-ms-transition: all 0.1s ease;
-o-transition: all 0.1s ease;
transition: all 0.1s ease;
}
<div class="container">
<div class="row">
<div class="product-box col-md-3 col-sm-4 col-xs-12">
<a href="#">
<div class="thumbnail">
<img src="http://dummyimage.com/100x250/bdbdbd/fff&text=image" alt="...">
</div>
<div class="caption">
<h4 class="product-title">SheIn Grey Contrast Collar Long Sleeve Pleated Dress</h4>
<h4 class="brand-name pull-left"><span>By</span> Day Dresses</h4>
<h4 class="price-number pull-right">$34.56</h4>
<div class="clearfix"></div>
</div>
</a>
</div>
<!-- /.box-product -->
</div>
</div>
Your transition is not working because you haven't used this.
Try this is would work.
.thumbnail:before {
content: "";
transition: all 600ms linear 0s;
}
.thumbnail:hover:before {
background-color: #000;
width: 100%;
height: 100%;
display: block;
position: absolute;
content: "";
top: 0px;
right: 0;
bottom: 0;
left: 0;
margin: auto;
opacity: 0.5;
-webkit-transition: all 600ms ease;
-moz-transition: all 600ms ease;
-ms-transition: all 600ms ease;
-o-transition: all 600ms ease;
transition: all 600ms ease;
}
Related
I have a header with two divs. The two divs are next to each other. I'm using bootstrap with flex box for this. I want to create a sliding effect (and zoom) when hovering over the divs. Hovering over the left div should change the width of both the left and right div.
Tricky part I'm having is that I want to add a diagonal line with the same color as the right div to create a nice look. I've tried creating that with a pseudo after on the right div but the issue is when hovering it will not move with the rest of the div. I had to give it position: absolute to display it outside the right div.
Maybe I'm doing something wrong or maybe there is a better solution. I haven't figured this one out yet.
JSfiddle
https://jsfiddle.net/aq9Laaew/235971/
.header {
z-index: 1;
height: 50vh;
position: relative;
overflow: hidden;
}
.header-img {
width: 60vw;
height: 50vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url(asset_path("bgs/bg-1.jpg"));
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
}
.header-img:hover {
transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
width: 80vw;
}
.header-content {
color: #000000;
background-color: #FFFFFF;
width: 40vw;
height: 50vh;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
overflow-x: visible;
}
.header-content:hover {
width: 80vw;
}
.overlay::after {
content: " ";
display: inline-block;
position: absolute;
width: 20%;
height: 100%;
left: 50%;
border-style: dashed;
border-width: 1em;
border-color: #000000;
}
<div class="header d-flex flex-row">
<div class="header-img"></div>
<div class="header-content">
<div class="overlay"></div>
<div class="d-flex justify-content-center">
<div class="mt-5">
<div class="text-center header-text">
<h2>Text</h2>
</div>
</div>
</div>
</div>
</div>
After some investigation I've fixed the sliding effect of the overlay. I've appended the div.overlay inside the header-content and set postion:relative on .header-content class.
.header {
z-index: 1;
height: 50vh;
position: relative;
overflow: hidden;
}
.header-img {
width: 60vw;
height: 50vh;
background-position: 75% 50%;
background-color: #EFEFEF;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
}
.header-img:hover {
transform: scale(1.1);
width: 100vw;
}
.header-content {
position: relative;
color: #000000;
background-color: #FFFFFF;
width: 40vw;
height: 50vh;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
overflow-x: visible;
}
.header-content:hover {
width: 80vw;
}
.content-text {
position: absolute;
left: -2%;
}
.overlay::after {
content: " ";
display: inline-block;
position: absolute;
width: 70%;
height: 200%;
left: -35%;
top: -60%;
background-color: #FFFFFF;
transform: rotate(10deg);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="header d-flex flex-row">
<div class="header-img"></div>
<div class="header-content">
<div class="overlay"></div>
<div class="d-flex justify-content-center">
<div class="mt-2">
<div class="text-center content-text">
<h3>text</h3>
</div>
</div>
</div>
</div>
</div>
This is a two part problem. The first part is I want the image fade and the text fade to happen at the same time (on a hover over).
The second part is, I thought if I had the <p> tag inside of the <div> then it would "inherit" (I may not be using the term properly) the div properties. The text is supposed to remain fixed center of the image so anytime the image resizes or moves it takes the text with it.
Clearly neither one of those things are happening.
.image-wrapper p {
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 0;
}
.image-wrapper p:hover {
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 100;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}
<div class="image-wrapper">
<img src="http://placehold.it/150x80?text=IMAGE" class="fade" style="width:100%" alt="Image">
<p>This text here</p>
</div>
Here is a link just in case
Check this out and let me know your feedback. Thanks!
The first part is I want the image fade and the text fade to happen at the same time (on a hover over).
For this to happen, add hover to image-wrapper rather than individually to p and the img like the below for instance:
.image-wrapper:hover p {
opacity: 1;
}
.image-wrapper:hover .fade {
opacity: 0.5;
}
The text is supposed to remain fixed center of the image so anytime
the image resizes or moves it takes the text with it.
For this you can use the transform to center align the text over the image responsively.
.image-wrapper p {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
snippet below:
.image-wrapper{
position: relative;
}
.image-wrapper p {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding: 10px;
border: 1px solid #FFF;
opacity: 0;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.image-wrapper:hover p {
opacity: 1;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.image-wrapper:hover .fade {
opacity: 0.5;
}
<div class="image-wrapper">
<img src="http://placehold.it/150x80?text=IMAGE" class="fade" style="width:100%" alt="Image">
<p>This text here</p>
</div>
for first one you can use like that
.image-wrapper:hover{
opacity :0.7;
}
Both 1.) and 2.) - Try this code:
HTML:
<div class="image-wrapper">
<img src="http://placehold.it/150x80?text=IMAGE" class="fade" style="width:100%" alt="Image">
<p class="fade">This text here</p>
</div>
Adding the class="fade" to the <p> will make the transition smoothly for the text as well.
CSS:
.image-wrapper p {
display: none;
color: #F00;
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 0;
}
.image-wrapper p:hover, .image-wrapper:hover p {
display: block;
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 100;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
// When either hovering the p or the image, apply the transition.
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}
So I am looking to have a div's (buttons) background image change on hover AND move 20px left and 20px up on hover. Right now when I hover the div the background image changes on a 0.7s transition like I want it to, but the position change does not have the transition time. Any help on this would be awesome
.buttons:hover{
background: transparent;
background-image: url('image2');
right: 20px;
top: -20px;
}
.buttons{
position: relative;
width:95%;
height: 145px;
background-image: url('image1');
-webkit-transition: all 0.7s ease-out;
-moz-transition: all 0.7s ease-out;
-ms-transition: all 0.7s ease-out;
-o-transition: all 0.7s ease-out;
transition: all 0.7s ease-out;
}
.buttons h3{
position: relative;
top: 50px;
}
.buttoncontainer{
width: 100%;
text-align: center;
}
.buttoncontainer a{
text-decoration: none;
}
<div class="buttoncontainer">
<a href="#">
<div class="buttons">
<h3 style="font-family: helvetica;color:#13506D;">General IP Services <img src="arrow.png" alt="">
</h3>
</div>
</a>
</div>
In order for the animation to work, it needs to transition from something, to your new location. Define top: 0; and right: 0; before the transition.
.buttons:hover{
background: transparent;
background-image: url('image2');
right: 20px;
top: -20px;
}
.buttons{
position: relative;
width:95%;
height: 145px;
right: 0; /* Define right */
top: 0; /* Define top */
background-image: url('image1');
-webkit-transition: all 0.7s ease-out;
-moz-transition: all 0.7s ease-out;
-ms-transition: all 0.7s ease-out;
-o-transition: all 0.7s ease-out;
transition: all 0.7s ease-out;
}
.buttons h3{
position: relative;
top: 50px;
}
.buttoncontainer{
width: 100%;
text-align: center;
}
.buttoncontainer a{
text-decoration: none;
}
<div class="buttoncontainer">
<a href="#">
<div class="buttons">
<h3 style="font-family: helvetica;color:#13506D;">General IP Services <img src="arrow.png" alt="">
</h3>
</div>
</a>
</div>
The vertical alignment of the text on :hover isn't working . Also after hovering, the whole area of posts should be cover with pointer cursor and should be clickable, but it isn't.
HTML
<div class="photoset post-background">
<div class="imgoverlay text-light">
<a href="{Permalink}">
<div class="photos">
{block:Photos}
<img alt="" src="{PhotoURL-500}">
{/block:Photos}
</div>
<div class="overlay">
<span class="overlaycolor"></span>
<div class="overlayinfo">
{block:ContentSource}
<h6>{SourceTitle}</h6>
{block:ContentSource}
</div>
</div>
</a>
</div>
</div>
CSS
.imgoverlay {
position: relative;
overflow: hidden;
display: block;
max-width: 100%;
}
.imgoverlay img {
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
-ms-transition: all .4s ease;
transition: all .4s ease;
}
.imgoverlay .overlay {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 0;
opacity: 0;
filter: alpha(opacity=0);
-ms-filter: "alpha(Opacity=0)";
-webkit-transition: opacity .3s ease;
-moz-transition: opacity .3s ease;
-o-transition: opacity .3s ease;
-ms-transition: opacity .3s ease;
transition: opacity .3s ease;
}
.imgoverlay:hover .overlay {
opacity: 1;
filter: alpha(opacity=100);
-ms-filter: "alpha(Opacity=100)";
}
.imgoverlay .overlaycolor {
width: 100%;
height: 100%;
background: {color:Post Hover};
};
Example http://www.jnck.sk/
Thanks for any help!
Use span with display:block instead of div inside link. Block elements like div shouldn't be in inline blocks.
For vertical align of text you can use i.e. this:
.overlayinfo {
position: relative;
top: 50%;
transform: translateY(-50%);
}
http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
Hello all I have two images that switch on hover. in the divs they are currently in the images overlap, both starting at the top of the div as opposed to beside it.example
<div class="storyboard">
<div class="storycard" >
<img src="Images/Articles/Index/world%20cup2.jpg" class="primary">
<img src="Images/Articles/Index/world%20cup.jpg" class="secondary">
</div>
<div class="storycard">
<img src="Images/Articles/Index/ntci2.jpg" class="primary">
<img src="Images/Articles/Index/ntci1.jpg" class="secondary">
</div>
and my css
.storyboard{
width: 100%;
padding: 30px;
}
.storycard{
position: relative;
float: left;
}
.storycard img{
position: absolute;
margin: 0 auto;
}
.storycard .secondary:hover {
position: absolute;
top: 0;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
-webkit-opacity: 0;
-moz-opacity: 0;
opacity: 0;
display: block;
}
Due to the .storycard .secondry:hover as it is I cant make the .storycard img relative other wise I get this. Thanks.
First of all enclose your all div elements in a #wrapper.
and set the display of #wrapper to display:inline-block;
#wrapper{
width: 100%;
padding: 30px;
display:inline-block;
}
Then give different class to both div elements inside the #wrapper
See the Demo