Unable to execute animation on hover using CSS - html

I need to show some <div> boxes after hovering on the <div> with codeyad class (.codeyad).
* {
direction: rtl;
}
html,
body {
display: flex;
justify-content: center;
align-items: center;
}
.container {
text-align: center;
font-size: 19px;
}
div :not(.container, .codeyad) {
border: 1px solid rgb(59, 59, 59);
padding: 5px;
margin: 2px;
position: relative;
left: 120%;
opacity: 0;
}
div.js {
transition: left 0.3s 0.2s, opacity 0.3s 0.2s ease-in-out;
}
.python {
transition: all 0.6s 0.2s ease-in-out;
}
.php {
transition: all 0.9s 0.2s ease-in-out;
}
div.codeyad:hover div.js {
left: 0%;
opacity: 1;
}
<div class="container">
<div class="codeyad">کدیاد</div>
<div class="js">جاوا اسکریپت</div>
<div class="python">پایتون</div>
<div class="php">آموزش php</div>
</div>
The problem is with the following part:
div.codeyad:hover div.js{
left: 0%;
opacity: 1;
}
I need to show the <div> with class js by using animations after hovering on the <div> with class codeyad, but it doesn't execute!
Can anyone help?

You need to modify your selector like below. It will select the class .js only when your hover on div.codeyad. learn about + - (Adjacent sibling combinators).
It will work until you keep the HTML structure as is. i.e. .codeyad is immediately followed by .js
div.codeyad:hover + div.js {
left: 0%;
opacity: 1;
}
Working code below (updated with comments)
* {
direction: rtl;
}
html,
body {
display: flex;
justify-content: center;
align-items: center;
}
.container {
text-align: center;
font-size: 19px;
}
div :not(.container, .codeyad) {
border: 1px solid rgb(59, 59, 59);
padding: 5px;
margin: 2px;
position: relative;
left: 120%;
opacity: 0;
}
div.js {
transition: left 0.3s 0.2s, opacity 0.3s 0.2s ease-in-out;
}
.python {
transition: all 0.6s 0.2s ease-in-out;
}
.php {
transition: all 0.9s 0.2s ease-in-out;
}
div.codeyad:hover~div.js,
div.codeyad:hover~div.php,
div.codeyad:hover~div.python {
left: 0%;
opacity: 1;
}
<div class="container">
<div class="codeyad">کدیاد</div>
<div class="js">جاوا اسکریپت</div>
<div class="python">پایتون</div>
<div class="php">آموزش php</div>
</div>

Yup, you can achieve this by using this: https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator
A note to keep in mind when using this: It'll work "only if it immediately follows the first element, and both are children of the same parent"
So to get the desired result you would do something like this:
div.codeyad:hover+div.js {
left: 0%;
opacity: 1;
}

With this code (last snippet provided), you are accessing div with class "js", that is a child of div class "codeyad"
You are telling css something like this =>
<div class="codeyad"> // on hover, do something with child class js
<div class="js"></div>
</div>
I think the easiest solution is with javascript, where you can access hover functions. Or you can also try with CSS, but it is a little tricky, you have to know CSS selectors. Link provided here.

Related

show child after parent hover transition

