Rotation with perspective jumps in Firefox 32.0.1 - html

I'm transforming a div with perspective(150px) and rotateY(-1deg) and on hover I'm transitioning the rotation to 0deg.
Everything worked great, on Firefox 31.0 for Windows, then I updated to Firefox 32.0.1.
Now in Firefox 32.0.1, the perspective and rotation work, but the transition between the normal state and the hover state has a nasty little jump that I can't seem to get rid of.
Here's the stripped down code:
#wrap {
border: 1px solid #000;
display: block;
position:relative;
z-index:1;
width:550px;
}
#one, #two {
height:100px;
width:550px;
background:red;
margin: 50px 0;
transition:all 1s linear;
border: 1px solid #000;
outline: 1px solid transparent;
position: relative;
z-index:2;
}
#one {
text-align:right;
transform-origin: left center 0px;
transform: perspective(150px) rotateY(1deg);
}
#two {
transform-origin: right center 0px;
transform: perspective(150px) rotateY(-1deg);
}
#one:hover, #two:hover {
transform: perspective(150px) rotateY(0deg);
transition:all 1s linear;
}
<div id="wrap">
<div id="one">one</div>
<div id="two">two</div>
</div>
jsFiddle demo
To recreate the issue, hover on the red divs and watch the right edge. At the end of the transition you will see a 5-10 pixel shift/jump.
I've tried:
Moving perspective to the parent element.
backface-visibility: hidden; and other anti-aliasing methods
Using rotate3D() rather than rotateY()
Using transform-style: preserve-3d;
Various combinations of perspective and rotation*
*Using more extreme perspective values seems to reduce the appearance of the jump, but strangely if I hover over the elements several times in succession the jump comes and goes randomly. Example
Note that the problem doesn't appear in other browsers/versions.

I've had a look at the issue, and you are right about the differences between the firefox versions.
The problem is the 0deg value in the rotate transformation. I've tried two different solutions, one of which seems to work every time on testing, and the other glitches occasionally.
My solution using 0rad is the occasional glitchy solution:
#wrap {
border: 1px solid #000;
display: block;
position: relative;
z-index: 1;
width: 550px;
}
#one, #two {
height: 100px;
width: 550px;
background: red;
margin: 50px 0;
transition-property: all;
transition-duration: 1s;
transition-timing-function: linear;
border: 1px solid #000;
outline: 1px solid transparent;
position: relative;
z-index: 2;
}
#one {
left: 0px;
text-align: right;
transform-origin: left center 0px;
transform: perspective(150px) rotateY(0.05rad);
}
#one:hover {
transform: perspective(150px) rotateY(0rad);
}
#two {
right: 1px;
transform-origin: right center 0px;
transform: perspective(150px) rotateY(-0.05rad);
}
#two:hover {
transform: perspective(150px) rotateY(0rad);
}
<div id="wrap">
<div id="one">one</div>
<div id="two">two</div>
</div>
My other solution requires a bit more work with positions and size to give the perception of a 0deg transform by using a value of 0.1deg.
#wrap {
border: 1px solid #000;
display: block;
position: relative;
z-index: 1;
width: 550px;
}
#one, #two {
height: 100px;
width: 550px;
background: red;
margin: 50px 0;
transition-property: all;
transition-duration: 1s;
transition-timing-function: linear;
border: 1px solid #000;
outline: 1px solid transparent;
position: relative;
z-index: 2;
}
#one {
left: 0px;
text-align: right;
transform-origin: left center 0px;
transform: perspective(150px) rotateY(1deg);
}
#two {
right: 1px;
transform-origin: right center 0px;
transform: perspective(150px) rotateY(-1deg);
}
#one:hover {
transform: perspective(150px) rotateY(0.1deg);
width: 552px;
}
#two:hover {
right: 3px;
transform: perspective(150px) rotateY(-0.1deg);
width: 552px;
}
<div id="wrap">
<div id="one">one</div>
<div id="two">two</div>
</div>
Ultimately the differences in the two solutions is the amount of work required to get it to work.
For the occasional glitch, I would suffice with rad over deg.
I hope this helps.

