demo
HTML
<span>text insie span</span> |||| text inside anchor
SASS
span {
transition: all 500ms ease;
}
a {
transition: all 5000ms ease;
&:hover {
color: red;
}
}
When hover, first 5000ms transition is fired on <a> ignoring <span>.
After it finished, fires 500ms transition on <span>
Why it happens? Shouldn't they start simultaneously? Why <a> delays <span>'s transition by its own duration?
Since the span doesn't have a :hover rule of its own, the browsers handles this different.
Chrome simply picks up the anchor's, but in Firefox it actually runs the span's first and then the anchor's override it.
I can't say which one is correct here, as there is both a property inheritance involved and to not be able to animate the same property on an element with to different rules.
If you add a :hover rule to the span, you'll see it work as expected
Note, you need to hover the span or else nothing happens with its transition
Stack snippet
span {
color: pink;
transition: all 500ms ease;
}
span:hover {
color: lime;
}
a {
transition: all 500ms ease;
}
a:hover {
color: red;
}
<span>text inside span</span> |||| text inside anchor
Related
I have a div that has a css animation transition for it's height when you hover over it. When you also hover over it, the background color change from pink to orange. However, I don't want this background color to change until after my height is done transitioning. Is there a way I can do this? I looked into using transition-delay but it seems that it can only be applied to one transition property? Thanks!
div {
margin: 3rem;
height: 10rem;
width: 10rem;
background: pink;
transition: height 0.3s ease;
}
div:hover {
height: 20rem;
background: orange;
}
<div />
You can specify delays for any property you like:
div {
transition: height 0.3s ease, background 0.3s ease 0.3s;
}
(In this case the last 0.3s defines the delay for the background color, see e.g. on MDN)
I'm applying transform:scale to the :hover event for an <img> element nested within a <button> control.
It works in Chrome, but not in Firefox or IE.
Here's the code (below). Is there a way to make it work in Firefox and IE?
I'd like to keep the effect on the hover event for the nested <img> file, but I can put it on the <button> if needed. I'm really just curious if this code can be made to work on FF & IE or if it's a known limitation with those browsers (or non-standard awesomeness allowed by Chrome).
.zoomable {
-webkit-transition: all 500ms;
-moz-transition: all 500ms;
-ms-transition: all 500ms;
-o-transition: all 500ms;
transition: all 500ms;
border: 1px transparent solid;
}
.zoomable:hover {
border: 1px orange solid;
transform: scale(1.2,1.2);
-moz-transform: scale(1.2,1.2);
}
<button>
<img src="bogus.png" class="zoomable" />
</button>
You should set :hover on a button and keep everything like it is. Just as you said. If you use element that doesn't include interaction like div or span you can leave .zoomable:hover and it will work. It is a button issue since it brings it's native interaction and probably collides with child element hover event.
Using CSS transitions on most properties runs as expected, except this issue I am having with colours.
I have set up a demonstration pen here.
When transitions are instructed to change the color property, they all queue after each other instead of happening all at once.
This seems limited to webkit as IE and Firefox work as expected.
#change {
color: green;
transition: color 200ms linear;
}
.changed {
color: red;
}
I think it's because color is inherited property, and you use * selector for transition. You should set transition: color only to element you change color, for example (http://codepen.io/sergdenisov/pen/QbjjjP):
#container {
padding: 0;
transition: color 500ms;
}
#container * {
transition: margin 500ms;
}
My blog simulates a terminal screen, so normal text is green and links are in red with a red background when the mouse is over. Since I use a monospaced font throughout the blog, <code> is styled to have a green background to differentiate from regular text. Likewise, <code> inside <a> has a red background that turns darker when the mouse is over. See this test page for a live version.
Here is the CSS (complete file here) for <a> tags:
a {
color:#CD0000;
text-decoration:none;
transition: background-color .6s;
-webkit-transition: background-color .6s; /* Safari and Chrome */
-moz-transition: background-color .6s; /* Firefox 4 */
-o-transition: background-color .6s; /* Opera */
}
a:hover {
background-color:#440000;
}
And for <code> tags inside <a> tags:
a code {
/* Only apply this to code that is a hyperlink */
color: #161616;
background-color: #CD0000;
border-radius: 5px;
padding: 0 2px 0px 2px;
text-decoration:none;
transition: background-color .6s;
-webkit-transition: background-color .6s; /* Safari and Chrome */
-moz-transition: background-color .6s; /* Firefox 4 */
-o-transition: background-color .6s; /* Opera */
}
a code:hover {
background-color:#440000;
border-radius: 5px;
padding: 0 2px 0px 2px;
}
The problem is that when I mouse over a link such as <a href='#'><code>long code</code></a>, the backgrounds of both the <code> and the <a> tags are transformed. Here are two images that illustrate this. In the first image, I managed to put the pointer of the mouse only over the <a> element. In the second, the mouse is over the <code> element:
Is there a way to style <code> links differently from normal links? Thank you in advance.
I think you're looking for the contains() selector, which is no longer part of the css3 selector spec
To achieve this, you will want to look at either a js framework solution, like has() in jquery or a dynamic css solution, such as less
I have two collections of elements I want to make inter-dependent (binded to each other)
On the one hand I have some text links in a navigation bar, on the other hand I have some elements with references to the same links. These images have animation effects, as described below (the animation occurs when hovering the images).
I want to achieve the following behavior: when hovering over links in the nav. bar, I would like to activate the hovering effects on the images. ¿Is that possible without jQuery?
This is the style of the animated elements
.view-first img {
transition: all 0.2s linear;
}
.view-first .mask {
opacity: 0;
background-color:rgba(116,89,47,0.8);
transition: all 0.4s ease-in-out;
}
.view-first h2 {
transform: translateY(-100px);
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first p {
transform: translateY(100px);
opacity: 0;
transition: all 0.2s linear;
}
.view-first a.info{
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first:hover img {
transform: scale(1.1);
}
.view-first:hover .mask {
opacity: 1;
}
.view-first:hover h2,
.view-first:hover p,
.view-first:hover a.info {
opacity: 1;
transform: translateY(0px);
}
.view-first:hover p {
transition-delay: 0.1s;
}
.view-first:hover a.info {
transition-delay: 0.2s;
}
This is the markup of the navigation elements
<nav><ul>
<li>DSIC</li>
<li>RNA</li>
<li>De Ludo Bellico</li>
</ul></nav>
This is the markup for one of the images with animation effects
<div class="view view-first">
<img src="images/animage.png" />
<div class="mask"/>
<div class="content">
<h2>Name</h2>
<p>Description</p>
Take me there!
</div>
</div>
So, when hovering over elements in the navigation bar , I would like to fire the animation in the associated "view" element
For what I have read, it seems that behaviour can be achieved by using jQuery (or js). But, ¿is it possible to achieve the same effect using pure html and css ? ¿how?
The following picture shows the layout of my page. When hovering in the elements of the navigation bar, in blue, I want to fire an animation in the pictures below.
The strict answer is no, it is not possible to make any element x run the animation for element y when you hover over it. However, you could use pure CSS in the following situations:
1) Your focused element is a parent of .view-first
.y:hover .view-first { ... }
2) Your focused element is adjacent to .view-first
.y:hover + .view-first { ... }
3) Your focused element is a general sibling of .view-first
.y:hover ~ .view-first { ... }
Interestingly, the current proposals for CSS4 include the addition of a "subject selector", which allows you to set the "subject" in your selectors using a !, and thus select upwards in the DOM. (See the current W3C spec - Thanks to Alohci for the link). This would also be useful for this situation, but would still not allow you to select "anything", the elements would have to be related in some way.
Edit
Mr. Alien points out that using the :target pseudo-class could be useful, if you were to allow clicking the element. Lets say you had your HTML as
Start Spin
<div id="spin" class="view-first"></div>
you could then use the target to initiate the spin, by having your CSS as:
.view-first:target { ... }
Though I'm not sure if that helps you too much.
Edit 2019 - The subject selector (!) has been replaced with the :has() selector, but it's still entirely unsupported across browsers (5 years on!)
You can try this:
.view-first { opacity: 0;
/*more properties here*/}
.myDiv:hover ~ .view-first{
-webkit-animation: boxanimation 1.5s;
opacity: 1;
-webkit-transition: all 0s;
-webkit-animation-fill-mode: initial;
/*more properties here*/}
This will work for chrom and safary, for more broser you can set the -moz for firefox, and -o for opera