How do I unskew background image in skewed layer (CSS)? - css

I'm trying to display a profile photo like this / - / (the slashes represent slants using skewX, the hyphen represents a horizontally-aligned background image).
The problem is that this code also skews the background image:
.photo {
transform: skewX(35deg);
-ms-transform: skewX(35deg); /* IE 9 */
-webkit-transform: skewX(35deg); /* Safari and Chrome */
width: 100px;
height: 92px;
border-right: 1px solid black;
border-left: 1px solid black;
background-image: url('silhouette.png');
background-repeat: no-repeat;
background-position: top left;
}
...
<div class="photo"></div>
I've tried to reverse the background skew like this:
.photo {
transform: skewX(35deg);
-ms-transform: skewX(35deg); /* IE 9 */
-webkit-transform: skewX(35deg); /* Safari and Chrome */
width: 100px;
height: 92px;
border-right: 1px solid black;
border-left: 1px solid black;
}
.photo div {
transform: skewX(-35deg);
-ms-transform: skewX(-35deg); /* IE 9 */
-webkit-transform: skewX(-35deg); /* Safari and Chrome */
width: 100%;
height: 100%;
background-image: url('silhouette.png');
background-repeat: no-repeat;
background-position: top left;
}
...
<div class="photo"><div></div></div>
...but I get / [-] / (the background doesn't fit flush to the slants).
I've been at this all day, please can you help me? I've got coder's bock!

I'd rather use a pseudo element that's holding the background-image. The key to the solution is using transform-origin:
Example
.photo {
transform: skewX(35deg);
-ms-transform: skewX(35deg); /* IE 9 */
-webkit-transform: skewX(35deg); /* Safari and Chrome */
width: 100px;
height: 92px;
border-right: 1px solid black;
border-left: 1px solid black;
/* new styles */
position: relative;
overflow: hidden;
-webkit-transform-origin: top left;
-ms-transform-origin: top left;
transform-origin: top left;
}
.photo::before {
content: "";
transform: skewX(-35deg);
-ms-transform: skewX(-35deg); /* IE 9 */
-webkit-transform: skewX(-35deg); /* Safari and Chrome */
background-image: url('http://placekitten.com/200/200');
background-repeat: no-repeat;
background-position: top left;
/* new styles */
position: absolute;
-webkit-transform-origin: top left;
-ms-transform-origin: top left;
transform-origin: top left;
width: 1000%; /* something ridiculously big */
height: 1000%; /* something ridiculously big */
}

Related

Vertical line on the right of the image while using filter: blur()

I am building a story section for the site. Following is the scss code for a story:
.story{
width: 75%;
background-color: $color-white;
font-size: 1.6rem;
margin: 0 auto;
box-shadow: 0 3rem 6rem rgba(0,0,0,0.2);
border-radius: .1rem;
padding: 4rem;
padding-left: 5.5rem;
transform: skewX(-12deg);
&__shape{
height: 15rem;
width: 15rem;
float: left;
shape-outside: circle(50% at 50% 50%);
clip-path: circle(50% at 50% 50%);
transform: translateX(-1.5rem) skewX(12deg);
position: relative;
}
&__img{
height: 100%;
transform: translateX(-4rem) scale(1.4);
backface-visibility: hidden;
transition: all .5s;
}
&__text{
transform: skewX(12deg);
}
&__caption{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,20%);
font-size: 1.7rem;
text-transform: uppercase;
color: $color-white;
text-align: center;
opacity: 0;
transition: all .5s;
backface-visibility: hidden;
}
&:hover &__caption{
transform: translate(-50%,-50%);
opacity: 1;
}
&:hover &__img{
transform: translateX(-4rem) scale(1);
filter: blur(3px) brightness(80%);
}
}
When I hover a vertical line appears on the right of image and goes away when unhovered. Following are the images of problem.
Without hover:
With hover:
This problem only appears on chrome and not on Mozilla Firefox.
It is common filter: blur(); and clip-path problem. You shape is a circle, so there is a border-radius solution.
Try to add to the image parent element:
&__shape{
/* add */
border-radius: 100%; /* will do the same circle form = your clip-path */
overflow: hidden; /* will hide everything outside the form, including your line */
}
overflow: hidden; + border-radius: 100%; on the parent element will hide that bug.

circular animation with fixed back ground image css