From what version did you update? I have tried Firefox 28.0, 31.0, 32.0.2, 33.0b4 (beta), 33.0b5 (beta), and 34.0a2 (alpha). All experience this issue.
After trying multiple possibilities for property values, my belief is that this is a bug in the rendering engine. While it might be possible to find some combination of properties that forces the rendering engine to be referenced to the right, using transform-origin: right center 0px; (as you have) does appear to be what should cause this to be locked to the right edge.
The correct action appears to be to file a bug with Mozilla.
Here is a screen capture of the jump I see into the <div>:
And out of the <div> (only a couple of pixels):
Looking at it some more, the bottom <div> also jumps in the vertical direction.
As mentioned, it is unlikely there will be a workaround. However, I can suggest a hack which actually makes a dramatic improvement (at least for me).
The hack is to obscure the edges which are where the issues show up. It is not really a good solution. However, for these simple mono colored divs it does look better. Here is a JSFiddle you can test with (definitely not as compete as you would need, but it will give you an idea).
html, body, * {
padding: 0;
margin: 0;
}
#mak-overwrap {
border: 0px solid #000;
display: block;
position:absolute;
z-index:0;
width:590px;
pointer-events:none;
}
#mak-wrap1 {
border: 0px solid #000;
display: block;
position:absolute;
z-index:10;
width:570px;
left:10px;
pointer-events:none;
}
#mak-wrap2 {
border: 1px solid #000;
display: block;
position:absolute;
z-index:10;
width:550px;
left:10px;
top:0px;
height:400px;
background:transparent;
pointer-events: none;
}
#mak-three {
height:300px;
width:20px;
border: 0px solid #000;
position: absolute;
top:0px;
z-index:10;
background:white;
top:30px;
}
#mak-four {
height:300px;
width:20px;
border: 0px solid #000;
position: absolute;
top:0px;
left:572px;
z-index:10;
background:white;
top:30px;
}
#mak-one-in {
height:50px;
width:75px;
border: 0px solid #000;
position: relative;
top:0px;
z-index:11;
background:transparent;
top:0px;
left:218px
}
#mak-two-in {
height:50px;
width:75px;
border: 0px solid #000;
position: relative;
top:0px;
z-index:11;
background:transparent;
top:0px;
left:274px
}
#mak-one, #mak-two {
height:100px;
width:570px;
background:red;
margin: 50px 0;
transition:all 1s linear;
border: 1px solid #000;
outline: 1px solid transparent;
position: reletive;
z-index:2;
pointer-events: auto;
}
#mak-one {
text-align:right;
transform-origin: left center 0px;
transform: perspective(120.7px) rotateY(1deg);
left:0px;
}
#mak-two {
transform-origin: right center 0px;
transform: perspective(120px) rotateY(-1deg);
left:0px;
}
#mak-one:hover, #mak-two:hover {
transform: perspective(150px) rotateY(0deg);
transition:all 1s linear;
}
<div id="mak-overwrap">
<div id="mak-wrap1">
<div id="mak-one">
<div id="mak-one-in">one</div>
</div>
<div id="mak-two">
<div id="mak-two-in">two</div>
</div>
<div id="mak-wrap2"></div>
</div>
<div id="mak-three"></div>
<div id="mak-four"></div>
</div>

Related

animate border property on any element in one complete round css

