Animate :hover:after - html

I have the following css rule:
button:hover:after {
content: ' ' attr(title);
}
Basically the button has a fontawesome icon as content and a title attribute. When you hover over the button, it will add a space and then the title to the button's content. See this JSFiddle
Now the question, how would I animate this? I want the new width of the button to be animated so it doesn't appear this static and ugly.

I got a solution, which works but might not be best fashion
button:after {
content:' ' attr(title);
visibility: hidden;
opacity:0;
transition: visibility 0s linear 0.5s, opacity 0.5s linear, font 0.05s linear;
font-size: 0;
}
button:hover:after {
content:' ' attr(title);
visibility: visible;
opacity:1;
transition-delay:0s;
font-size: 13px;
}
See working JSFiddle here
Background
Your approach is analog to using the display property. Therefore credits go to this Transitions on the display: property with my little hack to decrease the font-size to 0 in the initial :after state
Update
Even smoother transition:
button:after {
content: ' ' attr(title);
font-size: 0;
opacity: 0;
transition: opacity 0.2s 0s ease, font-size 0.2s 0.2s ease;
}
button:hover:after {
font-size: inherit;
opacity: 1;
transition: font-size 0.2s 0s ease, opacity 0.2s 0.2s ease;
}
See JSFiddle

It can work like this, but for this solution, you'll have to put fixed width to your button.
button:hover:after {
content: ' ' attr(title);
}
button:hover{
width:70px;
}
button{
width:20px;
overflow:hidden;
white-space:nowrap;
-webkit-transition:0.5s;
-moz-transition:0.5s;
-ms-transition:0.5s;
-o-transition:0.5s;
transition:0.5s;
}
http://jsfiddle.net/j3zw1thh/1/

Related

Smooth transitioning from one content image to another

.tidings {
width: 30%;
float: left;
margin: 0 3%;
}
.tidingsimg:before{
content: url("https://s4.postimg.org/466igrsgt/Tidingsrune.png");
position: relative;
transition: opacity 1s ease;
-webkit-transition: opacity 1s ease;
}
.tidingsimg:after{
content: url("https://s12.postimg.org/83p4b0ubx/Tidingsrune2.png");
position:absolute;
top: 0;margin-top: 10px;
opacity:0;
transition: opacity 1s ease;
-webkit-transition: opacity 1s ease;
}
.tidingsimg:hover:after{
opacity:1;
}
.tidingsimg:hover:before{
opacity:0;
}
<div class="tidings"></div>
I have an image that I am trying to have smoothly transition into another image using content: url. It works in changing the images abruptly, however I cannot figure out how to apply the transition to actually make it smoothly transition from one image to another. Is it possible to do this using content?
Here is a JSFiddle showing what I have going on.
You Should use Before after and set opacity and transition on them
In .tidingsimg:after class we add position:absolute and top: 0;margin-top: 10px; Because without it after style will go far below before style
.tidings {
width: 30%;
float: left;
margin: 0 3%;
}
.tidingsimg:before{
content: url("https://s4.postimg.org/466igrsgt/Tidingsrune.png");
position: relative;
transition: opacity 1s ease;
-webkit-transition: opacity 1s ease;
}
.tidingsimg:after{
content: url("https://s12.postimg.org/83p4b0ubx/Tidingsrune2.png");
position:absolute;
top: 0;margin-top: 10px;
opacity:0;
transition: opacity 1s ease;
-webkit-transition: opacity 1s ease;
}
.tidingsimg:hover:after{
opacity:1;
}
.tidingsimg:hover:before{
opacity:0;
}
<div class="tidings"></div>

:hover targeting not working exactly the way I want it to

