How do you affect multiple child divs when hovering on the parent - css

I am trying to implement some CSS on my website that I am having a little bit of difficulty with. I currently have five 'balls' (which are just circular divs) that have staggered heights. I have been experimenting with having the balls move around when you hover on them, which is great, but currently they only continue to move as long as you keep your pointer trained on it as it moves.
Ideally, I would like to have all five move independently when you hover in the general area. I have enclosed them in a wrapper div, but I am unsure of the code to affect the child divs when you hover on the parent. I am also not sure if I'm using the terms parent and child correctly, as I've only come across this concept in the last 20 minutes!
Here is the HTML:
<div id='demoStrip'><div id='ballWrapper'>
<div id='bounce'>
<div class='ball' id='ball1'><p>Professional</p></div>
<div class='ball' id='ball2'><p>Copy</p></div>
<div class='ball' id='ball3'><p>Just</p></div>
<div class='ball' id='ball4'><p>For</p></div>
<div class='ball' id='ball5'><p>You</p></div>
</div>
</div></div> <!-- End of demoStrip div -->
Here is the CSS as it currently stands:
#demoStrip {
width: 960px;
height: 410px;
margin: 20px auto 0 auto;
/*background: #00cccc;*/
border-radius: 20px;
}
#ballWrapper {
width: 900px;
height: 410px;
margin: 0 auto 0 auto;
}
.ball {
margin: 0 20px 0 20px;
/*width: 150px;
height: 150px;*/
border-radius: 200px;
background-image: radial-gradient(circle closest-corner at center, #FFFF99 0%, #FFFF00 100%);
float: left;
box-shadow: 5px 5px 5px #333333;
}
.ball p {
text-align: center;
text-transform: uppercase;
font-family: sans-serif;
margin: 0;
}
#ball1 {
width: 150px;
height: 150px;
margin-top: 245px;
}
#ball2 {
width: 140px;
height: 140px;
margin-top: 185px;
}
#ball3 {
width: 130px;
height: 130px;
margin-top: 125px;
}
#ball4 {
width: 120px;
height: 120px;
margin-top: 65px;
}
#ball5 {
width: 110px;
height: 110px;
margin-top: 5px;
}
#ball1:hover {
margin-top: 5px;
transition: margin-top 3s;
}
#bounce:hover ~ #ball2:hover {
margin-top: 65px;
transition: margin-top 3s;
}
The very last bit of code is my attempts to make ball2 'bounce' when hovering on the 'bounce' div. At the moment it doesn't work, but I'm sure syntactically it is all wrong. Any advice would be much appreciated!

Write your CSS so it affects the balls inside a hovered div:
#bounce:hover .ball {
...
}
Or, if you need different CSS for each ball:
#bounce:hover #ball1 {
...
}
#bounce:hover #ball2 {
...
}
...

Give the hover a 100% width/ height
#ball1:hover {
width:100%;
height:100%
margin-top: 5px;
transition: margin-top 3s;
}
#bounce:hover ~ #ball2:hover {
margin-top: 65px;
transition: margin-top 3s;
width:100%;
height:100%
}

Ideally, I would like to have all five move independently when you
hover in the general area...
So do something like this:
#demoStrip:hover #bounce .ball:nth-child(1) {
//animation here
}
This should fix your second issue of...
currently they only continue to move as long as you keep your pointer
trained on it as it moves
If you still run into that issue then set them both to position: relative and set each element's z-index, but be sure to set the .ball to a higher z-index. See Submenu does not stay open for more on why.

Your last attempt wasn't too far off, but instead of
#bounce:hover ~ #ball2:hover {...}
use
#bounce:hover #ball2 {...}
this will
make ball2 'bounce' when hovering on the 'bounce' div
You do not need the second :hover on #ball2, nor do you need the tilde (~).
In CSS the tilde (~) symbol is the 'general sibling' combinator. See this article for a great intro to CSS selectors/combinators http://code.tutsplus.com/tutorials/the-30-css-selectors-you-must-memorize--net-16048
You could use the tilde to hover #ball1 and animate #ball2 (providing #ball2 is after #ball1 in the DOM) like so:
#ball1:hover ~ #ball2 {
margin-top: 65px;
transition: margin-top 3s;
}

Related

Change appearance of sticky element when it reaches sticky position

