Rotating a div without rotating its content using CSS3 transformations - html

I have an image and a div over it which is working as a wrapper for the image, I am trying to rotate a square div over let's say 45 deg. to give it a diamond like shape so actually it comes as the image is being cut in a diamond like shape.
The issue is when I rotate the div the image and other things in it also gets rotated than I have to rotate those images back let's say -45deg to bring them to original place.
This is doing above involved a lot of rotating which is almost un-necessary, plus it's really not that simple for me to get it right for images and text of different size etc.
If only I can work out something through which on the above div gets rotated and elements inside it remain like how they are it will be great.
Can anyone suggest anything please?
My markup is:
<div class="wrapper" id="01">
<a href="#">
<img src="image.gif" />
<span class="text" id="text01">Lorem Ispum </span>
</a>
</div>
CSS:
.wrapper {
-webkit-backface-visibility: hidden;
position: relative;
width: 300px;
height: 300px;
margin: 0 30px 0 0;
overflow: hidden;
float: left;
-moz-transform: matrix(-0.5,-0.5,0.5,-0.5,0,0);
-moz-transform-origin: center;
-webkit-transform: matrix(-0.5,-0.5,0.5,-0.5,0,0);
-webkit-transform-origin: center;
-o-transform: matrix(-0.5,-0.5,0.5,-0.5,0,0);
-o-transform-origin: center;
-ms-transform: matrix(-0.5,-0.5,0.5,-0.5,0,0);
-ms-transform-origin: center;
transform: matrix(-0.5,-0.5,0.5,-0.5,0,0);
transform-origin: center;
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=-0.5,M21=-0.5,M12=0.5,M22=-0.5,SizingMethod='auto expand')";
filter: progid:DXImageTransform.Microsoft.Matrix(M11=-0.5,M21=-0.5,M12=0.5,M22=-0.5,SizingMethod='auto expand');
cursor: pointer;
}
.wrapper img {
width: 700px;
margin: -10px 0 0 -245px;
-moz-transform: rotate(135deg);
-moz-transform-origin: center;
-webkit-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
-webkit-transform-origin: center;
-o-transform-origin: center;
-ms-transform-origin: center;
transform: matrix(-0,-0,0,-0,0,0);
transform-origin: center;
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=-0,M21=-0,M12=0,M22=-0,SizingMethod='auto expand')";
filter: progid:DXImageTransform.Microsoft.Matrix(M11=-0,M21=-0,M12=0,M22=-0,SizingMethod='auto expand');
}
span.text {
background-color: rgba(255,255,255,0.7);
-webkit-transform: rotate(180deg);
margin: -475px 0 0 -1px;
float: left;
width: 296px;
height: 42%;
z-index: 100;
position: relative;
padding: 4px;
display: none;
font-size: 1.2em;
}

Related

HTML CSS Ken Burns distorted effect

