Using `*` selector for transition results in asynchronous effect - css

In writing some html, I was too lazy to decide a more specific CSS selector like this:
#z {
transition-duration:0s;
transition-delay:1s;
}
So I had chosen the * selector instead.
I was surprised with the result of this code. Try it:
* {
transition-duration: 0s;
transition-delay: .5s;
}
#z {
color: red;
background-color: white;
}
#z:hover {
color: white;
background-color: red;
}
<html>
<body>
<div id="z">
<span>mouse hover here!</span>
</div>
</body>
</html>
In my browser, transitions take effect in two steps: background-color changes after a 1s delay, followed by the change of color after another 1s delay.
If I switch back from the * selector to a more specific selector, transitions will be simultaneous. Is it browser specific? What is the relevant rule for this result?
EDIT:
1(question rephrased) Is there any specification made by CSS that every browser should follow to implement in this way(as described above), or this is up to browser or even hardware performance?
2\ I've tried it on Chrome, and a browser on an android mobile phone (a touch for a hover). Both produce the same result.

Chrome and Firefox seem to differ in how transition delay impacts inheritance.
The following CSS fixed your issue for me in chromium:
#z * {
transition-delay: 0s;
}
It sets the transition delay back to 0 for all descendants of #z.
* {
transition-duration: 0;
transition-delay: 1s;
}
#z {
color: red;
background-color: white;
}
#z:hover {
color: white;
background-color: red;
}
#z * {
transition-delay: 0s;
}
<div id="z">
<span>mouse hover here!</span>
</div>
Explanation:
The * Universal Selector selects elements of any type, so it's applying a transition delay to both div#z and span.
Chrome seems to interpret this as you wanting a delay for #z to change to white, and then a delay for span to inherit
Hover #z -- 1s --> white text on #z -- 1s --> span inherits white
Firefox seems to interpret this as you wanting a delay for #z to change to white and be inherited
Hover #z -- 1s --> white text on #z --> span inherits white immediately
Here is a crazy example with many nested elements:
* {
background-color: inherit;
padding: .5rem;
transition-duration: 0;
transition-delay: 1s;
}
#a {
background-color: white;
}
#a:hover {
background-color: red;
}
/* This rule seems to stop the propagation
#c {
transition-delay: 3s;
}
*/
<div id="a">
a
<div id="b">
b
<div id="c">
c
<div id="d">
d
<div id="e">
e
</div>
</div>
</div>
</div>
</div>

Related

Pointer-events animation not working on Safari

Is there any way to make the next code in Safari? Safari doesn't detect the a tag after hover.
.wrap {
width: 100px;
background-color: grey;
height: 100px;
}
.wrap:hover a {
pointer-events: none;
animation: pointerEvent 0s linear forwards .5s;
}
#keyframes pointerEvent {
100% {
pointer-events: auto;
}
}
<div class="wrap">
Demo
</div>
I need to delay the pointer-event because the a tag is inside a div which has a transformation animation on hover. If I do not delay the event, I can click over the a tag before the transformation ends.
The specific problem is in the footer here
I could not solve it only with CSS, I had to give up and add Javascript code
I had the same problem.
My Javascript solution:
4500 = animation-duration + animation-delay = 4.5 secondsYOURCLASS = Classname of the animation-container[0] = first occurrence of YOURCLASS
<script>
document.getElementsByClassName('YOURCLASS')[0].style.pointerEvents='none';
setTimeout(function(){ document.getElementsByClassName('YOURCLASS')[0].style.pointerEvents='YOURCLASS';}, 4500);
</script>

child selector doesn't work with transition

I'm having a problem similar to the following:
<div class="mydiv">
<p>hi</p>
<h4>hello</h4>
</div>
it works when I apply the following css to the above html. The color is getting red.
.mydiv:hover > p{
color:red
}
but it doesn't work when I apply the following css. What is the problem:
.mydiv{
transition: all 1s;
}
.mydiv:hover > p{
transform:rotate(90deg);
}
You're applying the transition: all 1s to the div, not the p element you're applying transform on - You can fix this by targeting .myDiv > p rather than .myDiv
If you're trying to rotate the text inline, you'll need to apply a width to the p tag though, and changing the :hover to also be affecting the p tag
.mydiv > p {
width: 1em;
transition: all 1s;
}
.mydiv > p:hover {
transform: rotate(90deg);
}
<div class="mydiv">
<p>hi</p>
<h4>hello</h4>
</div>

CSS3 fade in without fade out - one way transition

I want to animate my html only with css. A list should fade in, if I add a class ti the element but should immediately disappear, if I remove the class.
I tried several things with transitions in css3. But i seems that all transitions are for both, mount and unmount of an element.
The magic trick is to remove the transition in the basic class an append it in the show class.
$("button").on("click", function(){
$("#container").toggleClass("show")
})
#container {
color: white;
background: #357700;
opacity: 0;
overflow: hidden;
transition: none;
}
#container.show {
opacity: 1;
transition: all 1s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Show/Hide</button>
<div id="container">
<p>Hello World</p>
</div>

Why only chrome (and maybe safari) works good with transition (height,width)?

I have a textarea, which stretches (makes height bigger) smoothly:
<style type="text/css">
textarea {
height:20px;
width:170px;
transition-property: all 0.2s linear; /* PS: I don't want to write all prefixes in this question */
}
textarea:focus {
height:30px;
}
</style>
<div style="overflow:hidden;"><!--And some good styles-->
<textarea style="resize:none;padding:10px;"></textarea>
</div>
So, in chrome <div> stretches smoothly (and <textarea> too, what I want), but in opera and firefox <textarea> stretches smoothly, but <div> doesn't.
I tried to add transition to <div>, but without result..
Is there a solution of this? (PS: I have some ideas to solve it with javascript: just add class to <div> onfocus, but can I solve it without js?)
So, I did it: I just add class "active" to <div> on focus of textarea, and on blur: remove class "active" from <div>. All transformations doing by this class, like
div {
height: 20px;
transition: all 0.2s linear;
}
div textarea {
height: 10px;
transition: all 0.2s linear;
}
div.active textarea {
height:30px;
}
div.active {
height:40px
}
It works very well.

Why do text-decoration changes not appear in my css animation?

I want to emulate a console UI in HTML and I need to have a underscore blinking under text.
My approach is to put the class to underblink which has an animation. The colors cycle, the text hides and unhides, but the underline never appears. Why ?
CSS:
#-webkit-keyframes underblink {
0% { text-decoration: none;opacity: 0:color :orange }
50% { text-decoration: none;opacity: 0;color:green }
50.01% { text-decoration: underline;opacity: 1 }
100% { text-decoration: underline;opacity: 1 }
}
.underblink {
-webkit-animation: underblink 0.7s infinite linear alternate;
-webkit-font-smoothing: antialiased;
display:inline-block;
}
HTML:
<div id='always_sort_recursively' class='underblink'>x</div>
... but the underline never appears. Why ?
Because text-decoration is not in the list of animatable css properties.

Resources