I have create a bottom div that is present all the time when scrolling the site. Its "natural" stop is right after the footer. When I do scroll, and it's not at the footer, it is a bit transparent. However, what I would like to do is when the sticky div reaches the bottom (i.e. its "true" position), then the background changes or something like that.
Is that possible WITHOUT using JS or something like that ?
Updated with a fiddle:
https://jsfiddle.net/octvg6mn/
HTML:
<div class="largeDiv"></div>
<div class="stickyDiv">Test</div>
CSS:
.largeDiv {
height: 1500px;
width: 100%;
background: #cccccc;
}
.stickyDiv {
position: sticky;
bottom: 0px;
text-align: center;
background: blue;
color: white;
opacity: 0.8;
padding: 25px;
}
.stickyDiv:hover {
opacity: 1.0;
}
So as you can see in the fiddle, the sticky has a light opacity while scrolling, but when I reach the bottom, where it is supposed to be, I would like it to turn the opacity into 1.0 or something like, just like when hovering the mouse.
You can apply an opaque background to the container to simulate this. When the sticky element will reach the bottom that background will hide the transparency:
.largeDiv {
height: 1500px;
width: 100%;
background: #cccccc;
}
.container {
background:rgba(0,0,255,1);
}
.stickyDiv {
position: sticky;
bottom: 0px;
text-align: center;
background:rgba(0,0,255,0.5);
color: white;
padding: 25px;
}
.stickyDiv:hover {
background:rgba(0,0,255,1);
}
<div class="container">
<div class="largeDiv"></div>
<div class="stickyDiv">Test</div>
</div>

Why does transitioning the transform scale of an element cause some children elements to jitter