I am trying to animate border-property on below html element having different shapes like rectangle, square, circle etc:-
The animation looks like:- it should start drawing border from one corner and stops at the last corner to complete one rotation.
html
.rectangle{
width:50px;
height:25px;
border:1px solid #333; //animate this property
}
.square{
width:40px;
height:40px;
border:1px solid #333; //animate this property
}
.circle {
width:50px;
height:50px;
border: 1px solid #333;
border-radius:100%;
}
.marg-T{
margin-top:10px;
}
<div class="rectangle"></div>
<div class="circle marg-T"></div>
<div class="square marg-T"></div>
You can use a CSS animation:
#keyframes fade {
0% {border: 1px solid black;}
25% {border-left: 1px solid white;}
50% {border-left: 1px solid white;border-top: 1px solid white;}
75% {border-left: 1px solid white;border-top: 1px solid white;border-right: 1px solid white;}
100% {border-left: 1px solid white;border-top: 1px solid white;border-right: 1px solid white;border-bottom: 1px solid white;}
}
#circle {
width: 100px;
height: 100px;
border: 1px solid black;
animation: fade 4s linear;
}
<div id="circle"></div>
, although this fades it and doesn't stay afterwards, it still is a start. I doubt there being a pure CSS way to answer your question.
Below is the sample code for animated border. Please have a look and let me know if this helps.
HTML
<div className="box-b">
<span></span>
<span></span>
<span></span>
<span></span>
<div className="content-b">
<h1>Let's Connect</h1>
<div className="contact-content" >
<form className="Message-form" onSubmit={this.handleSubmit}>
<p>Name</p>
<input name="name" onChange={this.handleInput} ></input>
<br></br>
<p>Message</p>
<textarea onChange={this.handleInput} name="message" className="message-input" ></textarea>
<br></br>
<p>Email</p>
<input onChange={this.handleInput} name="email" ></input>
<br></br>
<button type="submit" onSubmit={this.handleSubmit} className="send" >Send</button>
</form>
</div>
CSS
.box-b{
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%, -50%);
width: 600px;
height: 600px;
/* background:#E3E3E3; */
box-sizing: border-box;
overflow:hidden;
box-shadow: 0 30px 50px rgba(82, 78, 78, 0.5);
/* border:2px solid aqua; */
}
.box-b:before{
content: "";
position: absolute;
top: 0;
left:0;
width:100%;
height: 100%;
background: rgba(255,255,255,.1);
transform: 0.5;
pointer-events: none;
}
/* .box:hover:before{
left: -50%;
transform: skewX(-5deg)
} */
.box-b .content-b{
position: absolute;
top:15px;
left:15px;
right: 15px;
bottom: 15px;
border: 2px solid aqua;
padding: 30px;
text-align: center;
box-shadow: 0 5px 10px rgba(0,0,0,.5);
}
.box-b .content-b h1{
color:white;;
font-size: 30px;
margin: 0 0 0 10px;
padding: 0;
}
.box-b .content-b p{
color: white;
}
.box-b span{
position: absolute;
top:0;
left:0;
width: 100%;
height: 100%;
display: block;
box-sizing: border-box;
}
.box-b span:nth-child(1){
transform: rotate(0deg)
}
.box-b span:nth-child(2){
transform: rotate(90deg)
}
.box-b span:nth-child(3){
transform: rotate(180deg)
}
.box-b span:nth-child(4){
transform: rotate(270deg)
}
.box-b span:nth-child(2):before{
animation-delay: -2s;
}
.box-b span:nth-child(2):before{
animation-delay: -2s;
}
.box-b span:before {
content: "";
position: absolute;
width: 100%;
height: 4px;
background: #ff1100;
animation: animate1 2s linear infinite;
}
#keyframes animate1{
0%{
transform: scaleX(0);
transform-origin: left;
}
50%{
transform: scaleX(1);
transform-origin: left;
}
50.1%{
transform: scaleX(1);
transform-origin: right
}
100%{
transform: scaleX(0);
transform-origin: right;
}
}
Live working Version https://sheltered-refuge-69000.herokuapp.com/contact

CSS - Arrow not lining up

