Activating div while hovering over underlaying div - CSS transition not working - css

First of all, I'm sorry if this question was already answered but I couldn't find it anywhere.
I'm trying to get a smooth transition when hovering over a div. On top of this div is another div, which gets visible when hovering. The transition didn't seem to do the trick, so how can I pull this off? (jquery instead of CSS, or other/better code?)
Maybe there's another way of doing this, I hope you guys can help me.
HTML:
<ul>
<li>
<div class="hover">
<a href="#">
<p>Test</p>
</a>
</div>
<img src="#" alt="img" />
<div class="text">
<p>Test</p>
</div>
</li>
</ul>
CSS:
body { background-color: #eee;
}
ul { margin: 0;
padding: 0;
list-style: none;}
ul li { width: 30.33%;
height: auto;
margin-right: 3%;
padding: 5px;
background-color: #fff;
float: left;
position: relative;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li img { width: 100%;
max-height: 100%;
z-index: 1;
background-color: #ddd;
border: 0;}
.text { width: 100%;
padding-top: 7%;}
.text p { margin: 0 10px;
padding-bottom: 7%;}
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
display: none;}
.hover a { width:100%;
height: 100%;
margin: 0;
padding: 25px;
display: block;
color: #fff;
text-decoration: none;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li:hover > .hover { display: block;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;}
Here's the code: http://jsfiddle.net/HAFEx/
Thanks in advance!

A couple things need to be changed. Firstly, you can't animate the display property, so you should toggle opacity on hover instead.
Secondly, you should apply the transition on .hover, not just on parent:hover .hover so that it transitions both ways.
Using both of those improvements (and some formatting of your code) you get this result
.hover {
transition: all 0.2s ease;
opacity:0;
... Other properties ...
}

display:block can't be afected by a transition.
Instead use opacity.
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
opacity:0;
}
ul li:hover > .hover{
display: block;
opacity:1;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}
http://jsfiddle.net/Rjq3y/

You cannot transition css display. Try opacity.
http://jsfiddle.net/HAFEx/2/
ul li:hover .hover {
opacity:1;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}

You can also jquery to animate the display:none property.
$("li").mouseover(function(){
$(".hover").fadeIn(1000);
});
$(".hover").mouseout(function(){
$(".hover").fadeOut(1000);
});
Check out this codepen.
http://codepen.io/anon/pen/rqozA

The display property is a number or hexadecimal value, so it cannot be tweened. In this circumstance, you can't simply have the hover state opacity: 0.
Two work arounds are Javascript (messy) and using CSS Keyframe animations. http://hschwarz77.wordpress.com/2013/10/16/css-transition-from-display-none-to-display-block-on-hover/
To the best of my knowledge, these are the only solutions to have the div completely hidden (and unusable...visibility:hidden occupies the space) and fade in.

Related

Focus effect on HTML <li>tag ( Wordpress)

Is there any way with css or JavaScript to set an animation border when it is clicked or active in wordpress?
I want to make this effect on a ul lists.I'm using a filter product and i can't put a button inside li elements.
.btn{
border:none;
color: #FFFFFF29;
position: relative;
display: inline-block;
overflow: hidden;
padding: 0.5rem 0;
font-size:65px;
transition: .3s;
transition-delay: 0.5s;
}
.btn::before{
content: "";
position: absolute;
left: 0;
bottom: 0;
height: 1px;
width: 100%;
background-color: #fff;
transform: translateX(-105%);
transition: transform 0.5s ease-in-out;
transition-delay: 0.5s;
}
.btn:focus::before{
transform: translateX(0);
}
.btn:focus{
transition:.3s;
color:#fff;
transition-delay: 0.5s;
outline: none;
background-color: transparent;
}
.btn:not(hover){
color: #FFFFFF29 ;
background-color: #1a1a1a;
}
ul {
background-color:#1a1a1a;
list-style-type: none;
}
<ul>
<li><button class="btn" >Digital Marketing</button></li>
<li><button class="btn" >Sviluppo</button></li>
</ul>
Elementor Class Add into a tag
.btn:not(hover){
color: var(--e-global-color-secondary) !important;
background-color: #1a1a1a;
}

Using CSS only to slow off hover

