delaying the hover of background- image [duplicate] - html

This question already has answers here:
CSS3 background image transition
(13 answers)
Closed 7 years ago.
CSS
.navbar-brand {
display: block;
margin: 0; padding: 0;
height: 80px;
width: 70px;
background: url('img/logo_orig.png') no-repeat center center;
background-size: 100% auto;
}
.navbar-brand:hover {
background: url('img/logo_hov.png') no-repeat center center;
background-size: 100% auto;
}
This creates a button with a background image, when hovered it hnages the background.
I want to add a delay to the background image when hovered. similar to using
transition: background-color 0.35s ease;

You can use something like this.
HTML:
#cf {
position: relative;
height: 281px;
width: 450px;
margin: 0 auto;
}
#cf img {
position: absolute;
left: 0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
height:inherit;
width:inherit;
}
#cf img.top:hover {
opacity: 0;
}
<div id="cf">
<img class="bottom" src="http://www.psdgraphics.com/file/colorful-triangles-background.jpg" />
<img class="top" src="http://cdp.pasctunisie.org/wp-content/uploads/2015/05/light-circles-wave-powerpoint-backgrounds.jpg" />
</div>

Related

Making floating image transparent on hover causes it to 'jump' [duplicate]

This question already has answers here:
image moves on hover - chrome opacity issue
(14 answers)
Closed 5 years ago.
I want to make an image that's wrapped in an a tag darken on hover. To do this I simply made the wrapping a tag's background black and applied:
a:hover > img {
opacity: .8;
-webkit-transition: opacity .2s ease-out;
transition: opacity .2s ease-out;
}
to the image.
This works, but I get a weird 'jumpy' issue when image element containers have float: left; or display: inline-block; applied. This only occurs on some images.
You can see this happening here when you hover over the middle image: https://jsfiddle.net/4566a85t/
Would anyone know how I could prevent this?
My code is:
HTML
<div class="wrapper">
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTojc9ycyhwL6TnP_lEhQrTXy8Cjrs738WeDmnDOmIXGmR20NEJTw">
</a>
</div>
<div class="wrapper">
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTojc9ycyhwL6TnP_lEhQrTXy8Cjrs738WeDmnDOmIXGmR20NEJTw">
</a>
</div>
<div class="wrapper">
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTojc9ycyhwL6TnP_lEhQrTXy8Cjrs738WeDmnDOmIXGmR20NEJTw">
</a>
</div>
CSS
.wrapper {
width: 25%;
float: left;
}
a {
background: black;
display: block;
}
img {
width: 100%;
margin: 0;
}
a:hover > img {
opacity: .8;
-webkit-transition: opacity .2s ease-out;
transition: opacity .2s ease-out;
}
EDIT:
I tried using -webkit-filter: brightness(70%); with no black background, but had the same issue. Seems to be the transition that's the problem.
I think you need to reset the browser default css first and add in -webkit-backface-visibility: hidden to image as suggested in the comments
*{
margin: 0;
padding: 0;
}
img{
-webkit-backface-visibility: hidden;
}
Source:
image moves on hover - chrome opacity issue
Example:
* {
margin: 0;
padding: 0;
}
.wrapper {
width: 25%;
display: inline-block;
}
a {
background: black;
display: block;
}
img {
-webkit-backface-visibility: hidden;
width: 100%;
margin: 0;
}
a>img {
opacity: 1;
}
a:hover>img {
opacity: .8;
-webkit-transition: opacity .2s ease-out;
transition: opacity .2s ease-out;
}
<div class="wrapper">
<img src="https://i.pinimg.com/736x/e5/0d/17/e50d177765012ab2e70f8bccb5dc884a--pug-puppies-pug-dogs.jpg">
</div>
<div class="wrapper">
<img src="https://i.pinimg.com/736x/e5/0d/17/e50d177765012ab2e70f8bccb5dc884a--pug-puppies-pug-dogs.jpg">
</div>
<div class="wrapper">
<img src="https://i.pinimg.com/736x/e5/0d/17/e50d177765012ab2e70f8bccb5dc884a--pug-puppies-pug-dogs.jpg">
</div>
My theory is that when it starts to animate CSS doesn't know the right size that's why it's like adjusting during the first frames.
But if you will set a fixed width of the wrapper. e.g.
.wrapper {
display: inline-block;
width:100px;
}
Cheers!
EDIT: below will only work for Webkit browsers
OK got it!
I used -webkit-filter: brightness(); and set the initial img to -webkit-filter: brightness(100%);
My new code:
a > img {
-webkit-filter: brightness(100%);
}
a:hover > img {
-webkit-filter: brightness(70%);
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
Update fiddle: https://jsfiddle.net/4566a85t/2/

Image does not fit to background image

I am trying to build a page using bootstrap and css where when a mouse pointer is placed on an image, the image will fade and the background image will show. Image fades fine but does not fit though all of them is 100px in size(in all dimensons) and white space is seen.Link:http://codepen.io/Ishtiaque/pen/ONPRyp?editors=1100
Here is my code:
<div class="portfolio">
<h2>Portfolio</h2>
<div class="row position">
<div id="project1" class="col-xs-6">
<img src="http://thumb1.shutterstock.com/display_pic_with_logo/3617441/376416154/stock-vector-phonebook-icon-phonebook-icon-eps-phonebook-icon-vector-phonebook-icon-eps-phonebook-icon-jpg-376416154.jpg">
</div>
<div id="project1" class="col-xs-6">
<img src="http://thumb1.shutterstock.com/display_pic_with_logo/3617441/376416154/stock-vector-phonebook-icon-phonebook-icon-eps-phonebook-icon-vector-phonebook-icon-eps-phonebook-icon-jpg-376416154.jpg">
</div>
</div>
</div>
CSS part:
#project1 {
background-image: url("https://t1.ftcdn.net/jpg/00/33/60/96/160_F_33609643_L3xInzQroBP4PX8zaZICZqofvvfRxZW9.jpg");
background-size: 100px;
width: 100px;
height: 100px;
}
#project1 img {
width: 100px;
height: 100px;
-webkit-transition: all ease 1s;
-moz-transition: all ease 1s;
-o-transition: all ease 1s;
-ms-transition: all ease 1s;
transition: all ease 1s;
}
#project1 img:hover {
opacity: 0;
}
.portfolio {
padding-top: 50px;
overflow: auto;
background: url(http://4k-background.com/highresolution/l_011.jpg)no-repeat center center fixed;
background-size: cover;
height: 500px;
}
.position {
padding-left: 70px;
}
Just tweaked with ur codepen and fixed it, there was padding on the div in the background. I set padding: 0px; and its good now.
CSS
#project1{
background-image:url("https://t1.ftcdn.net/jpg/00/33/60/96/160_F_33609643_L3xInzQroBP4PX8zaZICZqofvvfRxZW9.jpg");
background-size: cover;
padding: 0px;
}
#project1 {
-webkit-transition: all ease 1s;
-moz-transition: all ease 1s;
-o-transition: all ease 1s;
-ms-transition: all ease 1s;
transition: all ease 1s;
}
#project1 img:hover {
opacity: 0;
}
.portfolio{
padding-top:50px;
overflow:auto;
background:url(http://4k-background.com/highresolution/l_011.jpg)no-repeat center center fixed;
background-size:cover;
height:500px;
}
.position{
padding-left:70px;
}
.image {
width: 120px;
height: 100px;
}
Just replace your CSS with this.
EDIT: Oh, by the way, add the class="image" to both image tags

CSS: How to switch two background images with fading transition?

I want to switch between to background-image attributes on hover, but the default transition is too fast and sharp and I would like to incorporate a fade opacity transition for both of them. I would like it to fade when I hover and also when I stop hovering when it get reset to the original background-image. Any ideas?
#HeaderLogo {
background: url('/logourl.png') no-repeat center;
background-size: contain;
display: block;
width: 800px;
height: 100px;
margin-left: auto;
margin-right: auto;
cursor: pointer;
}
#HeaderLogo:hover {
background: url('/hoverlogourl.png') no-repeat center;
}
You can fade your background-image in various ways for example you can use:
#HeaderLogo {
background: url('/logourl.png') no-repeat center;
background-size: contain;
display: block;
width: 800px;
height: 100px;
margin-left: auto;
margin-right: auto;
cursor: pointer;
-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
}
#HeaderLogo:hover {
background: url('/hoverlogourl.png') no-repeat center;
}
You can use transition effect in HeaderLogo class
-webkit-transition: background-image 0.2s ease-in-out;
transition: background-image 0.2s ease-in-out;
#HeaderLogo {
background: url('/logourl.png') no-repeat center;
background-size: contain;
display: block;
width: 800px;
height: 100px;
margin-left: auto;
margin-right: auto;
cursor: pointer;
-webkit-transition: background-image 0.2s ease-in-out;
transition: background-image 0.2s ease-in-out;
}