I am trying tro create a pure CSS arrow with a line like this...
.arrow {
position:absolute;
left:50%;
}
.arrow_line {
width:2px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 25px;
width: 25px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
margin-top: -24px;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>
The vertical line never quite seems to line up vertically with the arrow, I have left it slightly adrift in the example to better demonstrate that it is not centered in relation to the arrow.
Is there a better way to create a CSS arrow?
You can use one element and gradient then you won't have issue with centring:
.arrow {
width:80px;
height:80px;
background:
linear-gradient(blue,blue) bottom right/40px 4px,
linear-gradient(blue,blue) bottom right/4px 40px,
linear-gradient(
to top right,
transparent calc(50% - 2px),
blue calc(50% - 2px),
blue calc(50% + 2px),
transparent calc(50% + 2px));
background-repeat:no-repeat;
transform:rotate(45deg);
margin:20px;
}
<div class="arrow">
</div>
You can also easily adjust the size:
.arrow {
width:var(--s,80px);
height:var(--s,80px);
background:
linear-gradient(blue,blue) bottom right/calc(var(--s,80px)/2) calc(var(--t,2px)*2),
linear-gradient(blue,blue) bottom right/calc(var(--t,2px)*2) calc(var(--s,80px)/2),
linear-gradient(
to top right,
transparent calc(50% - var(--t,2px)),
blue calc(50% - var(--t,2px)),
blue calc(50% + var(--t,2px)),
transparent calc(50% + var(--t,2px)));
background-repeat:no-repeat;
transform:rotate(45deg);
margin:20px;
display:inline-block;
}
<div class="arrow">
</div>
<div class="arrow" style="--t:3px;--s:60px">
</div>
<div class="arrow" style="--t:1px;--s:40px">
</div>
<div class="arrow" style="--t:2px;--s:20px">
</div>
<div class="arrow" style="--t:1px;--s:20px">
</div>
Give your line a width which is odd. You used 2px on the line, and that resulted in the line being slightly off to one side.
I made it 3px as example.
Or vice versa, make your "point" an even number, which may make more sense, since you'll want the lines to have the same thicckness.
.arrow {
position:absolute;
left:50%;
}
.arrow_line {
width:2px;
//width: 3px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 26px;
//height: 25px;
width: 26px;
//width: 25px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
margin-top: -24px;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>
Since you arrow point is 25px wide, it won't line up. Because 25 isn't an even number.
Change it to 24 like below or any other even number.
.arrow {
position:absolute;
left:50%;
}
.arrow_line {
width:2px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 24px;
width: 24px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
margin-top: -24px;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>
.arrow {
position:relative;
height:30px;
width:2px;
background:red;
}
.arrow:after{
position: absolute;
content: '';
height: 10px;
width: 10px;
transform: rotate(45deg) translateX(-65%);
border: 2px solid red;
border-top: none;
border-left: none;
bottom: -20%;
left: 50%;
}
<div class="arrow">
</div>
working randomly change height width of after
Make it simple by using unicode arrow instead of creating it.
.arrow{
color:red;
font-size:70px;
}
<div class="arrow">↓</div>
You just need to make two small changes to your code:
1) delete the css for .arrow
2) for .arrow_point change margin-top to margin:-24px auto;
if you want to you can delete the < div class='arrow' >
simple solutions are best!
.arrow {
/*position:absolute;
left:50%;*/
}
.arrow_line {
width:2px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 25px;
width: 25px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
/*margin-top: -24px;*/
margin:-24px auto;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>

create hr with css and html with arrow bottom left

I need some help.
How can I display the html code according to the attached image.
I tried modifying the css, but it's not ok
div {
margin:50px;
background-color: #c1c1c1;
border:#000 solid 1px;
position:relative;
}
div:after{
content:'';
width:24px;
height:24px;
background:#fff;
position:absolute;
-moz-transform:rotate(45deg);
-webkit-transform:rotate(45deg);
transform:rotate(45deg);
top:-12px;
left:50px;
border-right:#000 solid 2px;
border-bottom:#000 solid 2px;
}
<div></div>
Thank You
A bit of transform:skew() does it.
Unless you're targeting very old browsers, it's no longer necessary to include the vendor-specific prefixes on these rules; they're broadly supported. (Mozilla/Firefox and IE haven't needed the prefixes for 2d transforms since 2012; Safari since 2015).
div {
margin:50px;
background-color: #c1c1c1;
border:#000 solid 1px;
position:relative;
}
div:after{
content:'';
width:24px;
height:24px;
background:#fff;
position:absolute;
top:-12px;
left:50px;
border-bottom:#000 solid 2px;
border-left:#000 solid 2px;
transform:skew(0,-45deg)
}
<div></div>
Here is another way to have transparency:
div {
margin: 50px;
height: 2px;
background: linear-gradient(to right, #000 44px, transparent 44px, transparent 60px, #000 60px);
position: relative;
}
div:before,
div:after {
content: '';
width: 2px;
position: absolute;
top: 2px;
background: #000;
}
div:after {
height: 26px;
transform-origin: top right;
transform: rotate(45deg);
left: 60px;
}
div:before {
height: 19px;
top: 0px;
left: 42px;
}
body {
background: pink
}
<div></div>

Rounding a corner that's already been affected by a border-radius [duplicate]

I'm having a slight problem with css. I need a trapezoid div which upper left corner(the one with the angle above 90 degrees) is rounded. I already know that this:
HTML:
<div style="margin:30px">
<div class="trapezoid">
</div>
</div>
CSS:
.trapezoid{
vertical-align: middle;
border-bottom: 31px solid red;
border-left: 25px solid transparent;
height: 0;
width: 150px;
}
produces a trapezoid. I tried the border-top-left-radius property, however the effect is not sufficent enough.
Here's a jsfiddle with the above code to, well, fiddle with: http://jsfiddle.net/n3TLP/5/
I there is more info needed just comment.
Thanks in advance :)
Not that you should ever do this, but you can also create a rounded corner trapezoid with a single element by applying CSS 3d transformations:
.trapezoid {
position: relative;
width: 300px;
height: 200px;
overflow: hidden;
}
.trapezoid:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 200%;
height: 100%;
background: red;
border-radius: 20px 0 0 0;
-webkit-transform-origin: 100% 100%;
-moz-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
-o-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-webkit-transform: perspective(400px) rotateX(45deg);
-moz-transform: perspective(400px) rotateX(45deg);
-ms-transform: perspective(400px) rotateX(45deg);
-o-transform: perspective(400px) rotateX(45deg);
transform: perspective(400px) rotateX(45deg);
}
​
http://jsfiddle.net/RzJTP/
Although I think you're better off using <canvas>/SVG to draw this shape, this is close to what you want:
.trapezoid{
vertical-align: middle;
border-bottom: 120px solid red;
border-left: 200px solid transparent;
border-top-left-radius:30px;
height: 0;
width: 150px;}
/* ---------- */
.trapezoid {
position:relative;
}
.trapezoid:after {
content:' ';
left:-14px;
top:-10px;
position:absolute;
background:red;
border-radius:40px 0 0 0;
width:164px;
height:40px;
display:block;
}
Demo: http://jsfiddle.net/n3TLP/20/
It's not perfect, and you'll have to play with the numbers to get your desired dimensions, it's very finicky. You might be interested in something like Raphaël for drawing, CSS doesn't really have the capacity for complex shapes (at least not intentionally).
Voila:
css:
.trapezoid{
vertical-align: middle;
background: red;
padding-left: 200px;
height: 120px;
width: 150px;
position: relative;
border-top-left-radius: 40px;
overflow: hidden;
background-clip: content-box;
}
.trapezoid:after{
content: '';
margin-left: -100px;
top: 0;
height: 120px;
background: red;
transform: skew(-31deg,0deg);
-o-transform: skew(-31deg,0deg);
-ms-transform: skew(-31deg,0deg);
-moz-transform: skew(-31deg,0deg);
-webkit-transform: skew(-59deg,0deg);
position: absolute;
width: 1000px;
border-top-left-radius: 40px;
}
Demo:
http://jsfiddle.net/n3TLP/24/
Here's my attempt lol
.trapezoid{
position:relative;
border-bottom: 100px solid blue;
border-right: 12px solid transparent;
border-left: 180px solid transparent;
width: 122px;
}
.trapezoid:before{
content:' ';
left:-184px;
top:98px;
position:absolute;
background:blue;
border-radius:80px 20px 80px 80px;
width:318px;
height:20px;
}
.trapezoid:after {
content:' ';
left:-11px;
top:-7px;
position:absolute;
background:blue;
border-radius:150px 50px 90px 0px;
width:133px;
height:30px;
}
<div style="margin:30px">
<div class="trapezoid">
</div>
</div>
http://jsfiddle.net/Bzj3h/
Use Adobe Illustrator or any other software to draw a shape and than save it as SVG code, you can use SVG directly on the page but IE8 and lower will ignore it. If you need to support older versions of IE you can use Raphael.js to draw your SVG element.
Rendering SVG polygons in Raphael Javascript library