if you hover over a project some text will appear, but if you mouse over the text it kills the hover style because that's not what triggers the hover.
p.description {
position:absolute;
top:50%;
left:50%;
margin: 40px 0 0 -125px; /*offset 50px from center*/
transform: translateY(-50%); /*vertically centered*/
width:250px;
height:80px;
z-index:1000;
color: #ffffff;
opacity: 0;
}
.holder:hover p.description {
margin-top: 0; /*makes me slide up*/
opacity:1;
visibility:visible;
-moz-transition: all .2s ease-in;
-o-transition: all .2s ease-in;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
}
p.description span {
font-family: 'aileronbold';
font-size: 110%;
}
This is my css for trying to accomplish this. I am not sure how to re-target to achieve this. Everything works as I want it minus when you mouse over the text.
You can check this at: http://darrenbachan.com/
Change the selector from .holder a:hover to .holder:hover a. You were seeing this flicker issue because the transition would end when you hover over the p description element that would transition in. By moving the :hover pseudo class to the parent element, the transition will remain intact even when you aren't hovering over the a element:
.holder:hover a {
opacity: 0;
-moz-transition: all .2s ease-in;
-o-transition: all .2s ease-in;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
}
In order for the anchor element to be positioned over the p description element, you could absolutely position it relative to .holder (since it's relatively positioned).
.holder a {
position: absolute;
z-index: 10;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
Then remove z-index: 1000 from p.description.
It is a z-index issue:
z-index: 9999; /* Or anything more than 1000 */
Give the above z-index to .grow:
.grow {
z-index: 9999;
}
And just because you are using transition, that jerk happens. Guess there's no way.
Change
.holder:hover p.description
to
.holder:hover p.description, p.description:hover
A little bit of a hack, but it'll work.
P.S. Love the site! Very pretty.
Change
.holder a:hover {
opacity:0;
}
To
.holder:hover a {
opacity:0;
}
The key point is to prefix all hover style's selector with .holder:hover.

Z-Index Flickering in Chrome on Hover

I'm trying to create a hover button using the following code and it works relatively okay in all browsers except Chrome:
<div id="blur" class="et_pb_module et-waypoint et_pb_image et_pb_animation_off et_pb_image_0 et_always_center_on_mobile et-animated">
<a href="http://vina.typesetdesign.com/wines/reserva/reserva-sauvignon-blanc/">
<img alt="" src="http://vina.typesetdesign.com/wp-content/uploads/2015/11/2015_11_17Vina_Echeverria_Reserva_Sauvignon_Blanc_V1.png">
</a>
</div>
#blur img {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
#blur img:hover {
opacity: .4;
z-index: 1;
}
#blur a:hover:before {
background-color: #6d8e3b;
color: #fff;
content: "Learn More";
display: block;
font-size: 12px;
margin-left: auto;
margin-right: auto;
opacity: .9 !important;
padding: 18px;
position: relative;
top: 20em;
width: 70px;
z-index: 2;
margin-top: -3em;
}
For some reason, Chrome won't let you hover over the button without it glitching out and flickering super badly. Is there an easy way around this without having to add in a separate button?
Live Page: http://vina.typesetdesign.com/wines/varietal/
Fiddle: https://jsfiddle.net/35txpy8v/
It's flickering because the element moves while you hover over it. The reason the element is moving is because of the pseudo element's positioning. To work around this, I'd suggest absolutely positioning the pseudo element relative to the parent element. In doing so, the pseudo element's position won't have any effect on the parent element.
Updated Example
#blur img {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
position: relative;
}
#blur img:hover {
opacity: .4;
z-index: 1;
}
#blur a:hover:before {
content: "Learn More";
background-color: #6d8e3b;
position: absolute;
top: 50%;
margin-top: -50px;
color: #fff;
font-size: 12px;
opacity: .9;
padding: 18px;
width: 70px;
z-index: 2;
}

CSS - tooltip only with css and html doesn't work