I have a problem here. I need the "sidebar-buttons" to appear after increasing the parent element's size by the hover.
gif w/ my problem
buttons have display none and after I hovering my sidebar-list-item their display change to flex, so I need this change appear after changing sidebar-list-item height and background.
here is my code:
html:
<div class="sidebar-list-item">
<div class="sidebar-main-items">
<div>Стретч-плёнки</div>
<img
src="./assets/icons/sidebar/paper-icon.svg"
width="32"
alt="paper icon"
/>
</div>
<div class="sidebar-buttons">
<button class="sidebar-button-buy" onclick="#">Купить</button>
<button class="sidebar-button-how" onclick="#">Как выбрать?</button>
</div>
</div>
css:
.sidebar-list-item {
font-weight: 500;
font-size: 14px;
min-height: 75px;
height: 100%;
display: flex;
align-items: center;
color: black;
border-bottom: 1px solid #f9f9f9;
transition: all 0.5s ease-in-out;
}
.sidebar-list-item:hover {
display: block;
min-height: 114px;
background-color: #ffca3a;
}
.sidebar-list-item:hover .sidebar-buttons {
display: flex;
}
.sidebar-list-item:hover .sidebar-main-items img {
opacity: 1;
}
What you need is animate the height of it.
First, set the heigth of content as auto.
Second, in buttons container, set max-height:0 and overflow:hidden.
Third, animate the buttons container to max-height:200px.
What happens?
The css will animation will take 400ms to reach 500px even if the container is smaller, so consider testing smaller values so the button animation doesn't finish before the main container animation.
Edit: Updated the snippet, added the transition-delay property on button animation to run 500ms after container animation.
.sidebar-list-item {
font-weight: 500;
font-size: 14px;
height: 50px;
display: block;
align-items: center;
color: black;
border-bottom: 1px solid #f9f9f9;
transition: all 0.5s ease-in-out;
padding:10px 0;
transition-delay: 500ms;
}
.sidebar-list-item:hover {
transition-delay: 00ms;
background-color: #ffca3a;
height:60px;
}
.sidebar-list-item:hover .sidebar-main-items img {
opacity: 1;
}
.sidebar-list-item:hover .sidebar-buttons {
max-height:150px;
transition: all 0.5s ease-in-out;
transition-delay: 500ms;
}
.sidebar-buttons{
transition: all 0.5s ease-in-out;
display: flex;
max-height:0;
overflow:hidden;
}
<div class="sidebar-list-item">
<div class="sidebar-main-items">
<div>Стретч-плёнки</div>
<img
src="./assets/icons/sidebar/paper-icon.svg"
width="32"
height="32"
alt="paper icon"
/>
</div>
<div class="sidebar-buttons">
<button class="sidebar-button-buy" onclick="#">Купить</button>
<button class="sidebar-button-how" onclick="#">Как выбрать?</button>
</div>
</div>

Images get resized to 0 x 0 in heroku app

