I put small images into a large image and use background-position to set the position of the small image in the large one.
When #nav_left_home is onhover, the background image position is changed from 0 32px to be 0 0.
#nav_left_home {
background-position: 0 32px;
background-image: url('../img/nav_left.png');
transition: background-image 0.5s ease-in-out;
}
#nav_left_home:hover {
background-position: 0 0;
}
With the above code, the red house would move up when onhover and the white house will appear under the red house and move up until replace the position.
But I only want to change the color of the image (no moving in position) as in the way color changes with transition.
The only way I know to achieve this is to slice your image as a "mask" and use CSS to transition between different background colors. By mask, I mean the color portion of your icon would be left transparent to form a kind of cutout that lays on top of a solid background color.
You need to show both images at the same time, and fade between the 2.
To get this, you need to set the alternate image in a pseudo element, initially transparent:
#nav_left_home {
background-position: 0 32px;
background-image: url('../img/nav_left.png');
transition: background-image 0.5s ease-in-out;
}
#nav_left_home:after {
content: "";
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
background-position: 0 0;
background-image: url('../img/nav_left.png');
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
#nav_left_home:hover:after {
opacity: 1;
}
Related
I cannot figure out why this breaks it. I have an a element which uses CSS transitions to fade into a gradient background on hover. For whatever reason whenever I set the text color on hover to white the transition breaks?
.social-item {
margin-left: 0.25vw;
padding: 0.1vw;
transition: 0.2s;
color: white;
}
.social-item:hover {
background: linear-gradient(to left, #8E2DE2, #DC0486);
color: white;
}
<i class="fab fa-keybase"></i> Keybase
I'm also using Bulma and Font Awesome.
You can't simply make transitions with background gradients.
Animatable CSS Properties
Use pseudo-element and do an opacity transform.
.social-item {
position: relative;
color: white;
z-index: 1;
}
.social-item::before {
position: absolute;
content: "";
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: linear-gradient(to left, #8e2de2, #dc0486);
z-index: -1;
transition: opacity 0.5s linear;
opacity: 0;
}
.social-item:hover::before {
opacity: 1;
}
<i class="fab fa-keybase"></i> Keybase
A nice article about this.
Thank you!
What I figured your problem to be is that you're trying to do gradient transition. It is not supported. But if you want to simulate it, you can use the opacity property in css. Add opacity: 0 to the main element (.social-item) and opacity: 1 to the hover state (.social-events:hover). Hence the transition: 0.2 will apply on the opacity, as it is supported, thus simulating the desired outcome.
Thus the final css, shall be.
.social-item {
margin-left: 0.25vw;
padding: 0.1vw;
transition: 0.2s;
color: white;
opacity:0;
}
.social-item:hover {
background: linear-gradient(to left, #8E2DE2, #DC0486);
color: white;
opacity: 1;
}
If you actually want to have the thing display normally, and not just on hover, then opacity: 0 wont work for you. You have to use the pseudo-selector :after to add a dummy element to the main class and work all the transitions and background gradient stuff on that. Here is a codepen example.
I have a problem, I need to add a logo to the image. The logo should show up only on hover. Currently, I have this class that is reacting by darkening on hovering:
.et_pb_video_overlay_hover {
position: absolute;
z-index: 100;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0);
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
}
But when I add there content:url(...) it will show up in the class straight away.
I tried to do
.et_pb_video_overlay :hover{
content: url(https://www.aatevr.com/wp-content/uploads/2019/11/te-Aate-VR-healthcare-Virtual-Reality-e1574673050893.png);
}
But then it doesn't inherit the fading in and out beside the size is all over the image and I would need it to be smaller and in the center.
Is there any way, that I can move just around the content property to make it easy in and out and scale it down without messing up the previous property?
You can move it on :before
like this:
.content:hover:before {
content: "";
background-image: url(https://www.aatevr.com/wp-content/uploads/2019/11/te-Aate-VR-healthcare-Virtual-Reality-e1574673050893.png);
background-size: 100% auto;
background-repeat: no-repeat;
background-position: center;
width: 100px;
height: 100px;
}
Enjoy!
https://codesandbox.io/s/hover-logo-image-show-jtrh4
Set content empty by default in this class .et_pb_video_overlay
.et_pb_video_overlay{
content: '';
}
and then on hover
.et_pb_video_overlay:hover{
content: url(https://www.aatevr.com/wp-content/uploads/2019/11/te-Aate-VR-healthcare-Virtual-Reality-e1574673050893.png);
}
It will work and also you both classes are different .et_pb_video_overlayand .et_pb_video_overlay_hover
I have a button with a ::before pseudo element as a background, to achieve an animated hover effect, and above this button there's a carousel with adaptive height.
My problem is that when the user changes the slide to another with a different height, the button realocation shows some problems, and the worst is that I can't reproduce it on Codepen (I tried here but the glitch is not happening), so I captured the glitch and posted on YouTube, you can see the video clicking here.
By the way, this is the relevant CSS I have in the button:
.btn-block{
position: relative;
transition: .15s ease-out;
transition-property: color;
}
.btn-block::before{
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -1;
background-clip: content-box;
transition: .15s ease-out;
transition-property: background, padding, border-radius;
}
.btn-block:hover::before{
padding: 8px 10px;
}
Is there something I can do about this glitch, or is there another way to achieve the hover effect I want?
I'm not great at making websites but am trying to make my own. Basically i split my page up in two, the left side being a menu bar and the right side containing content. To get a 'cool' blur effect over my menu bar i overlay it with a coloured image, where as the user hovers over it, the opacity changes (with a transition).
It is working as intended except when you click on a link and a new page loads, it doesn't register the hover until you move the mouse, this means the opacity of the image is full until you move even a tiny bit, then it jumps to 0.
Ideally when a new page opens and your mouse is already in the left region, the opacity of the overlaying image would already be 0.
#left {
text-indent: 1cm;
width: 23%;
height: 100%;
position: fixed;
background: rgba(51, 51, 51, 1);
}
#right {
padding-top: 2cm;
width: 77%;
height: auto;
position: absolute;
right: 0;
background: white;
}
#img {
position: absolute;
opacity: 0.6;
width: 100%;
height: 100%;
pointer-events: none;
-webkit-transition: opacity .25s ease-out;
-moz-transition: opacity .25s ease-out;
-o-transition: opacity .25s ease-out;
transition: opacity .25s ease-out;
color: #000;
left: 0;
}
#left:hover>#img {
opacity: 0;
}
I hope i have given enough information, thanks in advance
Bas
How do you 'load' the page? is it ajax.load or? because if so, that language is already in use and therefor better to make a hover handler function in there because there is no way your CSS file is gonna notice on load wether the mouse is on your picture already or not untill you`ve moved it
Sorry i cant put comments down therefor i wrote here.
Update I implemented the CSS Reset and to no avail. The answer by Kejko also did not help and instead made it worse. (Chrome now displays it incorrect with the change in styles)
This may be the problem since I know actual tables can not be positioned relative?
.chatIcons {
display: table;
}
End Update
I was about to have my site go live after I tested how each page looked on the major browsers and ran into a problem. The problem seems to be involved with the hover effect of the icons.
In chrome the icon section appears exactly how I want it to.
In FireFox it appears the same but once one it is hovered it only effects the third icon and the .iconInfo's overlay from staying relative to the parent, instead it is doing 100% width and height of the main parent container.
In IE 10-11 it keeps everything correct but once it is hovered the "overlay" is not 100% height anymore and the height actually varies.
Here is the css pertaining to the hover:
.iconInfo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.2);
text-align: center;
opacity: 0;
transition: opacity 0.6s ease;
-webkit-transition: opacity 0.6s ease;
-moz-transition: opacity 0.6s ease;
}
.icon:hover .iconInfo {
opacity: 1;
}
I have included a fiddle to help, Demo
Try this:
.icon {
border-radius: 5px;
display: inline-block;
padding: 15px 0;
position: relative;
vertical-align: middle;
width: 32.99%;
}
That should fix your problem.