I have a website with a header image ( 3279 x 710 px ) and I added a Ken Burns effect to it, but it seems like it is distorted. I made a fiddle with a test image, but i can't reproduce the distorted effect, however it has something to do with it's aspect ratio. The Image looks like it's pressed together.
Right now i tried to fix it with width set to auto and height to 100%, but I can't get it to work.
I made a fiddle here.
HTML
<div id="header-wrapper" class="wrapper">
<img src='http://eventzerz.com/wp-content/uploads/2018/03/Test-Logo-Small-Black-transparent-1.png' class='image-kenburns'>
<div id="header">
</div>
</div>
CSS
#header-wrapper {
background: transparent;
padding: 0;
}
.wrapper {
padding: 6em 0 9em 0;
}
.wrapper .title {
font-size: 0.9em;
width: 25em;
/*
height: 3.25em;
*/
height: 3.4em;
top: -3.25em;
line-height: 3.25em;
margin-bottom: -3.25em;
margin-left: -12.5em;
padding-top: 0.5em;
}
#header {
position: relative;
padding: 12em 0;
}
.homepage #header {
padding: 18em 0;
}
.image-kenburns {
overflow: hidden;
position: absolute;
z-index: -1;
animation: move 40s ease-in infinite;
height: 100%;
width: 100%;
}
#keyframes move {
0% {
-webkit-transform-origin: bottom left;
-moz-transform-origin: bottom left;
-ms-transform-origin: bottom left;
-o-transform-origin: bottom left;
transform-origin: bottom right;
transform: scale(1.0);
-ms-transform: scale(1.0);
-webkit-transform: scale(1.0);
-o-transform: scale(1.0);
-moz-transform: scale(1.0);
}
50% {
transform: scale(1.2);
-ms-transform: scale(1.2);
-webkit-transform: scale(1.2);
-o-transform: scale(1.2);
-moz-transform: scale(1.2);
}
100% {
transform: scale(1.0);
-ms-transform: scale(1.0);
-webkit-transform: scale(1.0);
-o-transform: scale(1.0);
-moz-transform: scale(1.0);
}
}
EDIT: I should mention that it's fine looking on desktop, what I need is the responsive version for tablets.
If you need your image to resize proportionally / keep the aspect ratio just add to your .image-kenburns class height: auto

Nested Links not working in Mozilla, IE, and Edge

I am having a slight issue with my HTML due to improper nesting. When attempting to click my links in Chrome it properly anchors to a set point. However, in Internet Explorer, Mozilla Firefox, and Edge it does not. In fact it seems as if the link is disabled. How would I go about cleaning up my nesting to fix this issue?
body{
margin: 0;
font-family: 'Raleway', sans-serif;
background: #2e2e2e;
overflow-x: hidden;
}
*{
transition: .3s;
}
#abt{
width: 100%;
height: 100vh;
background-color: cyan;
}
#hero{
height: 50%;
min-height:400px;
width: 100vw;
background: url("imgs/space2.gif");
background-size: 11%;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
transition: none;
-webkit-transform-origin: left bottom;
-ms-transform-origin: left bottom;
-moz-transform-origin: left bottom;
-o-transform-origin: left bottom;
transform-origin: left bottom;
-webkit-transform: skewY(-3deg);
-ms-transform: skewY(-3deg);
-moz-transform: skewY(-3deg);
-o-transform: skewY(-3deg);
transform: skewY(-3deg);
z-index: -1;
}
#hero h3 img{
height: 1em;
-webkit-transform-origin: left bottom;
-ms-transform-origin: left bottom;
-moz-transform-origin: left bottom;
-o-transform-origin: left bottom;
transform-origin: left bottom;
transform: skewY(3deg);
}
#hero h1{
font-size: 3.5em;
color: rgb(245, 251, 255);
margin: 0;
margin-bottom: 1.5vh;
font-weight: 100;
text-shadow: 0 1px 0 #d1d1d1,
0 2px 0 #909090,
0 3px 0 #626161;
margin-left: 5vw;
margin-right: 5vw;
margin-top: 3vh;
-webkit-transform-origin: left bottom;
-ms-transform-origin: left bottom;
-moz-transform-origin: left bottom;
-o-transform-origin: left bottom;
transform-origin: left bottom;
-webkit-transform: skewY(3deg);
-ms-transform: skewY(3deg);
-moz-transform: skewY(3deg);
-o-transform: skewY(3deg);
transform: skewY(3deg);
}
#hero h3{
font-size: 1.5em;
color: rgb(245, 251, 255);
margin: 0;
font-weight: 100;
text-shadow: 0 1px 0 #d1d1d1,
0 2px 0 #909090,
0 3px 0 #626161;
-webkit-transform-origin: left bottom;
-ms-transform-origin: left bottom;
-moz-transform-origin: left bottom;
-o-transform-origin: left bottom;
transform-origin: left bottom;
-webkit-transform: skewY(3deg);
-ms-transform: skewY(3deg);
-moz-transform: skewY(3deg);
-o-transform: skewY(3deg);
transform: skewY(3deg);
}
#options{
margin-top: 5vh;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 3vh;
margin-top: 3vh;
-webkit-transform-origin: left bottom;
-ms-transform-origin: left bottom;
-moz-transform-origin: left bottom;
-o-transform-origin: left bottom;
transform-origin: left bottom;
-webkit-transform: skewY(3deg);
-ms-transform: skewY(3deg);
-moz-transform: skewY(3deg);
-o-transform: skewY(3deg);
transform: skewY(3deg);
}
#options button{
color: rgba(78, 78, 78, 0.92);
background: rgb(245, 251, 255);
border: none;
border-radius: 3px;
padding: 5px;
padding-left: 15px;
padding-right: 15px;
font-size: 1.2em;
margin: 5px;
}
<div id="backdrop">
<div id="hero">
<h1>Haca</h1>
<h3>Student</h3>
<div id="options">
About Link
</div>
</div>
<div>
<div id="abt">About Section</div>
</div>
Thanks for your help.
For your z index in your #hero id, you need to change it to something other than -1. I just turned it off and it works. Let me know if that solves it for you. New CSS should look like this:
#hero{
height: 50%;
min-height:400px;
width: 100vw;
background: url("imgs/space2.gif");
background-size: 11%;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
transition: none;
-webkit-transform-origin: left bottom;
-ms-transform-origin: left bottom;
-moz-transform-origin: left bottom;
-o-transform-origin: left bottom;
transform-origin: left bottom;
-webkit-transform: skewY(-3deg);
-ms-transform: skewY(-3deg);
-moz-transform: skewY(-3deg);
-o-transform: skewY(-3deg);
transform: skewY(-3deg);
}

