CSS3 transition - css

I have this page here (work in progress) http://kimwilddesigns.com/index_new.htm
In this section, I want to be able to hover on the li, have the background image fade out and the h2 to fade in. Is this possible with transitions? I might not be setting it up correctly but I wanted to see if this kind of effect is even possible.
<div id="categories-wrapper">
<ul>
<li class="fine-art"><img src="pics/hp_icon_fine-art.jpg" alt="fine art" width="290" height="240" border="0">
<h2>fine art work</h2>
</li>
<li class="gd">graphic design work</li>
<li class="students">my students' work</li>
</ul>
</div>

Yes, this works nicely with CSS transitions, something like that:
#categories-wrapper li a {
position:relative;
display: block
}
#categories-wrapper li h2 {
position: absolute;
left: 20px;
top: 20px;
opacity: 0;
}
#categories-wrapper li h2,
#categories-wrapper li img {
-webkit-transition: opacity .3s ease-in-out;
-moz-transition: opacity .3s ease-in-out;
-o-transition: opacity .3s ease-in-out;
transition: opacity .3s ease-in-out;
}
#categories-wrapper li:hover h2 {
opacity: 1
}
#categories-wrapper li:hover img {
opacity: 0
}
See the Fiddle for this, slightly changed your markup by putting the h2 inside of the a tag.

Related

css content property transition in animation keyframe [duplicate]

Please view this code jsfiddle:
http://jsfiddle.net/rflfn/6wCp6/
<div id="menu">
<ul>
<li>Link #1</li>
<li>Link #2</li>
<li>Link #3</li>
<li>Link #4</li>
</ul>
</div>
CSS:
*{
margin: 0;
padding: 0;
text-decoration: none;
font-family: arial;
font-size: 16px;
}
a{
color: #000000;
}
a:hover{
color: #860000;
}
#menu{
margin: 15px auto;
padding: 20px;
width: 300px;
background: #DDDDDD;
border-radius: 5px;
box-shadow: 0 0 5px #000000;
}
#menu ul{
list-style: none;
}
#menu li:before{
margin-right: 10px;
content: url("http://st.deviantart.net/emoticons/s/smile.gif");
transition: all 0.5s ease 0s;
/* transition: content 0.5s ease 0s; */
}
#menu li:hover:before{
content: url("http://st.deviantart.net/emoticons/r/razz.gif");
}
I have one image on tag 'li' and other image on 'li:hover', is possible make transition with fade only using css?
You can do this by using both pseudo elements :before/after and using the CSS3 transition to animate the opacity of both on hover. This will create a fade transition between both images.
DEMO
CSS :
*{
margin: 0;
padding: 0;
text-decoration: none;
font-family: arial;
font-size: 16px;
}
a{
color: #000000;
}
a:hover{
color: #860000;
}
#menu{
margin: 15px auto;
padding: 20px;
width: 300px;
background: #DDDDDD;
border-radius: 5px;
box-shadow: 0 0 5px #000000;
}
#menu ul{
list-style: none;
}
#menu ul li{
position:relative;
}
#menu li:before{
margin-right: 10px;
content: url("http://st.deviantart.net/emoticons/s/smile.gif");
transition: opacity 0.5s ease;
-webkit-transition: opacity 0.5s ease;
}
#menu li:after{
content: url("http://st.deviantart.net/emoticons/r/razz.gif");
position:absolute;
left:0;
opacity:0;
transition: opacity 0.5s ease;
-webkit-transition: opacity 0.5s ease;
}
#menu li:hover:after{
opacity:1;
}
#menu li:hover:before{
opacity:0;
}
EDIT :
Even better, you can position both images one on top of the other and with z-index and css transition animate the opacity of ony one image :
DEMO
Your case in particular
Not sure why're you trying to put images in content,
you could simply add that image as a background-image to the :before,
set it size & display: inline-block; and you would just animate the background-image like so: http://jsfiddle.net/7f695m1q/ , since background-image transition is supported :)
TL;DR: Can content CSS property be animated? No.
MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
OUTDATED w3.org official document: https://www.w3.org/TR/2017/WD-css-transitions-1-20171130/#animatable-css
This may however change in future because this list is missing in current official sources:
missing in working draft https://www.w3.org/TR/css-transitions-1/
missing in editor's draft https://drafts.csswg.org/css-transitions/
So in theory there is a possibility this list will be updated and changes made in future browser versions, but currently it doesn't work.
Is content affected by other animations? Yes.
Content not being animatable in itself doesn't mean it's not affected by other animations like opacity, visibility etc. It can be leveraged in at least 2 simple ways:
a) answer by #web-tiki provides a smooth&always visible fade effect, however, you have to sacrifce both :after and :before to it
b) if fadeOut => fadeIn is an option for you you can levarage CSS animations & #keyframes
#keyframes changeContent {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
content: "See? I've changed seemlessly!";
}
}
div:before{
content: "HOVER OVER ME!";
background: green;
transition: all 1s linear;
animation-direction: reverse;
}
div:hover:before{
animation-fill-mode: forwards;
animation: changeContent 3s linear forwards;
background: orange;
}
<div />
Important here is to put the "forward" - it's an animation fill mode that basically says "stop the animation at it's end", otherwise it'd jump back.
There is also one drawback - it's not easily animatable on hover-out - if I find some reasonable way I will edit this answer or please comment if you know.
I think #web-tiki 's answer suits your needs and it's simpler. But just to show another possible solution:
You can separate the icons in two elements, each with its own content. Then, apply the transition on the li:hover event, setting the element's opacity inverted. Like this example:
FIDDLE: http://jsfiddle.net/2J7b9/1/
<ul>
<li>
<div class="img1"></div>
<div class="img2"></div>
test
</li>
</ul>
CSS:
li {
position: relative;
padding-left: 30px;
}
li .img1, li .img2 {
position: absolute;
top: 0;
left: 0;
}
li .img1 {
opacity: 1;
transition: all .25s ease-in-out;
}
li .img2 {
opacity: 0;
transition: all .25s ease-in-out;
}
li .img1:before {
content: url("http://st.deviantart.net/emoticons/s/smile.gif");;
}
li .img2:before {
content: url("http://st.deviantart.net/emoticons/r/razz.gif");
}
li:hover .img1 {
opacity: 0;
}
li:hover .img2 {
opacity: 1;
}

