Make one div slide over another using only CSS - html

I am attempting to have 2 divs of the same size, one is initially visible while the other (below?) is initially hidden.
I desire that when you hover over the first div, the other will animate and slide upward to fully cover the first. This one should remain in place until you stop hovering over the area.
I can get a second div to move upward on hover, but it has many unwanted effects - such as a jumpy/jittery behaviour when the second div is in place - and in this fiddle, the lower one begins visible.
http://jsfiddle.net/cc28samh/1/
the HTML
<div>
<div id="stay-in-place">
<h1>hello world</h1>
<p>ipsum dolorum caveat emptor veni vidi vici</p>
</div>
<div id="move-in-to-place">
<h2>I'm on top</h2>
</div>
</div>
the style
<style type="text/css"> #stay-in-place {
position:relative;
height : 200px;
width : 200px;
background: red;
-webkit-transition: height 1s, -webkit-transform 1s;
transition: height 1s, transform 1s;
}
#stay-in-place:hover {
height : 0px;
}
#move-in-to-place {
position:absolute;
height : 200px;
width : 200px;
background: blue;
}
</style>

This is what I think you want:
http://jsfiddle.net/8heq7w0b/
Better: http://jsfiddle.net/sdL1vead/
<div class="box">
<div id="stay-in-place">
<h1>hello world</h1>
<p>ipsum dolorum caveat emptor veni vidi vici</p>
</div>
<div id="move-in-to-place">
<h2>I'm on top</h2>
</div>
</div>
CSS
#stay-in-place {
height: 100%;
width: 100%;
background: red;
position: absolute;
}
#move-in-to-place {
position: absolute;
bottom: -100%;
height : 100%;
width : 100%;
background: blue;
opacity:0;
}
.box {
position: relative;
width:200px;
height:200px;
overflow:hidden;
}
.box:hover #move-in-to-place {
bottom: 0;
-webkit-transition: all 1s, -webkit-transform 1s;
transition: all 1s, transform 1s;
width:100%;
height:100%;
opacity:1;
}

I made a improved version of http://jsfiddle.net/sdL1vead/ here http://jsfiddle.net/tongadall/trqj1qgo
html
<div class="box">
<div class="stay-in-place">
<h1>hello world</h1>
<p>ipsum dolorum caveat emptor veni vidi vici</p>
</div>
<div class="move-in-to-place">
<span>I'm on top</span>
</div>
</div>
CSS
.stay-in-place {
height: 100%;
width: 100%;
background: red;
position: absolute;
}
.move-in-to-place {
position: absolute;
bottom: -100%;
height : 100%;
width : 100%;
padding: 8px;
background: rgba(255, 255, 255, 0.7);
opacity: 0;
font-size: 12px;
line-height: 1.2;
}
.box {
margin: 2px;
float: left;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
}
.box:hover .move-in-to-place {
bottom: 0;
-webkit-transition: all 0.4s, -webkit-transform 0.4s;
transition: all 0.4s, transform 0.4s;
width: 100%;
height: auto;
opacity: 1;
}
.box:not(hover) .move-in-to-place {
bottom: -100%;
-webkit-transition: all 2s, -webkit-transform 2s;
transition: all 2s, transform 2s;
width: 100%;
height: 0;
opacity: 0;
}

Related

Why is the transition timing working on color, but not text-align?

I am trying to add transition timing when switching the text alignment via :hover. The transition is added to the color properly, but not the text alignment.
example: Codepen
div {
background-color: #ff4000;
height: 300px;
width: 600px;
}
div:hover>h1 {
color: #ddd;
text-align: right;
transition: .6s ease-in !important;
}
<div>
<h1>Lorem Ipsum</h1>
</div>
I guess it was just the CSS Working Group decided not to implement it for whatever reasons. But there are other ways around, see the following demo by using position and transform tricks.
div {
background-color: #ff4000;
height: 300px;
width: 600px;
position: relative;
}
h1 {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
margin: 0;
transition: 0.6s ease-in;
}
div:hover > h1 {
color: #ddd;
left: 100%;
transform: translateX(-100%);
}
<div>
<h1>Lorem Ipsum</h1>
</div>
Another approach is to animate width.
div {
background-color: #ff4000;
height: 300px;
width: 600px;
}
h1 {
width: 0;
text-align: right;
white-space: nowrap;
margin: 0;
transition: 0.6s ease-in;
}
div:hover > h1 {
color: #ddd;
width: 100%;
}
<div>
<h1>Lorem Ipsum</h1>
</div>
transform: translateX()
text-align is not animatable but position and transforms are -- the latter being the better choice because it's less GPU/CPU intensive than the former. The following is a what was added as the first leg of the animation in the demo.
transform:translateX(300px);
transition: transform .6s ease-in;
Demo
div {
background-color: #ff4000;
height: 300px;
width: 600px;
}
h1 {
transform: translateX(0px);
transition: transform .6s ease-out;
}
div:hover>h1 {
color: #ddd;
width: 200px;
transform: translateX(300px);
transition: transform .6s ease-in;
}
<div>
<h1>Lorem Ipsum</h1>
</div>