How make 3 divs skew in css

How to make a 3 div with distortion, as shown in the picture?
I have made this:
.cars {
width: 100%;
height: 500px;
}
.car {
width: 33.33333333%;
height: 100%;
background: #3498db;
position: relative;
-webkit-transform: skewx(-10deg);
-moz-transform: skewx(-10deg);
-o-transform: skewx(-10deg);
-ms-transform: skewx(-10deg);
transform: skewx(-10deg);
transform-origin: top left;
float: left;
display: inline;
}
.car:nth-child(2) {
background: #000
}
.car:nth-child(3) {
background: #ff0000
}
<div class="cars">
<div class="car"></div>
<div class="car"></div>
<div class="car"></div>
</div>
jsFiddle
Left div - left corner straight, right corner slanted
Center div - left and right corner slanted
Right div - left corner slanted, right corner straight
I have used CSS's :after pseudo class to add another red box after the last, slanted one. However this one isn't slanted, thus 'filling in' the bit of the slant that you don't want:
.car:nth-child(3):after {
/* create the box */
content: "";
display: block;
/* make it fill the required space */
width: 80%; /* (this is only 80 because it was a bit large at 100) */
height: 100%;
background: #ff0000;
/* transform it in the opposite direction to counter the -10deg skew of .car */
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: -20%; /* counteract the 80% width */
}
I did the same with the first div, and :before:
.car:nth-child(3):before{
content: "";
display: block;
width: 70%;
height: 100%;
background: #3498db;
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: 40%;
}
.cars {
width: 100%;
height: 500px;
margin-left: 100px;
}
.car {
width: 33.33333333%;
height: 100%;
background: #3498db;
position: relative;
-webkit-transform: skewx(-10deg);
-moz-transform: skewx(-10deg);
-o-transform: skewx(-10deg);
-ms-transform: skewx(-10deg);
transform: skewx(-10deg);
transform-origin: top left;
float: left;
display: inline;
}
.car:nth-child(2) {
background: #000;
}
.car:nth-child(3) {
background: #ff0000;
}
.car:nth-child(3):after {
content: "";
display: block;
width: 70%;
height: 100%;
background: #ff0000;
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: -30%;
}
.car:nth-child(1):before {
content: "";
display: block;
width: 70%;
height: 100%;
background: #3498db;
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: 40%;
}
<div class="cars">
<div class="car first"></div>
<div class="car"></div>
<div class="car last"></div>
</div>
<br><br>