Is possible use fade transition on tag 'content' only with css?

Please view this code jsfiddle:
http://jsfiddle.net/rflfn/6wCp6/
<div id="menu">
<ul>
<li>Link #1</li>
<li>Link #2</li>
<li>Link #3</li>
<li>Link #4</li>
</ul>
</div>
CSS:
*{
margin: 0;
padding: 0;
text-decoration: none;
font-family: arial;
font-size: 16px;
}
a{
color: #000000;
}
a:hover{
color: #860000;
}
#menu{
margin: 15px auto;
padding: 20px;
width: 300px;
background: #DDDDDD;
border-radius: 5px;
box-shadow: 0 0 5px #000000;
}
#menu ul{
list-style: none;
}
#menu li:before{
margin-right: 10px;
content: url("http://st.deviantart.net/emoticons/s/smile.gif");
transition: all 0.5s ease 0s;
/* transition: content 0.5s ease 0s; */
}
#menu li:hover:before{
content: url("http://st.deviantart.net/emoticons/r/razz.gif");
}
I have one image on tag 'li' and other image on 'li:hover', is possible make transition with fade only using css?
You can do this by using both pseudo elements :before/after and using the CSS3 transition to animate the opacity of both on hover. This will create a fade transition between both images.
DEMO
CSS :
*{
margin: 0;
padding: 0;
text-decoration: none;
font-family: arial;
font-size: 16px;
}
a{
color: #000000;
}
a:hover{
color: #860000;
}
#menu{
margin: 15px auto;
padding: 20px;
width: 300px;
background: #DDDDDD;
border-radius: 5px;
box-shadow: 0 0 5px #000000;
}
#menu ul{
list-style: none;
}
#menu ul li{
position:relative;
}
#menu li:before{
margin-right: 10px;
content: url("http://st.deviantart.net/emoticons/s/smile.gif");
transition: opacity 0.5s ease;
-webkit-transition: opacity 0.5s ease;
}
#menu li:after{
content: url("http://st.deviantart.net/emoticons/r/razz.gif");
position:absolute;
left:0;
opacity:0;
transition: opacity 0.5s ease;
-webkit-transition: opacity 0.5s ease;
}
#menu li:hover:after{
opacity:1;
}
#menu li:hover:before{
opacity:0;
}
EDIT :
Even better, you can position both images one on top of the other and with z-index and css transition animate the opacity of ony one image :
DEMO
Your case in particular
Not sure why're you trying to put images in content,
you could simply add that image as a background-image to the :before,
set it size & display: inline-block; and you would just animate the background-image like so: http://jsfiddle.net/7f695m1q/ , since background-image transition is supported :)
TL;DR: Can content CSS property be animated? No.
MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
OUTDATED w3.org official document: https://www.w3.org/TR/2017/WD-css-transitions-1-20171130/#animatable-css
This may however change in future because this list is missing in current official sources:
missing in working draft https://www.w3.org/TR/css-transitions-1/
missing in editor's draft https://drafts.csswg.org/css-transitions/
So in theory there is a possibility this list will be updated and changes made in future browser versions, but currently it doesn't work.
Is content affected by other animations? Yes.
Content not being animatable in itself doesn't mean it's not affected by other animations like opacity, visibility etc. It can be leveraged in at least 2 simple ways:
a) answer by #web-tiki provides a smooth&always visible fade effect, however, you have to sacrifce both :after and :before to it
b) if fadeOut => fadeIn is an option for you you can levarage CSS animations & #keyframes
#keyframes changeContent {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
content: "See? I've changed seemlessly!";
}
}
div:before{
content: "HOVER OVER ME!";
background: green;
transition: all 1s linear;
animation-direction: reverse;
}
div:hover:before{
animation-fill-mode: forwards;
animation: changeContent 3s linear forwards;
background: orange;
}
<div />
Important here is to put the "forward" - it's an animation fill mode that basically says "stop the animation at it's end", otherwise it'd jump back.
There is also one drawback - it's not easily animatable on hover-out - if I find some reasonable way I will edit this answer or please comment if you know.
I think #web-tiki 's answer suits your needs and it's simpler. But just to show another possible solution:
You can separate the icons in two elements, each with its own content. Then, apply the transition on the li:hover event, setting the element's opacity inverted. Like this example:
FIDDLE: http://jsfiddle.net/2J7b9/1/
<ul>
<li>
<div class="img1"></div>
<div class="img2"></div>
test
</li>
</ul>
CSS:
li {
position: relative;
padding-left: 30px;
}
li .img1, li .img2 {
position: absolute;
top: 0;
left: 0;
}
li .img1 {
opacity: 1;
transition: all .25s ease-in-out;
}
li .img2 {
opacity: 0;
transition: all .25s ease-in-out;
}
li .img1:before {
content: url("http://st.deviantart.net/emoticons/s/smile.gif");;
}
li .img2:before {
content: url("http://st.deviantart.net/emoticons/r/razz.gif");
}
li:hover .img1 {
opacity: 0;
}
li:hover .img2 {
opacity: 1;
}