I'm trying to scale a card element when a user hovers over it by using only the transform of the card.
However I'm noticing that in a lot of cases when the card is hovered, the child elements will jitter in some way, i.e. some letters jumping up in height for a split second.
Here's an example of the effect that i keep experiencing.
https://codepen.io/andrewmumblebee/pen/OrBGzm
You'll notice that the S of TEST, jumps in height during the transition.
I've managed to get a completely smooth transition working before, but this was absolutely positioned.
https://codepen.io/andrewmumblebee/pen/REevdB
After removing the absolute positioning, etc. it still is smooth, so I'm assuming it's something to do with having multiple child elements.
Here's the important code, the full code can be found on the first Codepen link.
<div class="container">
<div class="card">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/Godot_icon.svg" />
<div class="text">
test
</div>
</div>
</div>
body {
background: #478cbf;
}
.container {
margin: 50px auto;
width: 200px;
}
img {
width: 200px;
height: 200px;
}
.card {
width: 250px;
height: 300px;
background: linear-gradient(#444, #333);
transition: all 0.3s;
text-align: center;
padding: 30px;
will-change: transform;
transform: scale(1);
box-shadow: rgba(#000000, 0.2) 5px 5px 10px;
}
.text {
font-size: 50px;
text-transform: uppercase;
color: white;
font-family: arial;
will-change: transform;
text-align: center;
}
.card:hover {
transform: scale(1.1);
box-shadow: rgba(#000000, 0.2) 10px 10px 10px;
}

Inverse width transition from left to right to right to left

I'm reverse engineering the navigation in http://dreamelectronic.com/ (must use desktop for correct view) but in my own way.
I practically have it down, spot on, but i have one little issue i need to fix to get it just right. what i have is 2 div's that are on top of eachother and they both increase the width of the top border as see in the website. BUT one div starts at the center and stretches from center to the right and the other one stretches from the left to the center (if that makes sense). i need the second div (div2 if you go and read my code from CSSDeck) to start from the center and stretch to the left.
What i have tried is to use transform: rotateX(-180deg); as suggested from one of the answers from another question, i also tried to set the test-align: right; on the div2 also suggested. I tried animation-direction: alternate; too but no cake.
I have come across several similar situations on here but none have worked for me so far.
CSSDeck Project
Many thanks if i can get this last detail down!
You could set the below properties on your div2:
div2 {
float: right;
margin-right: 50px;
...
}
Snippet:
ul {
padding: 0;
margin: 20px;
}
li {
float: left;
list-style: none;
display: inline-block;
width: 100px;
}
div1 {
margin-left: 50px;
text-align: center;
line-height: 3;
display: block;
position: absolute;
width: 0px;
height: 50px;
border-top: 3px solid #D50;
transition: all .4s ease-in-out;
opacity: 0;
}
div2 {
float: right;
margin-right: 50px;
text-align: center;
line-height: 3;
display: block;
width: 0px;
height: 50px;
border-top: 3px solid #D50;
transition: all .4s ease-in-out;
opacity: 0;
}
men a {
text-align: center;
line-height: 3;
color: #444;
text-decoration: none;
display: block;
position: absolute;
width: 100px;
height: 50px;
z-index: 1;
transition: color .4s ease;
margin-top: 4px;
}
men a:hover {
color: #D50;
}
men a:hover~div1 {
width: 50px;
opacity: 1;
}
men a:hover~div2 {
width: 50px;
opacity: 1;
}
<ul>
<li>
<men>
HOME
<div1></div1>
<div2></div2>
</men>
</li>
<li>
<men>
ABOUT
<div1></div1>
<div2></div2>
</men>
</li>
<li>
<men>
PRODUCTS
<div1></div1>
<div2></div2>
</men>
</li>
<li>
<men>
CONTACT
<div1></div1>
<div2></div2>
</men>
</li>
</ul>
So your div1 is pushed using margin-left (which you already had) and your div2 is first forced to float from right and then pushed using margin-right.
Hope this helps.
P.S. Don't forget to close the div2.
You can use positioning for "right-to-left" div:
position: absolute;
right: 0;
http://jsfiddle.net/u5ofdp9m/1/

Animation stop with css3

At the moment i am working on a header with a slider animation (css3 only):
http://jimmytenbrink.nl/slider/
Everything is working fine except sometimes the slider is bugging if you go from the center to the right. It seems that i need to stop the animation for a few miliseconds to complete. However i searched everywhere on the internet but i cant seem to get it to work.
Anyone here has experience with it who can help me out?
HTML
<header>
<div><span>slide 1</span></div>
<div><span>slide 2</span></div>
<div><span>slide 3</span></div>
<div><span>slide 4</span></div>
<div><span>slide 5</span></div>
<div><span>slide 6</span></div>
<div><span>slide 7</span></div>
<div><span>slide 8</span></div>
</header>
CSS
header {
margin-top: 10px;
width: 800px;
overflow: hidden;
height: 500px;
}
header div {
background-color: #000;
width: 43.8px;
height: 200px;
position: relative;
float: left;
-webkit-transition: width .3s;
transition: width .3s;
overflow: hidden;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
margin-right: 2px;
}
header div:first-child {
margin-left: 0px;
}
header div:last-child {
margin-right: 0px;
}
header div:hover span {
left: 50px;
opacity: 1;
}
header div img {
position: relative;
left: -240px;
-webkit-transition: all .3s;
transition: all .3s;
-webkit-filter: grayscale(1);
overflow:hidden;
}
header div span {
-webkit-transition: left .3s;
transition: left .3s;
position: absolute;
bottom: 30px;
color: white;
left: -350px;
opacity: 0;
width: 450px;
font-family:'Fugaz One', cursive;
text-transform: uppercase;
font-size: 24px;
color: #fff;
text-shadow: 0px 0px 10px #f1f1f1;
filter: dropshadow(color=#f1f1f1, offx=0, offy=0);
}
header:hover > div {
width: 43.8px;
}
header:hover > div:hover {
width: 150px;
}
Here is a JSFiddle
So the question is, how can i set a stop on the animation for a few miliseconds so the animation can finish before it gets triggered again?
Hope my question is clear!
(thanks for the edit)
One might call my answer a workaround. Maybe it is but according to my comment on ExtPro's answer - it is still completely pure CSS.
I decided to use display: table-cell since the table cell's width is distributed equally.
So, the CSS might look like this:
HINT: This is only a bunch of necessary CSS. All the code is in the jsFiddle
header {
width: 368px;
display: table;
overflow: hidden;
}
header > div {
width: 44px;
height: 200px;
position: relative;
-webkit-transition: width .3s;
transition: width .3s;
display: table-cell;
overflow: hidden;
}
header > div:hover {
width: 151px;
}
Fiddle
As you can see, we don't have to determine the width of all not-hovered divs. Actually, the problem came from that very CSS rule:
/* DON'T USE THIS RULE - IT'S THE RULE WHICH WAS BAD */
header:hover > div {
width: 43.8px;
}
You were changing the width of the divs on header:hover, so when the transition didn't manage to do its job in time, you came out with mouse pointing to the header but to non of the divs.
If I understand what you mean by 'bugging', what is happening is if you move the mouse quickly to the right, it traverses the currently open div and is left in an area which when that div collapses, does not contain (e.g. the mouse is not hovered over) the next one in order to expand it- namely the hover event of the following div(s) is/are not firing thus they do not expand. There wont be a CSS fix for this Im afraid as its browser related, you may want to replace with jQuery/JS.

css footer menu transition

I have a problem trying to work out a small test menu with the (for me) "new" css3. The menu should be in the footer which always is on the bottom of the View port. However, I would like to mess around with the transition effects css3 offers therefore I want to grow a point of the menu when you :hover it.
The menu points are set to float:left in a relative menu div. The transition does as intended except the height transition enlarges the element downwards and (obviously as it is the footer) out of the page.
Instead I would like the menu points to grow upward. To solve this i could change the float:left to position:absolute and add bottom:0, but I would have to horizontal position every menu point (hyperlink) manually which I would like to avoid. Since the Menu size (number of menu points) should be variable and I also don't want to use and JavaScript, I am clueless.
Here is the css and the html:
<div id="footer">
<div class="menu">
menp1
menp2
menp3
menp4
menp5
menp6
</div>
</div>
and the css:
#footer {
position: absolute;
background-color: #497044;
bottom: 0px;
width: 100%;
height: 45px;
padding: 5px; }
div.menu {
position: relative;
height: 45px;
width: 480px;
left: 50%;
margin-left: -240px; }
div.menu a {
float:left;
width: 80px;
height: 50px;
border: 3px dashed;
margin-left: 5px;
text-align: center;
-moz-transition: height 2s; }
div.menu a:hover {
background-color: white;
height: 100px; }
thanks for the advice!
http://jsfiddle.net/nqCgu/2/
You mean something like this?
You can use a negative margin-top value and margin-top transition to achieve this. Add:
div.menu { ...
transition: margin-top .2s;
-moz-transition: margin-top .2s;}
div.menu a:hover {
margin-top:-50px;
background-color:white;
height: 100px; }

Resources