I am trying to do simple tooltip only with css3 and html, but the transition doesn't work. What am I doing wrong?
HTML
<p>
This has tooltip
</p>
<div class="tooltip">Tooltip content</div>
CSS
p {
width: 200px;
background-color: aqua;
padding: 10px;
margin-top: 50px;
}
div.tooltip {
position: absolute;
width: auto;
padding: 10px;
background-color: rgba(0,0,0, 0.5);
top: 0px;
display: none;
opacity: 0.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
p:hover + div.tooltip {
display: block;
opacity: 1.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
http://jsfiddle.net/MCDg4/
Update / Alternate solution
For a modern browser CSS3 solution you could use pseudo elements..
<span data-tooltip="I am the tooltip">This has a tooltip</span>
and
[data-tooltip]{
position:relative;
}
[data-tooltip]:before{
content:attr(data-tooltip);
position:absolute;
bottom:110%;
padding:10px;
background:#666;
opacity:0;
color:white;
font-size:smaller;
-webkit-transition:opacity 1s ease;
-o-transition:opacity 1s ease;
transition:opacity 1s ease;
pointer-events:none;
}
[data-tooltip]:hover:before{
opacity:1;
}
Demo at http://jsfiddle.net/BJ2tr/
(this could be done without pseudo-elements by nesting the tooltip inside the elements that it refers to, and adjusting the css accordingly)
Unfortunately when you change display from none to something else, you cannot have transitions.
Instead of display:none you could just offset it outside of the window (with top:-9999px) and bring it to position when showing it.
div.tooltip {
position: absolute;
width: auto;
padding: 10px;
background-color: rgba(0,0,0, 0.5);
top: -999px; /*CHANGED THIS AND REMOVED display:none*/
display: none;
opacity: 0.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
p:hover + div.tooltip {
opacity: 1.0;
top: 0px; /*ADDED THIS AND REMOVED display:block*/
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
This will, however, not fade out (only in) since it moves it away on mouseout (so it actually does fade but you do not see it because it is outside the viewport)..
Explanation
You put transition only on opacity, while when changing to display:block; it is shown as a block with opacity:1; by default.
Solution
(JSFiddle)
Delete the display:none; and display:block on your tooltip element.

CSS Transitions Not Working?

What I'm trying to do here is get a transition when this div is hovered over.
Everything works fine, its just the transition that does nothing. I've tried using the transition properties with transition: all, transition: opacity and transition: background. But none of them work.
It's the display property that's doing it. Because when I take that out, it works. How else can I get around this? Because I obviously want to keep the display property, as it works on all browsers, young and old.
Here's what I've got at the moment:
.matrix-overlay {
position: absolute;
width: 100%;
height: 100%;
background: rgb(0,0,0); /* fallback */
background: rgba(0,0,0,0);
color: #fff;
display: none;
-webkit-transition: background 2s;
-o-transition: background 2s;
-moz-transition: background 2s;
transition: background 2s;
}
a:hover .matrix-overlay {
display: block;
background: rgba(0,0,0,0.5);
}
I don't mind if I'm using opacity or background or whatever to control the fading, I just don't know what else to do.
Looks like the display property isn't supported with CSS transitions (also see this SO question).
With that in mind, you have several options. You could initially set the width/height to 0 in your pre-transition, or offset the element off the page (something like margin-left: -9999px;), or set the opacity to 0.
In your case, I would probably use this:
.matrix-overlay {
position: absolute;
width: 100%;
height: 100%;
background: rgb(0,0,0); /* fallback */
background: rgba(0,0,0,0);
color: #fff;
display: block;
margin-left: -9999px; /* hide element off the page */
-webkit-transition: background 2s;
-o-transition: background 2s;
-moz-transition: background 2s;
transition: background 2s;
}
a:hover .matrix-overlay {
margin-left: 0; /* reset element position */
background: rgba(0,0,0,0.5);
}
Here's what I ended up doing:
.matrix-overlay {
position: absolute;
width: 100%;
height: 100%;
background: rgb(0,0,0); /* fallback */
background: rgba(0,0,0,0.7);
color: #fff;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
-webkit-transition: opacity 0.2s ease 0s;
-o-transition: opacity 0.2s ease 0s;
-moz-transition: opacity 0.2s ease 0s;
transition: opacity 0.2s ease 0s;
}
a:hover .matrix-overlay {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
opacity: 1;
-webkit-transition: opacity 0.15s ease 0s;
-o-transition: opacity 0.15s ease 0s;
-moz-transition: opacity 0.15s ease 0s;
transition: opacity 0.15s ease 0s;
}
you could use clip instead of display, as the element is absolutely positioned
Working Example
e.g.
.matrix-overlay {
...other properties, not display ...
clip: rect(1px 1px 1px 1px); /* IE7 */
clip: rect(1px,1px,1px,1px);
}
a:hover .matrix-overlay {
..other properties, not display ...
clip: rect(auto); /* IE7 */
clip: auto;
}
I put in the quirky IE7 code clip code for information, although IE doesn't do transitions anyway and you could feed it the display codes if you wanted to, but this way keeps them the same ;)
You can try the following:
.matrix-overlay {
position: absolute;
width: 100%;
height: 100%;
background: rgb(0,0,0); /* fallback */
background: rgba(0,0,0,0.7);
color: #fff;
opacity: 0;
pointer-events:none;
transition: opacity 0.2s ease 0s;
}
a:hover .matrix-overlay {
pointer-events:auto;
opacity: 1;
transition: opacity 0.15s ease 0s;
}
Using pointer-events:none and opacity:0 together will have nearly the same effect as display:none, but now the transition should work fine.