This question already has answers here:
How to have multiple CSS transitions on an element?
(9 answers)
CSS transition shorthand with multiple properties?
(7 answers)
Closed 4 years ago.
I'm using Firefox 52.9.0.
I'm trying to add a skip navigation link to a page. Currently, page looks like this:
/* Accessibility */
/* Hide the skip to main content link unless it has focus */
body > a:first-child {
background: inherit;
position: fixed;
left: 0px;
top: -1em;
transition: top 2s ease-out;
}
body > a::first-child:not(:focus) {
}
body > a:first-child:focus {
top: 0px;
transition: top 0.1s ease-in;
}
skip to main content
<main id="lorem">
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum... can't remember the rest, sorry.</p>
<p>This CSS is mostly fine.</p>
</main>
(Click on the page and press Tab to see the effect.)
This looks fine, except the descender and underline are visible. In order to deal with this, I told the browser to change the text colour to transparent when it didn't have focus:
/* Accessibility */
/* Hide the skip to main content link unless it has focus */
body > a:first-child {
background: inherit;
position: fixed;
left: 0px;
top: -1em;
transition: top 2s ease-out;
transition: color 2s ease-out;
}
body > a:first-child:not(:focus) {
color: darkgoldenrod;
}
body > a:first-child:focus {
top: 0px;
transition: top 0.1s ease-in;
transition: color 0.1s linear;
}
skip to main content
<main id="lorem">
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum... can't remember the rest, sorry.</p>
<p>This CSS behaves strangely.</p>
</main>
(transparent is substituted for darkgoldenrod so it's easier to see the effect.)
The color transition works, but for some reason it's stopped the top transition from working!
Why is this, and how can I fix it?
Your second transition declaration erases, not adds to, the first one. This is the cascade at work.
You can't declare separate transitions additively using multiple transition declarations; you will need to group them into a single declaration like so:
body > a:first-child:focus {
top: 0px;
transition: top 0.1s ease-in, color 0.1s linear;
}
Related
This question already has an answer here:
How to show CSS transitions only on hover?
(1 answer)
Closed 1 year ago.
So, I have a hover transition that I would like to ease in on hover, but be instantaneous off hover.
Here's a sample snippet:
.invisible{
opacity: 0;
transition: 1s;
}
div{
cursor: pointer;
}
div:hover .invisible{
opacity: 100%;
}
<div>
<p>Hover Here</p>
<p class="invisible">Now you see me</p>
</div>
What can I change in the CSS to keep the text fading in over the space of 1 second, but instantly vanish when the mouse is moved away?
You can give transition to hover state only, by default it was given to all states.
Once you'll use it for :hover, transition will occur only for mouseover, not for mouseout.
.invisible {
opacity: 0;
}
div {
cursor: pointer;
}
div:hover .invisible {
opacity: 100%;
transition: 1s; /* moved this */
}
<div>
<p>Hover Here</p>
<p class="invisible">Now you see me</p>
</div>
You just need to specify a different transition-duration for the two states, resp. specify the duration not equal zero just for the hover state.
(transition: 0s; for the normal state - because you want it to be 0, when you return into this state, from the hover state. Can be implicit, if no transition-duration is already set for that state.)
.invisible{
opacity: 0;
/* transition: 0s; */
}
div{
cursor: pointer;
}
div:hover .invisible{
opacity: 100%;
transition: 1s;
}
<div>
<p>Hover Here</p>
<p class="invisible">Now you see me</p>
</div>
This question already has answers here:
css transition opacity fade background
(4 answers)
Closed 7 years ago.
I have an image on my home page (or index.html) and I want to be able to hover over the image then a black image fades on with a low opacity.
Example: http://wethepeoplebmx.de/hardgoods - if you go to hover over one of the images (or products), you can see the fade sort of thing I am trying to acomplish. I am fairly new at HTML and CSS, along with scripts and stuff like that. I'm assuming it's something to do with CSS, eg, hover, etc.
Thanks in advance
You can do this with CSS3 animations and :hover.
.wrap {
width: 100px;
height: 100px;
position: relative;
}
.effect {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
background: none;
/* First we need to help some browsers along for this to work.
Just because a vendor prefix is there, doesn't mean it will
work in a browser made by that vendor either, it's just for
future-proofing purposes I guess. */
-o-transition: .5s;
-ms-transition: .5s;
-moz-transition: .5s;
-webkit-transition: .5s;
/* ...and now for the proper property */
transition: .5s;
}
.effect:hover {
background: rgba(0, 0, 0, 0.4);
}
<div class="wrap">
<img src="http://placehold.it/100x100">
<div class="effect"></div>
</div>
I think you want something like this -
.wrap{position:relative;height: 100px;width: 120px;}
.wrap img{width: 100%;;height: 100%;}
.effect{background: rgba(0, 0, 0, .5);;position: absolute;height: 100%;width: 100%;;top:0;display: none;}
.wrap:hover .effect{display: block;opacity:.4}
<div class="wrap">
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcQiWGXo4U6CCvNItlDYFgEQz4d3T-YjLj13nqUZ-crpAr3qMPx-">
<div class="effect">
text
</div>
</div>
I'm using a very fancy webkit filter to make background-images grayscale, and on hover over the images become color.
Here's the filter
filter: none;
-webkit-filter: grayscale(0);
transition: opacity .3s ease-in-out;
-moz-transition: opacity .3s ease-in-out;
-webkit-transition: opacity .3s ease-in-out;
As you can see, there's even a 'transition' property so that the image has a smooth fading transition into full color. The problem that I'm having is that the div I'm applying it to is also affecting the child text positioned inside the div, turning the text into grayscale as well. This is a problem because the text needs to be white, even when not being hovered over.
I've tried negating the filter with another one on the child text but it doesn't seem to work... Check out the fiddle
Fiddle http://jsfiddle.net/yMHm4/1/
This is not a problem of properties inheritance, as you can think.
The way filters work makes that imposible to fix changing attributes in the CSS: The element affected by the filter is rendered, all the children are rendered, and then the result (as an image) has the filter applied.
So the only alternatives left are:
1) Change the HTML, as Lowkase suggested
2) In your case, seems that all you want to make gray is the background image. In this case, you can leave the HTML as is, display the image in a pseudo element, and apply the filter to this pseudo element.
CSS
.cell{
opacity:0.7;
width:420px;
height:420px;
transition: opacity .3s ease-in-out;
-moz-transition: opacity .3s ease-in-out;
-webkit-transition: opacity .3s ease-in-out;
}
.A1 {
position: relative;
}
.A1:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-image:url('http://i.imgur.com/NNKxZ5R.jpg');
filter: url(filters.svg#grayscale); /* Firefox 3.5+ */
filter: gray; /* IE6-9 */
-webkit-filter: blur(15px); /* Google Chrome, Safari 6+ & Opera 15+ */
z-index: -1;
}
#text {
color:#ffffff;
text-align:center;
font:18px sans serif;
text-decoration:none;
}
.cell:hover {
opacity:1.0;
}
.A1:hover:before {
filter: none;
-webkit-filter: grayscale(0);
transition: opacity .3s ease-in-out;
-moz-transition: opacity .3s ease-in-out;
-webkit-transition: opacity .3s ease-in-out;
}
fiddle
I have also changed your filter to blur to make it more clear the the text is not affected by the filter. Since you had also some opacity set, the text still looked grayish just because you were seeing the gray under it.
Added example using brightness filter (for webkit)
demo 2
You had a couple of HTML errors with your br's, they should be br/, not /br.
The following solution takes the text container out of the image div and places it as an absolute positioned element:
http://jsfiddle.net/yMHm4/3/
#text {
position:absolute;
top:10px;
left:25%;
color:#ffffff;
text-align:center;
font:18px sans serif;
text-decoration:none;
}
<div id="container">
<div id="row">
<div class="cell A1"></div>
<div id="text">
<b>SPINDRIFT KIOSK</b>
<br/>
Digital Collage
<br/>
<i>Mikey</i>
</div>
</div>
</div>
You could probably use "not" selectors in your CSS but I am not sure how cross browser friendly they are. This solution is a more plain jane way to do it.
I have the html:
<div class="social-section">
<i></i>
<i></i>
</div>
I'd like to have the icon fade to a different color when moused over, using a CSS3 transition. Unfortunately, I'm not sure how to make this work, if it's possible. My current attempt at the css is:
.social-section * i:before { /* Apply this to the i:before, when the a is hovered */
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-ms-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
transition: all 0.3s ease-in;
}
.social-section a i:before {
color: red;
}
.social-section a:hover i:before {
color: black;
}
In case this is helpful, here's the relevant section of the Glyphicons font css code:
.glyphicons {
display: inline-block;
position: relative;
padding: 0 0 5px 35px;
*display: inline;
*zoom: 1;
}
.glyphicons i:before {
position: absolute;
left: 0;
top: 0;
font: 20px/1em 'Glyphicons';
font-style: normal;
color: red;
}
A pseudo-code, since I'm not sure how it should act based on your quesiton...
put the transition css code you have in the element you want to affect (i.e. not the parent)
#child {
// transitions....
}
then do
#parent:hover #child {
// your changes
}
When the parent element is hovered, make changes to the child. The child's existing transition effects will be used for this, which I think is your goal.
Also, if you're going to be transitioning between icons, you'll need to change the position of the sprite-image, which I assume you're using, not changing the color style.
The answer is that pseudo elements aren't capable of transitions on most versions of most browsers. This issue is so frustrating that Chris Coyier (of css-tricks.com) is keeping a page open on the current status.
As of time of writing, transitions on pseudo elements are supported by:
Firefox 4.0+
Chrome 26+
IE 10+
You can confirm this on your browser.
I have a DIV that's wrapped in an anchor tag; all of the DIV is clickable, even the whitespace that doesn't contain any text (and this is desired, for my purposes).
I have another anchor tag that's absolutely positioned over this DIV with a higher z-index. This anchor tag wraps an image (a "close" icon).
This all works correctly, EXCEPT that I only want the close icon to appear on hover. As currently implemented, the close icon is always visible. I'm not sure if I'm going about this the right way. As a further wrinkle, I need to implement this without using JavaScript, since I'm running on an embedded system and I can't afford to invoke a JavaScript engine.
This only needs to work with WebKit (even more specifically, it only needs to work with Chrome).
Can someone give me a nudge in the right direction?
Here's the CSS I'm using:
.content {
border-top: 1px solid #eff1f2;
border-bottom: 1px solid #c5c5c5;
padding: 8px 11px;
border-left: 1px solid #c5c5c5;
}
div.content:hover {
background-color: #d1d6de;
}
.close {
position: absolute;
right: 100px;
top: 10px;
z-index: 0;
}
Here's my HTML:
<div>
<a href="native://action1/">
<div class="content">
<p>This is my content</p>
</div>
</a>
<a href="native://action2/">
<img class="close" src="images/close.png"/>
</a>
</div>
Here's a jsFiddle that contains my source.
All you need, given your current HTML, is a simple revision of your CSS:
.close {
display: none; /* Added this to hide the element */
/* other CSS */
}
div:hover a .close { /* to make the element visible while hovering the parent div */
display: block;
}
JS Fiddle demo.
With the use of the CSS transition properties, you can also use fade in/fade out:
.close {
opacity: 0; /* to hide the element */
-webkit-transition: opacity 0.5s linear;
-moz-transition: opacity 0.5s linear;
-ms-transition: opacity 0.5s linear;
-o-transition: opacity 0.5s linear;
transition: opacity 0.5s linear;
/* other CSS */
}
div:hover a .close {
opacity: 1; /* to reveal the element */
-webkit-transition: opacity 0.5s linear;
-moz-transition: opacity 0.5s linear;
-ms-transition: opacity 0.5s linear;
-o-transition: opacity 0.5s linear;
transition: opacity 0.5s linear;
}
JS Fiddle demo.
It's also worth noting that, prior to HTML 5, it's invalid to wrap a block-level element inside of an inline-level, the a, element. In HTML 5, though, this seems to be valid (though I've yet to find the W3 documentation to support this).