This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed last year.
I'm having an issue with a button animation I'm trying to make. I want a description box to slide out from behind a button when the button is hovered over, but in the way that I'm doing it, it has no transition and just snaps to its position. My setup is below:
.button {
position: absolute;
display: flex;
padding:7px;
margin: 20px;
background-color: red;
}
.button > .popout {
display: none;
position: absolute;
padding: 2px;
background-color: blue;
color: white;
transition: 1s;
}
.button:hover > .popout {
display: block;
transform: translateX(20px);
}
<div class="button">
<div class="icon">
O
</div>
<div class="popout">
email
</div>
</div>
when what I really want is the "email" text to glide out from beneath the O background without showing any blue or text on the left of the O. Sorry if I didn't do this right or provide enough info, I'm very new to stack overflow and just getting back into HTML and CSS after leaving it alone for a while
Animations don't work with display: none/block, you have to use visibility: hidden/visible:
.button {
position: absolute;
display: flex;
padding:7px;
margin: 20px;
background-color: red;
}
.button > .popout {
visibility: hidden;
position: absolute;
padding: 2px;
background-color: blue;
color: white;
transition: 1s;
}
.button:hover > .popout {
visibility: visible;
transform: translateX(20px);
}
<div class="button">
<div class="icon">
O
</div>
<div class="popout">
email
</div>
</div>
Related
When hovering over a in html I want to display a text. Right now I have it this way:
echo "<td onmouseover='' style='cursor: pointer; background-color:#ffeb3b' title=$text id=$text></td>";
The problem is that it looks very small and without design.
How could I make it look bigger and with a little look?
I would like to do something similar to this in html.A box that appears on the right
For more information look here
body {
text-align: center;
}
.tooltip {
position: relative;
display: inline-block;
cursor: default;
}
.tooltip .tooltiptext {
visibility: hidden;
padding: 0.25em 0.5em;
background-color: black;
color: #fff;
text-align: center;
border-radius: 0.25em;
white-space: nowrap;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 100%;
left: 100%;
transition-property: visibility;
transition-delay: 0s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
transition-delay: 0.3s;
}
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
This is how you can do it. First, create the main element, I'm using a text, and next to it add the text you wish to show on hover. Style everything according to your taste. Make sure you set the display of the extra text to none. Basically, we'll hide it and show it only when someone hovers over the main element.
Now, in the CSS, I've added .Main-Text:hover + .Extra-Text CSS Selector to achieve what we are trying to do. This basically means that when someone hovers on the element with class Main-Text, something will happen to the element with the class Extra-Text.
You can read about this more here.
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
min-height: 100vh;
}
.Main-Text:hover + .Extra-Text {
display: block;
}
.Extra-Text {
background-color: #FFFFFF;
margin-top: 10px;
width: 200px;
border: 2px solid #000000;
padding: 10px;
font-size: 16px;
display: none;
}
<html>
<div>
<p class="Main-Text">
Hover me to know more about me.
</p>
<div class="Extra-Text">
<p>
This is the extra information that will be displayed when the text is hovered.
</p>
</div>
</div>
</html>
I don't think so if this is something you are looking for but it's worth mentioning. You can use the title attribute in the HTML Elements to display some text when the user hovers over the element. Try it yourself. Run the snippet below and hover over the text.
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
min-height: 100vh;
}
<html>
<div>
<p class="Main-Text" title="This is some extra text">
Hover me to know more about me.
</p>
</div>
</html>
I'm trying to make a kind of animated website only using CSS Animations with the :target selector
I made up my first cascade and then the main problem is encountered :
I can't animate anymore. Maybe because I am not sure of every lines of the code I am using, that is why I am coming to you.
Basically the effect is actually working on the 2nd link only.
Here is a small piece of my code:
.saq {
width: 110px;
height: 110px;
color: yellow;
margin-left: 815px;
border: 1px black solid;
margin-top: -550px;
transition: 4s ease-in-out;
position: absolute
}
.qaq {
width: 60px;
height: 110px;
margin-left: 1205px;
margin-top: -550px;
transition: 5s ease-in-out;
position: absolute;
display: inline;
cursor: auto;
background-color: black;
z-index: 1000
}
a {
font-size: 100px;
text-align: right
}
;
.navi {
margin-left: 400px;
transform: translate(300px, 200px);
}
nav a {
background-color: yellow;
display: inline-block
}
nav a:hover {
background-color: brown;
color: yellow;
}
#s1:target {
display: block;
transition: all 4s ease;
transform: translate(300px, 350px) rotate(90deg) scale(0.6);
overflow: hidden;
overflow-y: hidden
}
#move #s1:target~.saq {
transform: translateY(-1720px)
}
#move #s1:target~.qaq {
transform: translateY(-1720px)
}
<div id=move>
<nav class=navi id=s1>
<ul>Home</ul>
<ul>Creations</ul>
<ul>About</ul>
<ul>Contact</ul>
</nav>
<div class="qaq"></div>
<div class="saq"></div>
Here is the link of the page : http://faxe-kondi.16mb.com/bru.html
Here what I have done so far, is a lot of div moving after the #s1 is targeted.
What i am looking to do : Making a lot of div move after the #s3 is targeted.
Maybe it is a selector problem, or children/sibling, or maybe I cannot use two animation on the same div.
But of course there is a solution you can bring to me.
The :target selector works alright in your code. But you only use it for the #s1:target rule. Which in your HTML is only the second link.
For example:
.links>a {
display: inline-block;
width: 50px;
height: 50px;
}
.link1 {
background: red;
}
.link2 {
background: blue;
}
.link3 {
background: green;
}
.animated-box {
display: inline-block;
width: 50px;
height: 50px;
border-radius: 50px;
transition: border-radius 1s;
}
.animated-box:target {
border-radius: 0;
}
#box1 {
background: red;
}
#box2 {
background: blue;
}
#box3 {
background: green;
}
<div class="links">
<a class="link1" href="#box1"></a>
<a class="link2" href="#box2"></a>
<a class="link3" href="#box3"></a>
</div>
<div class="animated-box" id="box1"></div>
<div class="animated-box" id="box2"></div>
<div class="animated-box" id="box3"></div>
See, the difference here is how you apply the transition-effect (border-radius: 0). If you want to target only one element you can go with a selector like #s1:target but it then will only happen in case the element with id="s1" gets the target (meaning, the link with href="#s1" gets clicked).
You either want to specify more CSS rules like you did with #s1:target or you want to use a class instead like I did below.
can you test it?
<div id=move>
<nav class=navi id=s1>
<ul>Home</ul>
<ul>Creations</ul>
<ul>About</ul>
<ul>Contact</ul>
</nav>
<div class="qaq"></div>
<div class="saq"></div>
</div>
Practicing on anchor tags and drop down menu. In the following code, the dropdown is not working. Don't know why. The div containing text "This is dropdown menu" should appear exactly below the div containing text "This is text. Its in center" whenever the later is hovered upon. Both the divs are of same width.
html,body {
margin: 0px;
height: 100%;
/* [disabled]width: 100%; */
left: 0px;
top: 0px;
background-color: rgba(255,255,255,1);
}
.wrapper {
text-align: center;
margin-top: 0;
margin-left: auto;
height: 100%;
max-width: 960px;
background-color: rgba(0,0,0,1);
margin-right: auto;
position: relative;
}
.link1 {
height: auto;
width: 50%;
color: rgba(255,255,255,1);
margin-right: auto;
margin-left: auto;
background-color: rgba(204,204,204,1);
}
.link1 a {
text-decoration: none;
display: block;
}
.link1 a:hover {
text-decoration: underline;
background-color: rgba(255,0,0,1);
}
.link1 a:hover .dropdown {
display: block;
}
.dropdown
{
height: 25%;
width: 50%;
background-color: rgba(204,204,204,1);
margin-right: auto;
margin-left: auto;
text-align: center;
display: none;
}
<div class="wrapper">
<div class="link1">
This is text. Its in center
</div>
<div class="dropdown">This is dropdown menu</div>
</div>
Your css selector .link1 a:hover .dropdown selects the element with the class dropdown which has to be inside of an a element in a hover state (a:hover), which is inside an element with a class of link1.
This doesn't match your html markup.
To get it work, you can change your html to this:
<div class="wrapper">
<div class="link1">
<a href="http://www.hotmail.com">
This is text. Its in center
<div class="dropdown">This is dropdown menu</div>
</a>
</div>
</div>
Hope it helped.
Lexith is partly right, you need to add the dropdown within the container div, you can then select the sibling of the hovered a link.
Like so;
CSS -
.link1 a:hover + .dropdown {
display: block;
}
HTML -
<div class="link1">
This is text. Its in center
<div class="dropdown">This is dropdown menu</div>
</div>
CSS update -
This allows the dropdown to stay open when hovering on it
.dropdown:hover,
.link1 a:hover + .dropdown {
display: block;
}
This means it doesnt have any of the a tag styling. View my code pen
I have a problem with showing the span on the hover from my canvas. I have found a lot articles on Stack Overflow but I don't get it.
This is my html:
<section id="graphs">
<span id="tooltip">thisistest</span>
<canvas id="myChart" class="tooltip" width="550" height="350"></canvas>
</section>
and this css:
//This part works
span#tooltip {
display: none;
position: relative;
top: 8px;
left: 10px;
padding: 5px;
margin: 10px;
z-index: 100;
background: #333;
border: 1px solid #c0c0c0;
opacity: 0.8;
width: 300px;
color: White;
text-align: left;
}
//This does not show the span...
canvas.tooltip:hover #tooltip {
display: block;
}
I quickly made this fiddle.
The main problem is your :hover statement.
in the fiddle on line 22 of css.
http://jsfiddle.net/robbiebardijn/hDbq3/
#graphs:hover #tooltip
I am experimenting with using CSS to display genereated content in pseudo-elements.
The hover state does not work correctly. The content generated from the last button appears before the mouse actually hovers over the button if the mouse enters from the bottom. Is there a way to fix this so that the content only appears when the button is hovered over?
Here is a fiddle for the example: http://jsfiddle.net/Ts6qy/
Here is my HTML:
<div class="container">
<span data-title="Number 1">Item 1</span>
<span data-title="Number 2">Item 2</span>
<span data-title="Number 3">Item 3</span>
<span data-title="Number 4">Item 4</span>
</div>
Here is my CSS:
.container {
position: relative;
text-align: center;
padding: 20px 0;
max-width: 420px;
margin: 0 auto;
}
.container span {
display: inline-block;
padding: 2px 6px;
background-color:#78CCD2;
color:#FFFFFF;
border-radius:4px;
margin:3px;
cursor:default;
}
/* Pseudo-elements can even access attributes in their parent elements */
.container span::before {
position:absolute;
bottom: 0;
left: 0;
width: 100%;
content: attr(data-title);
color: #666666;
font-weight:bold;
text-align: left;
opacity: 0;
/*Animate the transistions */
-webkit-transition: opacity 0.4s;
transition: opacity 0.4s;
}
.container span:hover::before {
opacity: 1;
}
Another approach, to make clearer what is happening:
Add pointer-events: none to the pseudo element:
.container span::before {
position:absolute;
bottom: 0;
left: 0;
width: 100%;
content: attr(data-title);
color: #666666;
font-weight:bold;
text-align: left;
opacity: 0;
/*Animate the transistions */
-webkit-transition: opacity 0.4s;
transition: opacity 0.4s;
pointer-events: none;
}
And it solves the problem (of course in supporting browsers).
What was happening is that the hover was triggered by the span and also by the pseudo element of the span.
Take a look http://jsfiddle.net/Ts6qy/26/
This width: 100%; has been removed from .container span::before.
So, this way, the before just shows up when hovered it self or when on of those spans is hovered.
I don't know if you really do need what width: 100%; anyway, this method works and you can keep transitions.