I have a simple webpage hosted on Heroku. There are 4 images which get resized to 0x0 automatically while it shows up perfectly fine on localhost. I can't figure out what's going wrong.
What it looks like on localhost
What it looks like on heroku
The grey background is because the next section has that background which means the image's size is 0x0.
To verify, I inspected the source code through developer tools.
<div class="section2">
<div class="heading">POWERED BY</div>
<div class="logos">
<a href="https://www.jamboreeindia.com/">
<div class="sponsor-logo">
<img src="jamboree3.png" class="overlay-logo">
<img src="jamboree.png" class="original-logo">
</div>
</a>
<a href="http://www.megalogix.org/">
<div class="sponsor-logo">
<img src="mcs2.png" class="overlay-logo">
<img src="mcs.png" class="original-logo">
</div>
</a>
</div>
</div>
CSS
.section2{
width: 100vw;
padding: 5px 0 0 0;
}
.heading{
text-align: center;
font-weight: 700;
color: #9FACCC;
}
.heading2{
text-align: center;
font-weight: 700;
color: #333;
font-size: 35px;
}
.logos{
width: 100vw;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.sponsor-logo img{
width: 150px;
height: auto;
margin: 50px;
}
.original-logo {
z-index: 1;
opacity: 0;
transition: all .3s ease;
}
.overlay-logo {
position: absolute;
z-index: 3;
transition: all .3s ease;
}
.overlay-logo:hover {
opacity: 0;
transition: all .3s ease;
}
.overlay-logo:hover + .original-logo {
opacity: 1;
transition: all .3s ease;
}
Thanks!
I found out why, disable your Adblocker on that site, it's blocking the images and injecting a style to the "sponsor-logo" class
{
display: none!important;
}

How to fix flickering on hover replacing text

If mouse on text as hover flickering text.
div {
position: absolute;
font-size: 40px;
color: black
}
.new {
opacity: 0;
visibility:hidden;
}
.old:hover {
opacity: 0;
visibility:hidden;
}
.new:hover {
opacity: 1;
visibility: visible;
}
<div class="old">Old</div>
<div class="new">New</div>
How i can show text New if mouse hover (without wrapper please)?
Code on JSFiddle
You can simply use content along with :after to replace text
div {
position: block;
font-size: 40px;
color: black
}
.old:after{
content:'old';
}
.old:hover:after{
content:'new';
}
<div class="old"></div>
Edited
I think you have been asking that old must disappear on hover and new must stay forever even after hover effects.
This can be done by transition effects. This time I go for Allan Jebaraj's answer using z-index and altering the opacity transition effects.
div {
position: absolute;
font-size: 40px;
color: black
}
.new {
opacity: 0;
transition: opacity 9999s;
}
.old {
z-index: 1;
transition: opacity 9999s;
}
.old:hover {
opacity: 0;
transition: opacity 0s;
}
.old:hover+.new {
opacity: 1;
transition: opacity 0s;
}
<div class="old">old</div>
<div class="new">new</div>
I think this is what you are asking. Set the transition time as large as possible to make sure they don't revert back to normal as user stays.
You can try this
div {
font-size: 40px;
color: black
}
.new {
display: none;
}
.old:hover + .new {
display: block;
}
You have to set the z-index of the class .old and use the adjacent sibling selector to hide the old class and display the .new class.
Refer the JSFiddle below.
JSFiddle link
div {
position: absolute;
font-size: 40px;
color: black
}
.new {
opacity: 0;
}
.old {
z-index: 1;
}
.old:hover {
opacity: 0;
}
.old:hover+.new {
opacity: 1;
}
<div class="old">Old</div>
<div class="new">New</div>

Make div slide up when another div is hovered on

I have a block called case-card which consists of a child div called case-card__wrapper that houses text.
On case-card hover, I want the case-card__wrapper to move up slightly. Not in one action, but as transition.
I feel like I have the general idea, but unsure on how to get the transition to work? At the moment, it just phases from one spot to another:
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
position: absolute;
transition: 0.5s;
/*top: 0; Don't want to add this because I want the text to be centered in the div and rather not define a number since the div heights may vary */
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
top: 150px;
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
I'm trying to do this just via CSS. Any ideas?
If you cannot set initial value simply use transfrom. You can also remove position:absolute
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
transition: 0.5s;
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
transform:translateY(-100%);
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>

The text within a div element is ignoring the CSS3 animation controls. What am I doing wrong?

I have a very simple menu that I am trying to get working - however, while I have the basic animation going, the child content inside the animated div is NOT hidden. This is pure CSS3, and I am trying to avoid jQuery IF it can be done at all. It uses the checkbox hack to act as a fake button to trigger the menu.
In this state, the menu is hidden but the content text is still clearly showing.
The text should be hidden along with the div that it's contained in.
HTML:
<body>
<input type="checkbox" value="selected" id="exCheckBoxID" class="exTooltip-input">
<label for="exCheckBoxID" class="exTooltip-Label exTooltipTopLeft"></label>
<div id="exMC" class="exMC-TopLeftPosition">
Test
</div>
CSS:
.exTooltip-Label {
background-color: #000;
width: 32px;
height: 32px;
cursor: pointer;
display: inline-block;
}
.exTooltip-input {
display: none;
}
.exTooltip-input:not(checked) ~ #exMC {
height: 0px;
}
.exTooltip-input:checked ~ #exMC {
height: 97%;
}
#exMC {
position: fixed;
width: 160px;
background-color: #565656;
-webkit-transition : all 0.30s ease-out;
-moz-transition : all 0.30s ease-out;
-o-transition : all 0.30s ease-out;
transition : all 0.30s ease-out;
}
The menu is written inside a standard HTML5 template, with
for consistency, but it seems like the Chrome stylesheet may be overriding things anyway. However, this same issue shows up in Firefox and Opera as well.
What is it that I am missing, in order to hide the contents of the menu when the
animation is in it's "closed" state?
Instead of using the height you could use the display: block & display: none properties but that would remove the animation.
However you can use the visibility property to achieve what you want here.
Refer to attached code:
.exTooltip-Label {
background-color: #000;
width: 32px;
height: 32px;
cursor: pointer;
display: inline-block;
}
.exTooltip-input {
display: none;
}
.exTooltip-input ~ #exMC {
height: 0px;
visibility: hidden;
/* display: none; */
}
.exTooltip-input:checked ~ #exMC {
height: 97%;
visibility: visible;
/* display: block; */
}
#exMC {
position: fixed;
width: 160px;
background-color: #565656;
-webkit-transition: all 0.30s ease-out;
-moz-transition: all 0.30s ease-out;
-o-transition: all 0.30s ease-out;
transition: all 0.30s ease-out;
}
<input type="checkbox" value="selected" id="exCheckBoxID" class="exTooltip-input">
<label for="exCheckBoxID" class="exTooltip-Label exTooltipTopLeft"></label>
<div id="exMC" class="exMC-TopLeftPosition">
Test
</div>