I have the following CSS and want to slow the displayLnone attribute when it goes off hover but the transitions don't seem to be working.
CSS:
.dropdown .dropdown-menu
{
position: absolute;
top: 38px;
left: -15px;
display: none;
margin: 0;
list-style: none;
width:200px;
border:1px solid #759931;
padding: 0;
background: #fff;
border-radius: 5px;
-moz-border-radius: 5px;
z-index:10000;
-webkit-transition: all 5000ms ease;
-moz-transition: all 5000ms ease;
-ms-transition: all 5000ms ease;
-o-transition: all 5000ms ease;
transition: all 5000ms ease;
}
.dropdown:hover .dropdown-menu
{
display: block;
}
A JSFiddle would be helpful.
display cannot be transitioned or animated. Use opacity or transform: scale() according to your likings. Here's an example using opacity:
.dropdown .dropdown-menu {
position: absolute;
top: 38px;
left: -15px;
opacity: 0;
margin: 0;
list-style: none;
width: 200px;
border: 1px solid #759931;
padding: 0;
background: #fff;
border-radius: 5px;
-moz-border-radius: 5px;
z-index: 10000;
-webkit-transition: all 5000ms ease;
-moz-transition: all 5000ms ease;
-ms-transition: all 5000ms ease;
-o-transition: all 5000ms ease;
transition: all 5000ms ease;
}
.dropdown:hover .dropdown-menu {
opacity: 1;
}
/* demo styles */
.dropdown {
background-color: #f0f0f0;
position: relative;
height: 30px;
width: 200px;
}
<div class="dropdown">Hover me
<div class="dropdown-menu">My beautiful menu</div>
</div>
.dropdown {
padding: 5px;
background: tomato;
position: relative;
}
.dropdown .dropdown-menu {
position: absolute;
transition: all 500ms ease-in-out;
opacity: 0;
visibility: hidden;
background: white;
border: 1px solid peru;
padding: 10px;
}
.dropdown:hover .dropdown-menu {
opacity: 1;
visibility: visible;
}
<div class="dropdown">
Hover
<div class="dropdown-menu">Menu</div>
</div>
Key bits are opacity: 0 and visibility: hidden, and then opacity: 1 and visibility: visible on hover. That will create the transition/fade-in look you're going for.
transition and animate only work on certain properties (see: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties ). You have to use height/width, opacity, etc.
It should also be noted, if using height or width, the keyword auto cannot be transitioned to or from.
Edit:
li>ul.height {
max-height: 0;
overflow: hidden;
}
li:hover>ul.height {
max-height: 200px;
}
li>ul.opacity {
opacity: 0;
}
li:hover>ul.opacity {
opacity: 1;
}
/* Basic Stuff */
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
div>ul>li {
display: inline-block;
position: relative;
padding: .5em;
}
li>ul {
position: absolute;
left: 0;
transition: all ease 2s;
}
a {
display: block;
padding: .5em;
}
<div>
<ul>
<li>Sublist Height
<ul class="height">
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
<li><a>Item 3</a></li>
</ul>
</li>
<li>Sublist Opacity
<ul class="opacity">
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
<li><a>Item 3</a></li>
</ul>
</li>
</ul>
</div>
The display property is not animatable. You can read the list of animatable properties (which translates to: properties that can be used transitions/animations) right here: CSS Animatable

Animate an element that had display: none?