Recreate jQuery link effect in CSS3

Does anyone know how to recreate this link effect that is done in jQuery in pure CSS3?
The effect can be seen at: http://www.yuhong-ng.com/
Same html :
<a href="#" id="liveshows" style="margin-top: -40px;">
<span class="top">Live Shows</span>
<span class="bottom">Live Shows</span>
</a>
Same base CSS :
#navigation li a {
height:80px;
font-size: 18px;
font-family: 'PT Sans Narrow';
font-weight: bold;
}
#navigation li,#navigation li a {
float: left;
}
#navigation li a span {
display:block;
height:32px;
padding:8px 20px 0 20px;
cursor:pointer;
}
An some new CSS3 stuff :
#navigation li a {
-webkit-transition: margin-top 500ms linear;
-moz-transition: margin-top 500ms linear;
transition: margin-top 500ms linear;
}
#navigation li a:hover {
margin-top: -40px;
}
So, what happens here ?
On hover, your JavaScript animates the margin property to -40px. Simple stuff.
So, in CSS, you need a transition property and, on :hover, change the margin. Same stuff.
A better version would use 3dtransforms, because it avoids repainting. It depends really if this effect is alone on your page (then transition on margin is fine) or if the website is "effect rich" (then repaints are to be tracked and eliminated.)
#navigation li a {
-webkit-transition: -webkit-transform 500ms linear;
-moz-transition: -moz-transform 500ms linear;
transition: -ms-transform 500ms linear;
transition: transform 500ms linear;
}
#navigation li a:hover {
-webkit-transform: translate3d(0,-40px,0px);
-moz-transform: translate3d(0,-40px,0px);
-ms-transform: translate3d(0,-40px,0px);
transform: translate3d(0,-40px,0px);
}
More about repaints (must see video) : http://www.youtube.com/watch?v=x0VR3lUOpdc