How to make div fall beside previous div

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

Transition on position:absolute header and background

I'm trying to apply a hover state to some portfolio navigation. It's a horizontally and vertically centered header on top of an image. The centering works as I need it to (there are reasons for it being as complicated as it is, or believe me, I would do it some other way).
But the hover state is giving me problems. I'm trying to do something like this: http://jsfiddle.net/kmjRu/33/. Which is a transition of the h2 and its background on hover of the image. I can get it almost working by fiddling with opacity or the z-index of the h2, but especially the change of the background color is not working (because there are no elements exactly covering the image, of which I can change the background). Does anyone know how to get the hover state working properly?
This is the code I have and on which I'm trying to get this hover effect to work:
(Also posted here: http://jsfiddle.net/kmjRu/34/)
HTML
<article>
<div class="img-crop">
<h2>Title</h2>
<img src="http://bit.ly/gUKbAE" />
</div>
</article>
CSS
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
article {
overflow: hidden;
}
.img-crop {
display: inline-block;
position: relative;
overflow: hidden;
max-width: 100%;
}
h2 {
margin: 0;
padding: 0;
z-index: 1;
line-height: 0;
position: absolute;
top: 50%;
left: 0;
width: 100%;
text-align: center;
}
h2 {
margin: 0;
padding: 0;
z-index: 1;
line-height: 0;
position: absolute;
display: block;
top: 50%;
left: 0;
width: 100%;
text-align: center;
opacity: 0;
transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
}
h2:hover {
opacity: 1;
}
This could be it!
Basically, you need to make sure following things.
your h2 should be exactly equal to the container behind, only then it will perform a total overlay.
set the default opacity of h2 to be 0. and change/transition it to some mid value say 0.6 upon hover.
now also, you need to make the background-color of the h2 black, or different than the parent container, only then it will appear.
and then give appropriate padding to the h2 element, to make the text appear in the middle.
set h2 like this:
h2 {
margin: 0;
z-index: 1;
padding-top:20%;
line-height: 0;
position: absolute;
top: 0%;
left: 0;
width: 100%;
text-align: center;
vertical-align:middle;
height:100%;
opacity:0;
}
and set your h2:hover like this:
h2:hover
{
padding-top:20%;
color:white;
background-color:Black;
opacity:0.6;
-webkit-transition: opacity 0.25s, background-color 0.25s;
-o-transition: opacity 0.25s, background-color 0.25s;
-moz-transition: opacity 0.25s, background-color 0.25s;
-ms-transition: opacity 0.25s, background-color 0.25s;
-kthtml-transition: opacity 0.25s, background-color 0.25s;
transition: opacity 0.25s, background-color 0.25s;
}
see this fiddle
So, I solved the question by doing it like this:
HTML
<article>
<div class="item">
<h2>Title</h2>
<img src="http://placehold.it/350x150" />
</div>
</article>
CSS
article {
overflow: hidden;
}
h2 {
font-weight: normal;
z-index: 2;
line-height: 0;
position: absolute;
top: 50%;
width: 100%;
text-align: center;
left: 0;
margin: 0;
padding: 0;
color: rgba(255,255,255,0);
-webkit-transition: color 0.2s linear;
-moz-transition: color 0.2s linear;
-o-transition: color 0.2s linear;
transition: color 0.2s linear;
}
.title {
display: inline-block;
position: absolute;
overflow: hidden;
z-index: 1;
width: 100%;
height: 100%;
background: rgba(0,0,0,0);
text-decoration: none;
-webkit-transition: background-color 0.2s linear;
-moz-transition: background-color 0.2s linear;
-o-transition: background-color 0.2s linear;
transition: background-color 0.2s linear;
}
.title:hover {
text-decoration: none;
}
.item {
display: inline-block;
position: relative;
max-width: 100%;
}
.item:hover .title {
background: rgba(0,0,0,0.6);
}
.item:hover h2 {
color: rgba(255,255,255,1);
}
img {
border: 0;
vertical-align: top;
max-width: 100%;
}
See this fiddle. That way it's dynamic (the image is fluid and there are no fixed heights or widths to it) and the headline is automatically centered vertically and horizontally.