I have a circular animation with back ground image in css :
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #4897D8; /* Blue */
border-radius: 50%;
width: 120px;
height: 120px;
position: fixed;
top: 50%;
left: 40%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
animation: spin 2s linear infinite;
background: url("../img/ExchangeHall.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
in this class the background image also rotating with the animation.
how can i fix the background image ? just the border rotate and the background image must be fix ?
Write two classes and split the styles into both. Put one div inside the another and apply the styles
.loader-background {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #4897D8; /* Blue */
border-radius: 50%;
width: 120px;
height: 120px;
position: fixed;
top: 50%;
left: 40%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
background: url("../img/ExchangeHall.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.loader-animation {
animation: spin 2s linear infinite;
}
<div class="loader-background">
<div class="loader-animation">
....
</div>
</div>

Transition with 3d rotation spins differently in Internet Explorer

I make an arrow, using two borders of a box and rotating the box. When clicking it, the arrow should point up instead of down, and use a transition.
In Chrome/Safari/Firefox this works corretly. In IE11 however, it rotates weirdly. It ends up in the correct orientation, but gets there differently/around other axis than in the other browsers.
button:after {
/* make a box with two borders */
content: "";
border-left: 1.5px solid blue;
border-top: 1.5px solid blue;
transition: all 1s;
width: 10px;
height: 10px;
display: inline-block;
margin-left: 0.5rem;
/* rotate to give illusion of arrows */
transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
transform-origin: 25% 25%;
-webkit-transform-origin: 25% 25%;
}
/* change direction of arrow */
button.open:after {
transform: rotateX(180deg) rotateZ(-135deg);
-webkit-transform: rotateX(180deg) rotateZ(-135deg);
}
Interactive example, click the button:
https://jsfiddle.net/b51sctnu/1/
In general, it's a good idea to keep the changes easy for the browser to understand
In your case, use 2 transforms that are the most similar posible.
Since the final step is
transform: rotateX(180deg) rotateZ(-135deg);
in the initial step use:
transform: rotateX(0deg) rotateZ(-135deg);
The 0deg rotation seems useless, but matches the final transform
Example, changing the new state to a hover to make easier to go back and forth
button:after {
content: "";
border-left: 1.5px solid blue;
border-top: 1.5px solid blue;
transition: all 1s;
width: 10px;
height: 10px;
display: inline-block;
margin-left: 0.5rem;
-webkit-transform-origin: 25% 25%;
-webkit-transform: rotate(-135deg);
transform-origin: 25% 25%;
transform: rotateX(0deg) rotateZ(-135deg);
}
button:hover:after {
-webkit-transform: rotateX(180deg) rotateZ(-135deg);
transform: rotateX(180deg) rotateZ(-135deg);
}
button {
border: 0px;
background: grey;
padding: 20px;
}
<button>asdasd</button>

how to route arrow from right to down css

I just want to route a arrow down.
My CSS:
.arrow-admin{
bottom: -130px;
right: -240px;
width: 0;
height: 0px;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left: 18px solid #666;
position:relative;
}
with css property transform. This property allows you to rotate, scale, move, skew, etc., elements.
.arrow-admin{
-ms-transform: rotate(90deg); /* IE 9 */
-webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */
-moz-transform: rotate(90deg); /* mozilla */
transform: rotate(90deg);
}

Rotating Image around y axis

I have an image which is divided into two equal parts. I am trying rotate the right part of the image in -180°(anti-clockwise) around y axis on hover.
Problem is some times(randomly) image gets rotated in 180°(clockwise) instead of -180°(anti-clockwise). what might be the reason behind this? I am using chrome.
css:-
.container {
position: relative;
margin-top : 10px;
width : 500px;
height: 330px;
-webkit-perspective: 1500px;
box-shadow: 3px 3px 13px #AAA;
}
.frontDiv {
padding: 20px;
width: 500px;
height: 330px;
}
.frontImg {
position: absolute;
border:1px solid;
height : 281px;
width : 225px;
overflow: hidden;
background-image: url('iday.jpg');
transition:all 1s ease-in-out;
-webkit-transition:all 1s ease-in-out;
backface-visibility : hidden;
-webkit-transform-origin:0% 0%;
}
.f1 {
top: 20px;
left:20px;
background-position: 0px 0px;
}
.f2 {
top: 20px;
left:245px;
background-position: -225px 0px;
}
.frontDiv:hover .f2
{
-webkit-transform : rotateY(-180deg);
}
html:-
<article class='container'>
<div class='frontDiv'>
<div class='frontImg f1'></div>
<div class='frontImg f2'></div>
</div>
</article>
fiddle
Some of the browsers are not supported rotate like,
Internet Explorer 9 (and earlier versions) and Opera does not support the rotateX or rotateY method.
else try
.frontDiv:hover .f2
{
transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg); /* IE 9 */
-webkit-transform: rotateY(-180deg); /* Safari and Chrome */
}

Resources