How to slide a div over an image with CSS?

On a webpage I am working on, I have a div which contains an image and another div. The inner div is initially set to
opacity: 0;
so that it's not visible. The inner div should appear over my image when hovered. I have achieved this, but now I want to improve upon it further by having the 'overlay' div (which appears with an opacity of 0.5) slide down gradually over the image. I could do it theoretically with JavaScript but on this occasion it must be a pure CSS solution. So far my solution just makes the overlay div appear gradually (it fades in) but does not slide down as I have never done this in CSS alone.
See the image below to understand further:
The HTML:
<div class="img"> <img class="squareImg" src="img1.jpg"/><div class="overlay"> tweet This <br> Buy This</div></div>
<div class="img"> <img class="squareImg" src="img3.jpg"/></div>
<div class="img"> </img></div>
CSS
.overlay{
position: absolute;
width: 200px;
overflow-y: hidden;
transition-property: all;
transition-duration: .5s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
height: 200px;
background-color: red;
border: 1px solid white;
top: 10px;
left: 10px;
opacity: 0;
} .overlay:hover{
cursor:pointer;
opacity: 0.5;
z-index: 1;
}
.img{
position: relative;
margin-bottom: 10px;
border: 2px solid yellow;
background-color: black;
width: 200px;
height: 200px;
left: 50%;
margin-left: -110px;
padding: 10px;
}
Here it is with a slide down thanks to a height transition.
Improvements:
Instead of opacity, use background: rgba(255,0,0,0.5) so that the contents of the overlay remain fully opaque.
The transition property has been simplified to transition: all .5s
The outside border is created with box-shadow and the black border is now created with the border property instead of padding.
.overlay has a height of 0 and on hover it is given a height of 100%. It is stretched accross the image with the combination of left: 0 and right: 0
There is no set image size, the size of the <img> now controls the size of the border and overlay, allowing different image sizes.
Complete Example
.img {
position: relative;
border: 10px solid black;
box-shadow: 0 0 0 2px yellow;
display: inline-block;
vertical-align: top;
cursor: pointer;
margin: 10px;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
transition: all .5s;
overflow: hidden;
height: 0;
background: rgba(255, 0, 0, 0);
}
.img:hover .overlay,
.overlay:hover {
height: 100%;
background: rgba(255, 0, 0, 0.5);
}
.img > img {
display: block;/* Prevent inline gap under image*/
}
<div class="img">
<img src="http://www.placehold.it/200" />
<div class="overlay">tweet This <br>Buy This</div>
</div>
<div class="img">
<img src="http://www.placehold.it/300" />
<div class="overlay">tweet This <br>Buy This</div>
</div>
You can just use simple transitions for this, rather than a keyframe animation
Example:
http://jsfiddle.net/realseanp/c4e08hy7/9/
HTML:
<div class="holder">
<div class="info">
<span>All your info</span>
<div class="overlay"></div>
</div>
</div>
CSS:
.holder{
position:relative;
height:200px;
width: 200px;
overflow: hidden;
border:1px solid #000;
z-index:3;
}
.info {
box-sizing: border-box;
height: 100%;
padding: 20px;
position: absolute;
top: -100%;
transition: top 0.5s ease 0s;
width: 100%;
z-index: 4;
}
.overlay {
background: none repeat scroll 0 0 #000;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
top: 0;
width: 100%;
z-index: -1;
transition: 1s all;
}
.holder:hover .info{
top:0;
}
.holder:hover .overlay{
opacity: .85
}
Just a simple approach using the image as background:
.img{
position: relative;
background: none 50% / cover;
width: 200px;
height: 200px;
margin: 0 auto;
border: 10px solid #000;
box-shadow: 0 0 0 2px yellow;
}
.overlay{
position: absolute;
width: 100%;
height: 0%;
overflow: hidden;
transition: all .5s cubic-bezier(0, 1, 0.5, 1);
box-shadow: inset 0 0 0 1px white;
background: rgba(255,0,0,0.4); /* Don't use opacity but rgba on bg */
}
.img:hover .overlay{
height: 100%;
}
<div class="img" style="background-image:url(//placehold.it/300x300/aba)">
<div class="overlay">Tweet This <br> Buy This</div>
</div>
If you need to slide it down, you should use #keyframes:
.overlay:hover{
-webkit-animation: slide 5s; /* Chrome, Safari, Opera */
animation: slide 5s;
}
#keyframes slide {
from {height: 0px;}
to {height: 200px;}
}
/* Chrome, Safari, Opera */
#-webkit-keyframes slide {
from {height: 0px;}
to {height: 200px;}
}
You can achieve this by setting the .overlay with a negative top position and then you can target the sibling element with the + selector and change the top position to positive.
Also you can change the transition timing by setting the transition-duration: 2s; to 2 sec.
.overlay{
position: absolute;
width: 200px;
overflow-y: hidden;
transition-property: all;
transition-duration: 2s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
height: 200px;
background-color: red;
border: 1px solid white;
top: -200px;
left: 10px;
opacity: 0;
z-index:-1;
}
.squareImg:hover + .overlay, .overlay:hover {
cursor:pointer;
top:10px;
opacity: 0.5;
z-index: 1;
}
.img{
position:relative;
height:200px;
width: 200px;
overflow: hidden;
border:1px solid #000;
z-index:3;
margin-bottom: 10px;
border: 2px solid yellow;
background-color: black;
left: 50%;
margin-left: -110px;
padding: 10px;
}
DEMO http://jsfiddle.net/a_incarnati/c4e08hy7/8/