Proper positioning for z-index and opacity

I have nested link in two absolute div's like this:
<div class="container">
<div class="leftPostHolder">
<div class="leftPost">
<h3>link</h3>
</div>
</div>
</div>
First div(leftPostHolder) has black background, second one(leftPost) has red and when second div is hovered opacity of it is set to 0.5 and link background is set to white. Now I want that link to be above these two div's so that darken effect is not applied to it but just to second div with red background. Link with it's background should not be overlayed with that darken effect with opacity.
How to set link above those two elements? I tried with z-index and positioning that link but without success.
Full code is here: http://jsfiddle.net/v21t290a/
This is not a z-index issue.
Your a-tag is a child of leftPost which means it will inherit the opacity. Changing the Z-index will not change this.
The solution to your issue would be to either move the a-element so it's not a direct child of leftPost
or
Put the Opacity on an element that is not the parent of your link.
EXAMPLE:
$(".leftPost").hover(function() {
$(".leftPost a").toggleClass("aHover");
});
.container {
-webkit-transform: rotate(2deg);
-moz-transform: rotate(2deg);
-o-transform: rotate(2deg);
-ms-transform: rotate(2deg);
transform: rotate(2deg);
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
-ms-transform-origin: left center;
transform-origin: left center;
}
.leftPostHolder {
background-color: #000;
position: absolute;
width: 30%;
height: 100px;
overflow: hidden;
-webkit-backface-visibility: hidden;
}
.leftPost {
width: 100%;
position: absolute;
background-position: center;
background-size: cover;
height: 100%;
-webkit-transition-duration: .2s;
transition-duration: .2s;
display: table;
z-index: 2;
}
.leftPost:hover{
transform: scale(1.05);
-ms-transform: scale(1.05);
-mos-transform: scale(1.05);
-webkit-transform: scale(1.05);
transform-origin: top center;
-ms-transform-origin: center;
-mos-transform-origin: center;
-webkit-transform-origin: center;
}
.opacityDiv {
width: 100%;
position: absolute;
background-position: center;
background-size: cover;
height: 100%;
-webkit-transition-duration: .2s;
transition-duration: .2s;
display: table;
z-index: 1;
}
.leftPost:hover + .opacityDiv {
opacity: 0.5;
}
.leftPost h3 {
height: 100%;
display: table-cell;
vertical-align: middle;
}
.leftPost a{
color: transparent;
text-align: center;
padding:10px;
display:block;
}
.aHover {
color: #454545!important;
transform: rotate(-2deg);
background-color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="container">
<div class="leftPostHolder">
<div class="leftPost">
<h3>link</h3>
</div>
<div class="opacityDiv"></div>
</div>
</div>

multiline text but fully heighty applied in transform rotate

demo
Demo html
<div class="controller">
<div>Special Offer</div>
</div>
Demo css
.controller{
width: 55px;
height: 216px;
background: #000;
border-radius: 0 19px 19px 0;
text-align: center;
vertical-align: middle;
display: table-cell;
}
.controller div{
transform: rotate(90deg);
}
I could use white-space: nowrap; to .controller div it will increase the width of that controller and if I have long text this will have in one line. But I want this multiline but fully heighty as this.
Ok,what about THIS
.controller{
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
width: 55px ! important;
height: 215px;
background: #000;
border-radius: 0 19px 19px 0;
text-align: center;
vertical-align: middle;
display: block;
float:left;
position:relative;
margin-right: 10px;
}
.controller div{
position: relative;
top: 90px;
left: -70px;
width: 190px;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}