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>
Related
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>
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>
I have squares with text on a website homepage and I want to add hover effect but dont know which class to choose from my website
www.justtobe.com.au homepage
the first big grid image ( beach photo), I want to add a hover effect similar to this homepage grid
<h2 id="demo12">12. Opacity #2</h2>
<div class="hover12 column">
<div>
<figure><img src="https://nxworld.net/example/css-image-hover-effects/pic01.jpg" /></figure>
<span>Hover</span>
</div>
<div>
/* Opacity #2 */
.hover
figure {
background: #1abc9c;
}
.hover12 figure img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover12 figure:hover img {
opacity: .5;
}
Can someone please help?
There are a couple of things that you have to change if your picture to look the same as the one in the website you mentioned, but if you only want that hover effect then you just need to target the span
.hover12 span {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
cursor:pointer;
}
.hover12 span:hover {
opacity: .5;
display:block;
}
Example: https://jsfiddle.net/fhntLpmz/
Though, if you want it to look like the one in the website you mentioned, you need to change the structure of your html and then your css code.
<h2 id="demo12">12. Opacity #2</h2>
<div class="hover12 column">
<div class="wrapper">
<span>Hover</span>
</div>
<div>
Instead of using img to show the image, I use css to put it as a background, so that the Hover button is inside it.
.wrapper {
background-image:url(https://nxworld.net/example/css-image-hover-effects/pic01.jpg);
background-size:100%;
background-repeat:no-repeat;
width:300px;
height:200px;
}
Other than this, it's just another couple of css. Take this example: https://jsfiddle.net/0shmd21e/1/
There are multiple ways to do this, though. This is just one of them
I'm curious. It's more for fun and tips but do you know if I can deal with a property to position the text in the middle.
I have post code on JS bin (refresh if CSS don't open) : http://jsbin.com/3/uhumok/edit?html,css,live
HTML :
<a class="one" href="#">Hi !</a>
CSS :
a {
display:block;
color:white;
text-decoration:none;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
width:100px;
height:100px;
text-align:center;
-webkit-border-radius:50px;
-moz-border-radius:50px;
border-radius:50px;
border-width:50px;
border-color:rgba(0,0,0,1);
-webkit-transition:0.2s ease;
-moz-transition:0.2s ease;
-ms-transition:0.2s ease;
-o-transition:0.2s ease;
transition:0.2s ease;
}
a:hover {
border-width:0;
border-color:rgba(0,0,0,0.5);
-webkit-transition-duration:0.5s;
-moz-transition-duration:0.5s;
-ms-transition-duration:0.5s;
-o-transition-duration:0.5s;
transition-duration:0.5s;
}
a.one {border-style:solid;}
I think this is impossible without :after or :before.
Can't you add another tag inside the <a>? If so, you can absolute position this inner tag to achieve that: http://jsbin.com/3/uhumok/6/edit?html,css,live.
if you make the color:#000 and add padding-top:50px to :hover, the text will almost stay in the same place. i didn't save the example because i didn't see a save option. if you used :before/:after the text would be absolutely positioned so idk why you don't want to use them;
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.