I want to make my links ease into images

I am a beginner in this and I am working on my new website. But I am stuck at one point where I want the effect that will make my links fade into images. I am having a navigation-bar on top of my page and when I hover over the link, I want the text to fade out at the same time as a small logo is fading in. And when I hover out of the link I want the image to fade out at the same time as the lin is fading back in, you know?
But when I do this, the image just pops up and fades out at the same time as the link is fading out...
#navigation a[name="project"] {
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#navigation a[name="project"]:hover {
opacity:0;
background-image:url(bilder/project.png)
}
The image is the background for the element you're fading out, so it will also fade on hover. You'll need to separate the image into a separate element.
Perhaps you could use absolute positioning inside a container to have the text cover up the image, and then when the text is hovered over, it'll fade out, revealing the image underneath.
A working example of this is at http://jsfiddle.net/y9aw7/
HTML:
<div id="container">
Example Text
<img src="http://placekitten.com/100/100" />
</div>
CSS:
#container {
position: relative;
}
a, img {
position: absolute;
left: 0;
top: 0;
height: 100px;
width: 100px;
}
a {
z-index: 1;
line-height: 100px;
text-align: center;
background-color: #fff;
-webkit-transition: 0.4s opacity;
-moz-transition: 0.4s opacity;
-o-transition: 0.4s opacity;
-ms-transition: 0.4s opacity;
transition: 0.4s opacity;
}
a:hover {
opacity: 0;
}
Edit: Further jsfiddle, forked from the fiddle provided by the OP, with corrected CSS: http://jsfiddle.net/JmwdC/1
Try this :
Demo
CSS
#gl{
position:absolute;
left:0px;
width:100px;
height:30px;
opacity:0;
transition:all 0.5s;
}
#gl:hover{
opacity:1;
}
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<a href='http://www.google.com/'> <img id=gl src='https://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif'>
Google</a>
</body>
</html>
You can use any property you want to achieve this, except display which does not work with CSS3 transition.
The most common techniques make use of
opacity (to 0)
height (to 0)
z-index (to negative / lower value than the container)
Sticking to your example, you can do it by using an background-image in <li>, and changing the opacity to the <a>, no changes to your HTML are needed.
Demo: http://jsfiddle.net/D6wuH/2/
Relevant CSS
li {
/* ... other stuff... */
background:none no-repeat scroll center center ;
}
#navigation li, #navigation li > a{
transition: all 1s ease-in-out;
}
#navigation li > a{
background: white;
}
#navigation li:hover {
background:url(http://dareminnesota.com/images/facebook-like-button.png)
no-repeat scroll center center transparent;
}
#navigation li:hover > a {
opacity: 0;
}
Playing with the difference between the initial state and the hover state of a lot of properties (was X, on hover becomes Y; wasn't there, on hover it's there; was there, on hover it's not there anymore) will let you achieve a world of different results, with weird effects like this: http://jsfiddle.net/D6wuH/0/ :)

Selecting parent menu should show child menu

I am developing a Wordpress site and trying to display my menu as shown in image. How can I display the sub menu when the parent menu is selected?
You can create your main top links with secondary nested like so
<ul class="primary">
<li>Tutorial</li>
<ul class="secondary">
<li>Photoshop</li>
<li>Illustrator</li>
<li>Flash</li>
<li>HTML</li>
<li>PHP</li>
<li>Wordpress</li>
<li>jQuery</li>
<li>more...</li>
</ul>
<li>Wallpaper</li>
<li>Get A Quote</li>
<li>Photography</li>
<li>Freelance</li>
</ul>
then your styling would be like so ( this is using just CSS3, not JS )
<style>
ul.primary {
width: -- ;
height: -- ;
margin: -- ;
overflow: hidden;
}
ul.primary > li {
width: -- ;
height: -- ;
margin: -- ;
float: left;
list-style: none;
}
ul.seconday {
opacity: 0;
width: -- ;
height: -- ;
margin: -- ; /* when this is used with position: relative you can adjust where the drop down is placed. */
position: relative; /* need to set this to relative to position properly */
/* css3 transition */
transition: all .5s ease-in;
-webkit-transition: all .5s ease-in;
-moz-transition: all .5s ease-in;
-ms-transition: all .5s ease-in;
-o-transition: all .5s ease-in;
}
ul.primary > li:hover ul.secondary {
opacity: 1;
}
</style>

Resources