hey guys I was working on transforms and testing them on overlapping divs and I couldn't make the div that is beneath to transform too
is it possible to do it without any JS?
as you can see the purple div on hover transforms and disappears and I want the red div under it to slightly rotate too and I couldn't make It work
.container {
position: relative;
padding: 2%;
}
.cover {
position: absolute;
top: 13px;
left: 13px;
}
.box1 {
display: inline-block;
width: 200px;
height: 200px;
background-color: red;
}
.box2 {
display: inline-block;
width: 200px;
height: 200px;
background-color: purple;
transition: 2s ease-in-out;
}
.box2:hover {
transform: rotate(35deg);
transition: 2s ease-in-out;
border-radius: 50%;
opacity: 0;
}
<div class="container">
<div class="top">
<div class="box1"></div>
<div class="box1"></div>
</div>
<div class="cover">
<div class="box2"></div>
<div class="box2"></div>
</div>
</div>
Update based on a comment, now using pseudo elements instead of a doubled markup
.container {
padding: 2%;
}
.box {
position: relative;
display: inline-block;
width: 150px;
height: 150px;
}
.box::before,
.box::after {
content: ' ';
position: absolute;
left: 0; top: 0;
height: 100%;
width: 100%;
transition: 2s ease-in-out;
background-color: purple;
}
.box::before {
background: url(http://lorempixel.com/200/200/nature/1);
background-size: cover;
}
.box:hover::before,
.box:hover::after {
transform: rotate(35deg);
transition: 2s ease-in-out;
border-radius: 50%;
opacity: 0;
}
.box:hover::before {
opacity: 0.6;
}
<div class="container">
<div class="top">
<div class="box"></div>
<div class="box"></div>
</div>
</div>
This is what you could do
.container {
width: 500px;
}
.box {
display: inline-block;
position: relative;
}
.box:hover .top,
.box:hover .cover {
transform: rotate(35deg);
transition: 2s ease-in-out;
border-radius: 50%;
opacity: 0;
}
.top {
width: 200px;
height: 200px;
background-color: red;
}
.cover {
position: absolute;
width: 200px;
height: 200px;
background-color: purple;
}
<div class="container">
<div class="box">
<div class="cover"></div>
<div class="top"></div>
</div>
<div class="box">
<div class="cover"></div>
<div class="top"></div>
</div>
</div>
Just brainstorming: How about creating a parent by putting both divs inside a div3, make div3 transparent, position with z-index above the other ones, capturing the hover. Select the other divs then simply as childs of div3:hover.
Related
Is there any way to trigger a div outside of a div without using Javascript. I tried CSS combinators and couldn't get it to work. I'm not sure if I just did it wrong or it's not possible. If anyone knows a way to achieve this I would appreciate the help.
.wrapper{
display: flex;
flex-direction: row;
}
.overlay{
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height:0;
transition: .5s ease;
opacity: 0.5;
}
.bottom:hover .overlay, .top:hover .overlay {
bottom: 0;
height: 100%;
}
.top{
position: relative;
width: 200px;
height: 200px;
margin: 25px 25px 0px 0px;
background-color: black;
}
.bottom{
height: 200px;
width: 200px;
background-color: green;
margin-top: 25px;
}
<div class="wrapper">
<div class="top">
<div class="overlay"></div>
</div>
<div class="bottom"></div>
</div>
Yes but to an extent. In this example I can rotate the second div in the html flow by hovering over the first div using ~.
#one {
position: absolute;
width: 100px;
height: 100px;
background: red;
}
#two {
position: absolute;
right: 10px;
width: 100px;
height: 100px;
background: blue;
}
#one:hover ~ #two{
animation: rotate 2s linear infinite;
}
#keyframes rotate {
to {transform: rotate(360deg)}
}
<div id="one"></div>
<div id="two"></div>
For your code if you place <bottom> before <top> in html you can hover over the green to make the overlay animate.
html
<div class="wrapper">
<div class="bottom"></div>
<div class="top">
<div class="overlay"></div>
</div>
</div>
CSS
.bottom:hover ~ .top .overlay{
bottom: 0;
height: 100%;
}
UPDATE:
.wrapper{
display: flex;
flex-direction: row-reverse;
width: min-content;
}
.overlay{
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height:0;
transition: .5s ease;
opacity: 0.5;
}
.bottom:hover ~ .top .overlay{
bottom: 0;
height: 100%;
}
.top{
position: relative;
width: 200px;
height: 200px;
margin: 25px 25px 0px 0px;
background-color: black;
}
.bottom{
height: 200px;
width: 200px;
background-color: green;
margin-top: 25px;
}
<div class="wrapper">
<div class="bottom"></div>
<div class="top">
<div class="overlay"></div>
</div>
</div>
Assuming the red box represents my webpages container, and items B,C,D are outside the container. Is it possible to have the items (A,B,C,D...) auto scroll left to right like a carousel using just CSS?
I'm seen examples online on how to do this with images but not with DIVs full of text with a set width?
.container {
margin: 0 auto;
width: 800px;
background: red;
padding: 36px;
box-sizing: border-box;
}
.items {
display: flex;
}
.item {
box-sizing: border-box;
margin-left: 72px;
margin-right: 72px;
padding: 36px;
position: relative;
width: 200px;
min-width: 200px;
background: #efefef;
text-align: center;
border-radius: 4px;
}
<div class="container">
<div class="items">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
</div>
Here's a way to do it.
.container {
margin: 0 auto;
background: red;
box-sizing: border-box;
overflow-x: hidden;
}
.items {
min-height: 200px;
position: relative;
}
.item {
box-sizing: border-box;
padding: 36px;
position: absolute;
width: 30%;
background: #efefef;
text-align: center;
border-radius: 4px;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
animation: slide-item 4s infinite;
animation-timing-function: cubic-bezier(.4, 0, .2, 1);
opacity: 0;
}
.item:nth-child(2) { animation-delay: 1s; }
.item:nth-child(3) { animation-delay: 2s; }
.item:nth-child(4) { animation-delay: 3s; }
#keyframes slide-item {
0% { left: 150%; opacity: 1; }
36% { left: 50%; opacity: 1; }
72% { left: -50%; opacity: 1; }
100% { left: -50%; }
}
<div class="container">
<div class="items">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
</div>
I was working on some transition related boxes where I bumped into this problem. Here are some images with grey scale. When you hover on them they come to their normal state. What the actual problem is when you hover on the image there is a class with border and specific height that is being displayed. I gave specific height to the class and when you hover on image the height of the class should increase and stop at one particular point. But, the height transition is not working.
.section-inner {
width: 440px;
margin: 0 auto;
}
.grid-img:hover {
-webkit-filter: grayscale(0);
filter: grayscale(0);
}
.grid-img {
background-color: #ffffff;
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
position: relative;
display: inline-block;
margin-right: 50px;
transition: all 0.8s ease-in-out;
}
.profile img {
width: 150px;
height: auto;
}
.img-caption {
top: 10px;
left: 5%;
z-index: -1;
height: 20%;
position: absolute;
display: none;
width: 90%;
height: 20%;
border: 4px solid gray;
}
.grid-img:hover .img-caption {
z-index: 99;
border: 4px solid orange;
display: block;
height: 120%;
}
.dummy {
position: absolute;
bottom: 0;
}
.dummy h4 {
font-size: 16px;
padding-bottom: 10px;
}
<div class="section-inner">
<div class="atg-col-2 grid-img">
<div class="profile">
<img src="https://preview.ibb.co/dJHACQ/Road.jpg">
</div><!-- .profile-->
<div class="img-caption">
<div class="dummy">
<h4>SARA CAVIL</h4>
</div>
</div><!-- img-caption-->
</div><!-- grid-img-->
<div class="atg-col-2 grid-img">
<div class="profile">
<img src="https://preview.ibb.co/jFhtXQ/adam_birkett_187521.jpg">
</div><!-- .profile-->
<div class="img-caption">
<div class="dummy">
<h4>SARA CAVIL</h4>
</div>
</div><!-- img-caption-->
</div><!-- grid-img-->
</div>
Any kind of help is appreciated.
Thank you in advance.
Do you want something like this?
The problem was the display:none, which was causing the transition problem. I added an extra transition to show the change. Also since you are using absolute positioning you need not mention the width, you can just define the left and right positions, Also instead of using the display:none property, how about going for visibility:hidden and visibility:visible as demonstrated on in my below CSS classes.
CSS:
.img-caption {
top: 0px;
left: 0px;
right:0px;
visibility:hidden;
z-index: -1;
height: 20%;
position: absolute;
transition:all 1s ease;
height: 20%;
border: 4px solid gray;
}
.grid-img:hover .img-caption {
z-index: 99;
visibility:visible;
border: 4px solid orange;
display: block;
height: 120%;
}
Snippet:
.section-inner {
width: 440px;
margin: 0 auto;
}
.grid-img:hover {
-webkit-filter: grayscale(0);
filter: grayscale(0);
}
.grid-img {
background-color: #ffffff;
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
position: relative;
display: inline-block;
margin-right: 50px;
transition: all 0.8s ease-in-out;
}
.profile img {
width: 150px;
height: auto;
}
.img-caption {
top: 0px;
left: 0px;
right:0px;
visibility:hidden;
z-index: -1;
height: 20%;
position: absolute;
transition:all 1s ease;
height: 20%;
border: 4px solid gray;
}
.grid-img:hover .img-caption {
z-index: 99;
visibility:visible;
border: 4px solid orange;
display: block;
height: 120%;
}
.dummy {
position: absolute;
bottom: 0;
}
.dummy h4 {
font-size: 16px;
padding-bottom: 10px;
}
<div class="section-inner">
<div class="atg-col-2 grid-img">
<div class="profile">
<img src="https://preview.ibb.co/dJHACQ/Road.jpg">
</div><!-- .profile-->
<div class="img-caption">
<div class="dummy">
<h4>SARA CAVIL</h4>
</div>
</div><!-- img-caption-->
</div><!-- grid-img-->
<div class="atg-col-2 grid-img">
<div class="profile">
<img src="https://preview.ibb.co/jFhtXQ/adam_birkett_187521.jpg">
</div><!-- .profile-->
<div class="img-caption">
<div class="dummy">
<h4>SARA CAVIL</h4>
</div>
</div><!-- img-caption-->
</div><!-- grid-img-->
</div>
you can use
.img-caption {
top: 10px;
left: 5%;
z-index: -1;
height: 0%;
position: absolute;
width: 90%;
border: 4px solid gray;
transition: all 0.8s ease-in-out;
}
I'm trying to use overlay effect for the images, but I'm not able to fit it exactly to the size of the image.
here is my link to code pen: https://codepen.io/saisree/pen/OmKMgm
<div class="row">
<header class="text-center sec-heading">
<h2>Meet the Family</h2>
<span class="subheading">We are the ones!</span>
</header>
<div class="a col-lg-4 col-md-6 mb-sm-50">
<img style="height:100%;width:100%;" class="a img-responsive" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRsl7JTXK1z2ZomjuzpU49t7TlSMdYcioHrQLvHjmuM_3r5oc36" />
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</div>
Here is the CSS:/* .
.myjumbotron{
background-color: black;
} */
#over img {
margin-left: auto;
margin-right: auto;
display: block;
}
.jumbotron {
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRygQnWzs3GfysYKie99aTXhbYvGrS7gxQzTAFFu9DN4azC_nwz");
background-position: center;
background-size: cover;
}
h3{
text-color:black;
}
#family h2{
color: black;
text-decoration:none;
}
#Nav h3{
color: black;
text-decoration:none;
}
/* .wrapper {
position: relative;
padding: 0;
width:100px;
display:block;
}
.text {
position: absolute;
top: 0;
color:#f00;
background-color:rgba(255,255,255,0.8);
width: 100px;
height: 100px;
line-height:100px;
text-align: center;
z-index: 10;
opacity: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.text:hover {
opacity:1;
}
img {
z-index:1;
}
*/
.text {
white-space: nowrap;
color: black;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.a:hover .overlay {
height: 100%;
}
.b:hover .overlay {
height: 100%;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: white;
overflow: hidden;
width:100%;
height: 0;
transition: .5s ease;
}
/* .team-item {
display:inline-block;
background:red;
margin-bottom:10px;
}
*/
Any kind of help would be highly appreciated!
You forgot to give position: relative; to the parent, please just add:
.a {
position: relative;
}
#over img {
margin-left: auto;
margin-right: auto;
display: block;
}
.jumbotron {
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRygQnWzs3GfysYKie99aTXhbYvGrS7gxQzTAFFu9DN4azC_nwz");
background-position: center;
background-size: cover;
}
h3{
text-color:black;
}
#family h2{
color: black;
text-decoration:none;
}
#Nav h3{
color: black;
text-decoration:none;
}
.text {
white-space: nowrap;
color: black;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.a {
position: relative;
}
.a:hover .overlay {
height: 100%;
}
.b:hover .overlay {
height: 100%;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: white;
overflow: hidden;
width:100%;
height: 0;
transition: .5s ease;
}
<div class="row">
<header class="text-center sec-heading">
<h2>Meet the Family</h2>
<span class="subheading">We are the ones!</span>
</header>
<div class="a col-lg-4 col-md-6 mb-sm-50">
<img style="height:100%;width:100%;" class="a img-responsive" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRsl7JTXK1z2ZomjuzpU49t7TlSMdYcioHrQLvHjmuM_3r5oc36" />
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</div>
So you can see how this works, I've stripped back your CSS to focus on exactly what's needed here.
I think you should wrap both the image and the overlay div in an another element, which I've given the class inner-wrap as below. This element should be position: relative since it is the parent of both the image and the overlay.
You can then give the overlay position: absolute so it is placed in accordance with the parent. I've stretched it across the entirety of the parent and added a translucent background colour so you can see what's going on easier.
.inner-wrap {
position: relative;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255,255,255,0.4);
text-align: center;
}
<div class="row">
<header class="text-center sec-heading">
<h2>Meet the Family</h2>
<span class="subheading">We are the ones!</span>
</header>
<div class="a col-lg-4 col-md-6 mb-sm-50">
<div class="inner-wrap">
<img style="height:100%;width:100%;" class="a img-responsive" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRsl7JTXK1z2ZomjuzpU49t7TlSMdYcioHrQLvHjmuM_3r5oc36" />
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</div>
</div>
I'm trying to create a hover-over effect where my white box slides to the right and my text slides back into the screen.
You can see from the following video that it works if I hover over the middle of the box but because I am using negative right properties, it is glitching out if I hover over it on the left side. Does anyone know an alternative that I can do to get this to work smoothly?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: pink;
}
nav {
position: fixed;
top: 0;
right: 0;
border: 1px solid red;
height: 200px;
width: 120px;
}
nav a {
background-color: #fff;
float: right;
padding: 10px;
display: block;
width: 100%;
margin-bottom: 10px;
transition: all .4s;
text-decoration: none;
color: black;
font-weight: bold;
}
nav a:hover {
color: yellow;
margin-right: 10px;
border-box: content-box;
background-color: transparent;
}
.box,
.navlink {
position: fixed;
background-color: #fff;
width: 110px;
height: 35px;
right: 0;
transition: all .4s;
}
.navlink {
right: -110px;
font-size: 24px;
padding-top: 5px;
font-weight: bold;
color: gold;
background-color: transparent;
}
.box:hover {
right: -110px;
}
.box:hover .navlink {
right: 0;
}
.one {
top: 0;
}
.two {
top: 45px;
}
.three {
top: 90px;
}
<div class="box one">
<div class="navlink one">Home</div>
</div>
<div class="box two">
<div class="navlink two">Pizza</div>
</div>
<div class="box three">
<div class="navlink three">Plaything</div>
</div>
What I would do is a background div inside the box with position absolute.
Here is my propos: http://codepen.io/r3npi2/pen/JKNYmd
HTML:
<div class="box one">
<div class="bg"></div>
<div class="navlink one">Home</div>
</div>
<div class="box two">
<div class="bg"></div>
<div class="navlink two">Pizza</div>
</div>
<div class="box three">
<div class="bg"></div>
<div class="navlink three">Plaything</div>
</div>
CSS:
body {
background-color: pink;
}
.box {
position: fixed;
width: 110px;
height: 35px;
right: 0;
}
.box .bg {
position: absolute;
background-color: #fff;
width: 100%;
height:100%;
right: 0;
top:0;
transition: all .4s;
}
.navlink {
position: absolute;
right: -110px;
font-size:24px;
font-weight:bold;
color:gold;
background-color: transparent;
width: 100%;
height:100%;
top:0;
transition: all .4s;
padding-top:5px;
box-sizing: border-box;
}
.box:hover .bg {
right:-110px;
}
.box:hover .navlink {
right: 0;
}
.box.one {
top: 0;
}
.box.two {
top: 45px;
}
.box.three {
top: 90px;
}
Maybe it's not the best way, depending on your minimal browser requirement, but it will do.
I suggest using 3d transforms to enhance performance, since it triggers gpu.
CSS:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: pink;
}
.fixed-wrap {
position: fixed;
right: 0;
}
.hover-box {
margin-bottom: 10px;
width: 110px;
height: 35px;
transition: all .4s;
position: relative;
}
.hover-box::before {
content: "";
background-color: #fff;
width: 110px;
height: 35px;
position: absolute;
z-index: -2;
transition: all .2s ease-in-out;
}
.navlink {
font-size:24px;
/* Height hack */
line-height: 35px;
font-weight:bold;
color:gold;
transition: all .2s ease-in-out;
transform: translate3d(110px,0,0);
}
.hover-box:hover .navlink {
transform: translate3d(0,0,0);
}
.hover-box:hover:before {
transform: translate3d(110px,0,0);
}
HTML
<div class="fixed-wrap">
<div class="hover-box one">
<div class="navlink one">Home</div>
</div>
<div class="hover-box two">
<div class="navlink two">Home</div>
</div>
<div class="hover-box three">
<div class="navlink three">Home</div>
</div>
</div>
https://jsfiddle.net/xdc6umcd/
Suggest to leave the the box objects as a container with a hover state. But not transition
Have 2 child objects that transition on box:hover
.box:hover .slideOff{
left:100%;
}
.box:hover .slideOn{
left:0%;
}