why transition doesn't work on absolutely positioned image?

I have an absolutely positioned image inside a relatively positioned container.
Height of image is bigger than that of the container.
I want the image to scroll up to its end using only CSS.
The catch is that height of the image could vary, so it makes sense to make sure that bottom of the image is aligned with bottom of the container once hovered.
Following is the code:
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
img:hover {
bottom: 0;
}
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
Try transition on transform
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
top: 0;
transition: transform 1s ease;
}
img:hover {
transform: translateY(-60%);
}
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
EDIT:
As the height is not set, I'd suggest a jQuery/js solution
$("img")
.mouseover(function() {
var offset = -$(this).height() + 200;
$(this).css("top", offset);
})
.mouseleave(function() {
$(this).css("top", 0);
});
body {
display: flex;
justify-content: space-around;
}
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
top: 0;
transition: top 1s ease;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
<div class="box">
<img src="https://upload.wikimedia.org/wikipedia/commons/0/0c/Vertical-Banner-EN.jpg">
</div>
You need a way to position the element equivalent to bottom: 0px, but taken for the reference the top .
If you set top: 100%, the top of the element will be at the bottom of the parent.
Then, set a transform of 100%, and the bottom will be where the top was.
Notice that this solution works for any image and container height.
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
overflow: hidden;
}
.box img {
position: absolute;
left: 0;
top: 0%;
transform: translateY(0%);
transition: all 1s ease;
}
img:hover {
top: 100%;
transform: translateY(-100%);
}
<div class="box">
<img src="http://voxman.net/wp-content/uploads/2011/04/whiteonblack.jpg">
</div>
You can have a transition between bottom: 0 and bottom: calc(100% - 18px), which is the height of the container minus the height of box2.
.box {
position: relative;
display: block;
height: 200px;
width: 200px;
background-color: red;
}
.box2 {
position: absolute;
height: 18px;
bottom: calc(100% - 18px);
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.box:hover .box2 {
background-color: green;
bottom: 0;
}
<div class="box">
<div class="box2">
test
</div>
</div>
You can use this, try this with working snippet,
.box{
position:relative;
display:block;
height:200px;
width:200px;
background-color:red;
transition: all 1s ease;
}
.box2{
position: absolute;
transition: all 1s ease;
}
.box:hover .box2{
background-color:green;
margin-top: 180px;
}
<div class="box">
<div class="box2">
test
</div>
</div>

Multi boxs css hover

I want to make a box pack includes 5 below.
When leaving the mouse on a box, the box extend to whole main div and display of rest of the boxes set to none.
in this code, just box1's mouse hover well extend.
These are my codes.
.multibox{
width: 300px;
height: 300px;
border: 1px solid black;
overflow: hidden;
}
.multibox div{
position: absolute;
transition: width 0.5s, height 0.5s, -webkit-transform 0.5s;
-moz-transition: width 0.5s, height 0.5s, -webkit-transform 0.5s; /* Firefox 4 */
-webkit-transition: width 0.5s, height 0.5s, -webkit-transform 0.5s; /* Safari and Chrome */
-o-transition: width 0.5s, height 0.5s, -webkit-transform 0.5s; /* Opera */
-ms-transition: width 0.5s, height 0.5s, -webkit-transform 0.5s; /* IE9 (maybe) */
}
.box1{
background: gray;
width: 250px;
height: 50px;
float: right;
display: block;
position: initial !important;
}
.box1:hover{
width: 300px;
height: 300px;
}
.box2{
background: blue;
width: 50px;
height: 250px;
float: left;
display: block;
position: initial !important;
}
.box2:hover{
width: 300px;
height: 300px;
}
.box3{
background: red;
width: 50px;
height: 250px;
display: block;
float: right;
position: initial !important;
}
.box3:hover{
width: 300px;
height: 300px;
}
.box4{
background: green;
width: 200px;
height: 200px;
display: block;
float: right;
position: initial !important;
}
.box4:hover{
width: 300px;
height: 300px;
}
.box5
{
background: brown;
width: 250px;
height: 50px;
display: block;
float: left;
position: initial !important;
}
.box5:hover{
width:300px;
height: 300px;
}
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<div class="multibox">
<div class="box1">
box 1
</div>
<div class="box2">
box 2
</div>
<div class="box3">
box 3
</div>
<div class="box4">
box 4
</div>
<div class="box5">
box 5
</div>
</div>
</body>
</html>
In which part have made a mistake?
Make all boxes position:absolute and place them properly.
.multibox{
width: 300px;
height: 300px;
border: 1px solid black;
overflow: hidden;
position: relative;
}
.multibox div{
position: absolute;
transition: all 0.5s, height 0.5s, -webkit-transform 0.5s;
-moz-transition: all 0.5s, height 0.5s, -webkit-transform 0.5s; /* Firefox 4 */
-webkit-transition: all 0.5s, height 0.5s, -webkit-transform 0.5s; /* Safari and Chrome */
-o-transition: all 0.5s, height 0.5s, -webkit-transform 0.5s; /* Opera */
-ms-transition: all 0.5s, height 0.5s, -webkit-transform 0.5s; /* IE9 (maybe) */
}
.multibox div:hover{
z-index: 99;
}
.box1{
background: gray;
width: 250px;
height: 50px;
right: 0;
top: 0;
display: block;
}
.box1:hover{
width: 300px;
height: 300px;
}
.box2{
background: blue;
width: 50px;
height: 250px;
float: left;
display: block;
}
.box2:hover{
width: 300px;
height: 300px;
}
.box3{
background: red;
width: 50px;
height: 250px;
display: block;
right: 0;
top: 50px;
}
.box3:hover{
width: 300px;
height: 300px;
top: 0;
}
.box4{
background: green;
width: 200px;
height: 200px;
display: block;
left: 50px;
top: 50px;
}
.box4:hover{
width: 300px;
height: 300px;
left: 0;
top: 0;
}
.box5
{
background: brown;
width: 250px;
height: 50px;
display: block;
left: 0;
bottom: 0;
}
.box5:hover{
width:300px;
height: 300px;
}
<div class="multibox">
<div class="box1">
box 1
</div>
<div class="box2">
box 2
</div>
<div class="box3">
box 3
</div>
<div class="box4">
box 4
</div>
<div class="box5">
box 5
</div>
</div>

Adding a rollover only works on one image div

I am creating a rollover on an image div where once you roll over, the image opacity goes down and text over the top appears. This works fine for just one image, but when trying it on more then one image the opacity doesn't work correctly and the text doesn't seem to appear on the other images.
HTML:
<div class="worklongdiv" style="padding-top:111px";>
<img src="images/Vividworklong.jpg"/>
<div class="work-text-content-long">
<header>VIVID VAPOURS</header>
<p style="font-size:17px; font-family:GothamRoundedBold;">Branding • Product Dev • Web Dev</p>
</div>
</div>
<div class="worklongdiv" >
<img src="images/Vividworklong.jpg"/>
<div class="work-text-content-long">
<header>VIVID VAPOURS</header>
<p style="font-size:17px; font-family:GothamRoundedBold;">Branding • Product Dev • Web Dev</p>
</div>
</div>
CSS:
.worklongdiv{
width: 100%;
min-height: 120px;
max-height:auto
position: relative;
background-color: black;
}
.worklongdiv:hover img {
opacity: 0.3;
}
.worklongdiv:hover .work-text-content-long {
opacity: 1;
}
.worklongdiv img {
padding: 0;
width: 100%;
display: block;
opacity: 1;
}
.worklongdiv img,
.work-text-content-long {
-webkit-transition: opacity 0.5s ease-out;
-moz-transition: opacity 0.5s ease-out;
-o-transition: opacity 0.5s ease-out;
transition: opacity 0.5s ease-out;
}
.work-text-content-long {
height:100px;
position: absolute;
color: white;
left: 0;
top: 25%;
right: 0%;
left:101px;
bottom: 0;
font-size: 24px;
text-align: left;
opacity: 0;
}
You're missing a ; in one of your CSS rules.
.worklongdiv{
width: 100%;
min-height: 120px;
max-height:auto;
position: relative;
background-color: black;
}

HTML pop up footer issues. 100% height problems

I'm trying to make a footer so that when clicked it pops up and fills the entire screen.
I do not know how to do this so the height is 100%.
I can do it with set pixels but I want it to fill the screen and not exceed the screen if a small window is open and reach halfway if its a big window.
If I set the footers container to 100% of the height the content and the animation will come to the top and animate downwards. Which it does 100% of the screen.
HTML
<div id="footerSlideContainer">
<div id="footerSlideButton"></div>
<div id="footerSlideContent">
<div id="footerSlideText">
<h3>blabla</h3>
<p>blablablabla.</p>
<ul>
<li>bla</li>
<li>Bla</li>
<li>bla</li>
<li>blabla</li>
</ul>
<p>bedst i test</p>
</div>
</div>
</div>
CSS
#footerSlideContainer {
position: fixed;
bottom: 0;
width: 100%;
z-index: 5;
}
#footerSlideButton {
background: rgba(255,255,255,0.0);
position: absolute;
top: -60px;
width:100%;
height:120px;
border: none;
cursor: pointer;
}
#footerSlideContent {
width: 100%;
height: 0;
background: white;
color: #CCCCCC;
font-size: 0.8em;
border: none;
-webkit-transition: height 700ms ease-in;
-moz-transition: height 700ms ease-in;
-ms-transition: height 700ms ease-in;
-o-transition: height 700ms ease-in;
transition: height 700ms ease-in;
}
#footerSlideContent.open {
height: 100%;
}
Maybe something like this will help in your situation:
#footerSlideContainer {
width: auto;
height: auto;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
z-index: 5;
}