How can I make a hidden element unhidden and transition?
Example:
I want to animate a <div> that has display: none; height: 0px; transition: height 600ms;.
So on click I add a class with display: block; height: 100px;.
The height does not animate.
CodePen
I would prefer a solution that uses transition, but if none is available I can use animation. I am not looking for any answers that use javascript.
You're not going to be able to animate it with display. If you give your .submenu class an overflow: hidden; and remove the display: none;, it will animate as desired since you're already animating the height from 0.
CSS
.submenu {
height: 0;
overflow: hidden; /* <-- Add This */
background: blue;
transition: height 600ms ease 0ms;
}
CodePen
$('.menu').click(function(){
$('.submenu').toggleClass('open');
});
.menu {
background: red;
position: fixed;
top: 0;
left: 0;
right: 0;
transition: all .2s ease-in-out;
}
.submenu {
height: 0;
overflow: hidden;
background: blue;
transition: height 600ms ease 0ms;
}
.submenu.open {
display: block;
height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu">
<h1>Click me to expand a submenu</h1>
<div class="submenu">
<p>test 1</p>
<p>test 2</p>
</div>
</div>

Scrollable / hoverable CSS tooltip with psuedo elements

I have a hoverable CSS-only tooltip that works well in most instances, but I want to add a scrollbar when it exceeds a max-height. If I add max-height: 50px; overflow-y: auto, my pseudo elements :before and :after will disappear due to the overflow property.
See: http://jsfiddle.net/accelerate/24xwru1n/
Is there a way to add a scrollbar to my tooltip while maintaining my pseudo elements? Or will I have to live without my pseudo elements to make it work?
I'm afraid you have to add a wrapper when you want a scroll in hover and apply to this the css as in tooltip-text:
HTML
<div class="tooltip tooltip-scroll">Hover over me for scrollbar
<div class="wrapper">
<span class="tooltip-text">Hello there<br/>abc<br/>def<br/>ghi<br/>jkl<br/></span>
</div>
</div>
.wrapper{
position:relative;
}
.tooltip {
transform: none;
margin: 50px;
}
.tooltip:hover > .tooltip-text, .tooltip:hover > .wrapper {
pointer-events: auto;
opacity: 1.0;
}
.tooltip > .tooltip-text, .tooltip >.wrapper {
display: block;
position: absolute;
z-index: 6000;
overflow: visible;
padding: 5px 8px;
margin-top: 10px;
line-height: 16px;
border-radius: 4px;
text-align: left;
color: #fff;
background: #000;
pointer-events: none;
opacity: 0.0;
-o-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
/* Arrow */
.tooltip > .tooltip-text:before, .tooltip > .wrapper:before {
display: inline;
top: -5px;
content: "";
position: absolute;
border: solid;
border-color: rgba(0, 0, 0, 1) transparent;
border-width: 0 .5em .5em .5em;
z-index: 6000;
left: 20px;
}
/* Invisible area so you can hover over tooltip */
.tooltip > .tooltip-text:after, .tooltip > .wrapper:after {
top: -20px;
content: " ";
display: block;
height: 20px;
position: absolute;
width: 60px;
left: 20px;
}
.wrapper > .tooltip-text {
overflow-y: auto;
max-height: 40px;
display: block;
}
<div class="tooltip">Hover over me for no scrollbar<span class="tooltip-text">Hello there<p/>abc<br/>def<br/>ghi<br/>jkl<br/></span></div>
<p/><p/><p/>
<div class="tooltip tooltip-scroll">Hover over me for scrollbar
<div class="wrapper">
<span class="tooltip-text">Hello there<br/>abc<br/>def<br/>ghi<br/>jkl<br/></span>
</div>
</div>

How to create tooltip without JavaScript using only inline CSS?

I'm trying to create a hover tooltip using inline CSS without JavaScript.
This is the code I have now
<a href="#"
style="{position:relative; top:50px; left:50px;}
:hover span {opacity:1; visibility:visible;}">
hover text
<span
style="top:-10px; background-color:black; color:white; border-radius:5px; opacity:0; position:absolute; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; -ms-transition: all 0.5s; -o-transition: all 0.5s; transition: all 0.5s; visibility:hidden;">
tooltip text
</span>
</a>
According to this it should be allowed: http://www.w3.org/TR/2002/WD-css-style-attr-20020515
I know this is not the recommended way to do it, but it needs to be usable where only inline CSS can be used.
You were pretty close, I've added some properties:
HTML Markup:
<a href="#" class="tooltip">hover text
<span>tooltip thisIsALongTextMadeToBeBreak</span>
</a>
CSS Markup:
a.tooltip {
position: relative;
top: 50px;
left: 50px;
}
a.tooltip:hover span {
opacity: 1;
visibility: visible;
}
a.tooltip span {
padding: 10px;
top: 20px;
min-width: 75px;
max-width: 150px;
background-color: #000000;
color: #FFFFFF;
height: auto;
border-radius: 5px;
opacity: 0;
position:absolute;
visibility: hidden;
word-wrap: break-word;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
Here's a live demo if you want to check it out
If you want, you can check it out some more examples/ideas here
Hope it helps!
try this sample.....
a.tooltip {
outline:none;
}
a.tooltip strong {
line-height:30px;
}
a.tooltip:hover {
text-decoration:none;
}
a.tooltip span {
z-index:10;
display:none;
padding:14px 20px;
margin-top:-30px;
margin-left:28px;
width:240px;
line-height:16px;
}
a.tooltip:hover span {
display:inline;
position:absolute;
color:#111;
border:1px solid #DCA;
background:#fffAF0;
}
.callout {
z-index:20;
position:absolute;
top:30px;
border:0;
left:-12px;
}
/*CSS3 extras*/
a.tooltip span {
border-radius:4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-moz-box-shadow: 5px 5px 8px #CCC;
-webkit-box-shadow: 5px 5px 8px #CCC;
box-shadow: 5px 5px 8px #CCC;
}
above css create a tooltip ...
for demo
JsFiddle demo
The top answer doesn't quite address the specific letter of the question (which as a comment suggests may just be impossible), but provides a valuable plug and play solution (if you have access to a stylesheet). I found myself in a similar situation, but where I wasn't able to modify the page style sheet (only insert html), so I thought i'd also give an answer that is effective but misses the specifics of the question.
In particular, should you be willing to use a little bit of javascript, then you can make use of this hacky approach:
<div
onMouseOver="this.children[0].style.display = 'block'"
onMouseOut="this.children[0].style.display = 'none';"
>Example Content
<span id="innerContent" style="
display: none;
background: #C8C8C8;
margin-left: 28px;
padding: 10px;
position: absolute;
z-index: 1000;
width:200px;
height:100px;">Inner Content</span>
</div>
The use of this.children instead of querySelector is intentional, as it makes it easier to just drop in, without the need for adjusting ids to get the inner element. This styling is drawn from this fiddle.

Resources