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%;
}
Related
<div align="center">
<div class="container2">
<img src="img/3.png" alt="discussion Threads" class="image" height="200px" width="150px">
<div class="overlay">
<div class="text">Here you can discuss different topics and ask or answer questions.</div>
</div>
</div>
<div class="container2">
<img src="download.png" alt="Avatar" class="image">
<div class="overlay overlay2">
<div class="text">Bottom</div>
</div>
</div>
<div class="container2">
<img src="download.png" alt="Avatar" class="image">
<div class="overlay overlay3">
<div class="text">Bottom</div>
</div>
</div>
</div>
i want to make the images next to each other but i can't idk why or how tbh and this is the css i have tried everything it doesn't work
I want 3 images side by side with hover and caption, at the moment I have 3 images going from top to bottom, the hover is good but not side by side. How do I make the images appear side by side? Thanks.
.container2 {
position: relative;
width: 250px;
}
.image {
display: block;
width: 250px;
height: 300px;
height: auto;
margin: 17%;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay {
height: 85%;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.overlay2 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay2 {
height: 85%;
}
.overlay3 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay3 {
height: 85%;
}
You would have to add float property to your container2 selector. Please check the css rule below.
.container2 {
float: left;
position: relative;
width: 250px;
}
.container {
width: 400px;
height: 400px;
padding: 0px;
display: grid;
grid-template-columns: auto auto auto;
}
.item {
width: 100px;
height: 200px;
margin: 2px;
}
<div class="container">
<div class="item" style="background-color:red">
</div>
<div class="item" style="background-color:blue">
</div>
<div class="item" style="background-color:yellow">
</div>
</div>
Why don't you grid-display property ?
This might help you
For these such scenarios there is a beautiful/clean/simple concept called flex which is helping by decreasing number of lines of code:
here is the example with column, color and hover effect, hope it helps you:
#MainDiv {
height: 200px;
width: 650px;
display: flex;
/* here is a concept */
flex-direction: row;
/* you can either change it to row/columns */
padding: 5px;
}
#firstDiv {
width: 200px;
margin: 5px;
background-color: red;
}
#secondDiv {
width: 200px;
margin: 5px;
background-color: blue;
}
#thirdDiv {
width: 200px;
margin: 5px;
background-color: green;
}
#firstDiv:hover {
background-color: blue;
color: white;
}
#secondDiv:hover {
background-color: green;
color: white;
}
#thirdDiv:hover {
background-color: red;
color: white;
}
<div id="MainDiv">
<div id="firstDiv">First Div</div>
<div id="secondDiv">Second Div</div>
<div id="thirdDiv">Third 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 currently have a few vertical tabs that when hovered expand down toward the content within the page. As they expand down, a "content" div within the hovered tab expands out to the right away from the tab. I like the way this looks aside from the fact that I can't seem to get the "content" div to appear on top of the other tabs. I would assume that this is due to stacking order since when I reverse the order it works just fine. Can anyone help me resolve this issue? I've tried z-index, and opacity tricks to get it to work and nothing so far. I understand that z-index changes context based on position and opacity but my knowledge on this is limited. When you supply a possible solution, can you explain why it works?
Code:
.tab {
background: #0AF;
width: 50px;
height: 150px;
position: absolute;
top: -100px;
border-radius: 5px;
transition: all linear 0.2s;
}
.tab:hover {
top: -5px;
border-bottom-right-radius: 0px;
}
.content {
position: absolute;
left: 0;
width: 50px;
height: 150px;
background: #EEE;
border-radius: 5px;
transition: all linear 0.2s;
opacity: 0;
text-align: center;
color: #222;
}
.content .foot {
position: absolute;
bottom: 0;
margin-left: -50px;
margin-bottom: 5px;
}
.tab:hover > .content, .content:hover {
left: 40px;
width: 300px;
opacity: 1;
border-bottom-left-radius: 0px;
}
.about {
background: #0AF;
}
.social {
left: 80px;
background: #F05;
}
.projects {
left: 150px;
background: #0F5;
}
<div class="tab about">
<div class="content">
<span class="foot">About Me</span>
</div>
</div>
<div class="tab social">
<div class="content">
<span class="foot">Social Media</span>
</div>
</div>
<div class="tab projects">
<div class="content">
<span class="foot">Projects</span>
</div>
</div>
Thanks,
Jamie
You could give an z-index to .tab:hover. The order is given by the order of elements in the DOM so if you give a z-index you create a new stacking order referred to the nearest position relative parent. Smashing magazing has a good post in merit link
.tab {
background: #0AF;
width: 50px;
height: 150px;
position: absolute;
top: -100px;
border-radius: 5px;
transition: all linear 0.2s;
}
.tab:hover {
top: -5px;
z-index: 3;
}
.content {
position: absolute;
left: 0;
width: 50px;
height: 150px;
background: #EEE;
border-radius: 5px;
transition: all linear 0.2s;
opacity: 0;
text-align: center;
color: #222;
}
.content .foot {
position: absolute;
bottom: 0;
margin-left: -50px;
margin-bottom: 5px;
}
.tab:hover > .content, .content:hover {
left: 40px;
width: 300px;
opacity: 1;
}
.about {
background: #0AF;
}
.social {
left: 70px;
background: #F05;
}
.projects {
left: 130px;
background: #0F5;
}
<div class="tab about">
<div class="content">
<span class="foot">About Me</span>
</div>
</div>
<div class="tab social">
<div class="content">
<span class="foot">Social Media</span>
</div>
</div>
<div class="tab projects">
<div class="content">
<span class="foot">Projects</span>
</div>
</div>
Just Insert z-index:999 to .content
.tab {
background: #0AF;
width: 50px;
height: 150px;
position: absolute;
top: -100px;
border-radius: 5px;
transition: all linear 0.2s;
}
.tab:hover {
top: -5px;
border-bottom-right-radius: 0px;
}
.content {
position: absolute;
left: 0;
width: 50px;
height: 150px;
background: #EEE;
border-radius: 5px;
transition: all linear 0.2s;
opacity: 0;
text-align: center;
color: #222;
z-index: 999;
}
.content .foot {
position: absolute;
bottom: 0;
margin-left: -50px;
margin-bottom: 5px;
}
.tab:hover > .content, .content:hover {
left: 40px;
width: 300px;
opacity: 1;
border-bottom-left-radius: 0px;
}
.about {
background: #0AF;
}
.social {
left: 80px;
background: #F05;
}
.projects {
left: 150px;
background: #0F5;
}
<div class="tab about">
<div class="content">
<span class="foot">About Me</span>
</div>
</div>
<div class="tab social">
<div class="content">
<span class="foot">Social Media</span>
</div>
</div>
<div class="tab projects">
<div class="content">
<span class="foot">Projects</span>
</div>
</div>
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>
So, I have gallery that contains some photos. I want to make when the image hovered then some information of the person is shows up, the name of person and the their role.
.gallery {
position: relative;
padding: 6px 6px;
float: left;
width: 24.99999%;
}
.flag {
border: 1px solid #ccc;
padding: 5px;
}
.flag img {
display: block;
width: 100%;
height: auto;
}
.biodata {
position: absolute;
bottom: 0;
left: 0;
right: 0;
overflow: hidden;
color: white;
width: 100%;
height: 0;
transition: .5s ease;
}
<div class="gallery">
<div class="flag">
<img src="https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300">
<div class="biodata"> HIS NAME<br/> HIS JOB </div>
</div>
</div>
I used overlay to make the info shows up, but why the text is not in order and its not on the photo? I want its in the middle bottom on the photo. any suggestion? thanks before.
below is updated snippet
.gallery {
position: relative;
padding: 6px 6px;
float: left;
width: 24.99999%;
}
.flag {
border: 1px solid #ccc;
padding: 5px;
position:relative;
}
.flag img {
display: block;
width: 100%;
height: auto;
}
.biodata {
position: absolute;
bottom: 5px;
left: 5px;
right: 0;
overflow: hidden;
color: white;
width: calc(100% - 10px) ;
height: 0;
transition: .5s ease;
display:block;
background:rgba(0,0,0,0.5);
}
.flag:hover .biodata{
height:calc(100% - 10px);
}
<div class="gallery">
<div class="flag">
<img src="https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300">
<div class="biodata"> HIS NAME<br/> President of INASGOC </div>
</div>
</div>
See this fiddle
CSS
.biodata {
z-index:100;
}
.flag:hover .biodata {
height:100%
}
Use this Code:
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height:0;
transition: .5s ease;
}
.container:hover .overlay {
bottom: 0;
height: 100%;
}
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/83/Shaki_Waterfall2.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">
<p style="padding:20px;">I am Mr. Alven</p>
</div>
</div>
</div>
</body>
</html>