Make a background image fill all the space when rotated - html

I have a div which has been rotated 45 degrees, this creates a diamond shape. Inside I have another div with a minus 45-degree rotation so the content is square I set the inner container to have 100% width & heightbut because of the rotation, it doesn't fill all the space.
I know the output I get is accurate to the code I've written because of the rotation it is 100%, so I suppose I need it larger than 100% and to scale as the browser scales.
.headerImg {
position: absolute;
top: -100px;
right: -100px;
width: 50%;
display: block;
background: #eee;
height: 95vh;
overflow: hidden;
transform: rotate(45deg);
}
.rotateBack {
width: 100%;
height: 100%;
transform: rotate(-45deg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="headerImg">
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
</div>
An example JSFiddle

HTML
<div class="part">
<div class="losange">
<div class="los1">
<img src="http://farm3.staticflickr.com/2178/3531465579_8bff044e9b_z.jpg?zz=1" alt="" width="255" height="320" />
</div>
</div>
CSS
.losange, .losange div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 250px;
height: 250px;
}
.losange {
transform: rotate(45deg) translateY(10px);
}
.losange .los1 {
width: 355px;
height: 355px;
transform: rotate(-45deg) translateY(-74px);
}
.losange .los1 img {
width: 100%;
height: auto;
}
I found this and have used for a project of mine. Hope it helps you, understand the main idea.

Since the container div has fixed size you can use absolute position with the image and make it overflow by specifing negative values on top/left/bottom/right;
.headerImg {
width: 50%;
margin: auto;
display: block;
background: #eee;
height: 95vh;
overflow: hidden;
transform: rotate(45deg);
position: relative;
}
.rotateBack {
position: absolute;
top: -30%;
left: -30%;
bottom: -30%;
right: -30%;
transform: rotate(-45deg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="headerImg">
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
</div>
By the way here is another way to achive what you want using clip-path:
body {
margin: 0;
}
.rotateBack {
height: 100vh;
width: 50%;
margin: auto;
clip-path: polygon(50% 0, 0 50%, 50% 100%, 100% 50%);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
Or using linear-gradient (but the background cannot be transparent):
body {
margin: 0;
}
.back {
height: 100vh;
width: 50%;
margin: auto;
background:
linear-gradient(45deg, #fff 25%, transparent 20%, transparent 75%, #fff 70%),
linear-gradient(-45deg, #fff 25%, transparent 20%, transparent 75%, #fff 20%),
url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg') center/cover no-repeat;
}
<div class="back">
</div>

Related

how can i make like this background with shadow?

I have a div which contains an image and overlay:
<div class="container">
<div class="overlay"></div>
<img src="tablet.png" alt="tablet">
</div>
How can I make an overlay with shadow like ?
While it surely can be done via CSS or SVG, most likely that shadow is just a background image where the shadow is already drawn.
However, here's an example of how you could think of it in css:
.scene {
position: relative;
width: 200px;
height: 200px;
background: #60c18b;
overflow: hidden;
}
.object {
position: absolute;
width: 40px;
height: 45px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-image: url(https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.onlinewebfonts.com%2Fsvg%2Fimg_121330.png&f=1);
background-repeat: no-repeat;
background-size: 100% 100%;
background-position: top left;
}
.object:after, .object:before {
content: '';
display: block;
width: 100%;
height: 100px;
background: linear-gradient(rgba(0,0,0,0.3), transparent);
transform: skew(-45deg, 0deg);
transform-origin: top left;
position: absolute;
}
.object:before {
transform: translateY(2px) skew(0deg, -45deg);
transform-origin: top right;
width: 100px;
height: 100%;
position: absolute;
right: 0;
background: linear-gradient(to left, rgba(0,0,0,0.3), transparent);
}
<div class="scene">
<div class="object"></div>
</div>
Note that this is just for fun, it's not perfect and I wouldn't use this on a production site.

how to created a curved background on top of image

I have this design
How can I make the blue curved background on top of the image (I need the transparency as well) ?
I started it with a different backgournd but I don't know where to go from there. Any help will be really appreciated.
.bg {
background-image:url("https://s8.postimg.cc/rsxes8dx1/red_or_blue_pill_crimson_quill-12.jpg");
max-width: 100%;
height: 200px;
background-size: cover;
background-position: center;
position: relative;
}
.bluebg {
background-color: blue;
position: absolute;
}
<div class="bg">
<div class="bluebg">
</div>
</div>
https://jsfiddle.net/0rsLxtw5/7/
I hope the below-given snippet helps!
.bg {
background-image: url("https://s8.postimg.cc/rsxes8dx1/red_or_blue_pill_crimson_quill-12.jpg");
height: 200px;
background-size: cover;
background-position: center;
overflow: hidden;
}
.bluebg {
background: rgba(135, 206, 235, 0.5);
height: 140%;
width: 90%;
-webkit-mask-image: radial-gradient(circle at right, transparent 0, transparent 30%, black 30px);
mask-image: radial-gradient(circle at right, transparent 0, transparent 30%, black 30px);
}
<div class="bg">
<div class="bluebg"></div>
</div>
I changed your HTML like the parent as child and child as parent.
.bg {
background-image: url("https://s8.postimg.cc/rsxes8dx1/red_or_blue_pill_crimson_quill-12.jpg");
max-width: 100%;
height: 200px;
background-size: cover;
background-position: center;
position: relative;
-webkit-clip-path: circle(50% at 98% 50%);
clip-path: circle(50% at 98% 50%);
}
.bluebg {
background-color: blue;
position: absolute;
height: 200px;
width: 100%;
}
<div class="bluebg">
<div class="bg">
</div>
</div>

curved div with transparent top

I'm trying to create transparent div full width and height around 500px using borders but i have trouble with creating this kind of curved shape.
It should look like on the example image, the yellow shape.
.transparent_bg {
width: 100%;
height: 485px;
background: transparent;
border:solid 5px #000;
border-color:#000 transparent transparent transparent;
border-radius: 50%/200px 200px 0 0;
transform: rotate(180deg);
position: relative;
overflow:hidden;
}
.transparent_bg:after {
content: "";
width: 100%;
height: 485px;
position: absolute;
top: 0;
background: red;
}
<div class="transparent_bg"></div>
I have included a link to my work until this moment but without success.
You can use clip path in both ways (on the top element or the bottom one) and simply make top and bottom to overlay like this :
.first,
.second {
display: inline-block;
margin: 5px;
}
.first .top {
clip-path: circle(72.9% at 50% 27%);
height: 200px;
width: 200px;
background: url(https://picsum.photos/id/10/800/800) center/cover;
position: relative;
}
.first .bottom {
margin-top: -70px;
background: yellow;
height: 100px;
width: 200px;
}
.second .top {
height: 200px;
width: 200px;
background:url(https://picsum.photos/id/10/800/800) center/cover;
position: relative;
}
.second .bottom {
clip-path: polygon(0 25%, 14% 41%, 28% 51%, 49% 54%, 66% 53%, 79% 48%, 89% 39%, 100% 27%, 100% 100%, 47% 100%, 0% 100%);
margin-top: -70px;
background: yellow;
height: 100px;
width: 200px;
}
<div class="first">
<div class="top">
</div>
<div class="bottom">
</div>
</div>
<div class="second">
<div class="top">
</div>
<div class="bottom">
</div>
</div>
Here is a useful link to generate path :
https://bennettfeely.com/clippy/
Here is another idea using radial-gradient
.first {
height: 200px;
width: 400px;
background:
radial-gradient(100% 100% at top, #0000 60%, yellow 61%),
url(https://picsum.photos/id/10/800/800) center/cover;
}
<div class="first">
</div>
Using mask if you want transparency:
.first {
height: 200px;
width: 400px;
background: url(https://picsum.photos/id/10/800/800) center/cover;
-webkit-mask:radial-gradient(100% 100% at top, #fff 60%, #0000 61%);
mask:radial-gradient(100% 100% at top, #fff 60%, #0000 61%);
}
.bottom {
-webkit-mask:radial-gradient(100% 100% at top, #0000 60%, #fff 61%);
mask:radial-gradient(100% 100% at top, #0000 60%, #fff 61%);
}
body {
background:yellow;
}
<div class="first">
</div>
<div class="first bottom">
</div>
If you want to overlay top and bottom, just use clip path both ways (on the top or bottom element).`
.transparent_bg {
width: 100%;
height: 485px;
background: transparent;
border-top-left-radius: 50% 50%;
border-top-right-radius: 50% 50%;
transform: rotate(180deg);
position: relative;
overflow:hidden;
}
.transparent_bg:after {
content: "";
width: 100%;
height: 485px;
position: absolute;
top: 0;
background: red;
}
.transparent_bg {
width: 100%;
height: 485px;
background: transparent;
border-top-left-radius: 50% 50%;
border-top-right-radius: 50% 50%;
transform: rotate(180deg);
position: relative;
overflow:hidden;
}
.transparent_bg:after {
content: "";
width: 100%;
height: 485px;
position: absolute;
top: 0;
background: red;
}
<div class="transparent_bg"></div>

'Cut' page on two sides

I want to 'cut' my page on two sides, something like this:
http://i.stack.imgur.com/ngZrp.jpg
DEMO: https://jsfiddle.net/r2g0eyxf/3/
#left {
background: url(https://static.pexels.com/photos/24353/pexels-photo.jpg);
width: 50%;
position: absolute;
left: 0px;
height: 100%;
}
#right {
background: url(http://media.caranddriver.com/images/media/51/25-cars-worth-waiting-for-lp-ferrari-488gtb-photo-658256-s-original.jpg);
width: 50%;
position: absolute;
right: 0px;
height: 100%;
}
But:
I need this images responsive
I want to create this 'slash'
How can I do this?
EDIT
This not solving my problem - I need it on full page and without space between images.
An hint would be to use transform and some padding.
average example
body {
margin: 0;
padding: 0;
width:100%;
overflow-x:hidden;
color:turquoise;
text-shadow:0 0 white;
font-size:2em;
}
#left {
position: absolute;
left: -10%;
height: 100%;
}
#left,
#right {
width: 60%;
transform: skew(-15deg);
overflow: hidden;
}
#left .content {
background: url(https://static.pexels.com/photos/24353/pexels-photo.jpg);
height: 100%;
}
#right .content {
height: 100%;
background: url(http://media.caranddriver.com/images/media/51/25-cars-worth-waiting-for-lp-ferrari-488gtb-photo-658256-s-original.jpg);
}
#right {
position: absolute;
right: -10%;
height: 100%;
}
#left .content,
#right .content{
width: 100%;
padding: 0 20%;
margin: 0 -15%;
transform: skew(15deg);
display: flex;
align-items: center;
justify-content: center;
background-size: cover;
}
<div id="left">
<div class="content">Content here</div>
</div>
<div id="right">
<div class="content">Content here</div>
</div>
You could use clip-path, support.
.clipped-img {
position: relative;
}
.clipped-img img {
position: absolute;
width: 50%;
}
.clipped-img img:nth-child(1) {
-webkit-clip-path: polygon( 0% 0, 100% 0, 80% 100%, 0 100% );
clip-path: polygon( 0% 0, 100% 0, 80% 100%, 0 100% );
}
.clipped-img img:nth-child(2) {
right: 10%;
-webkit-clip-path: polygon( 20% 0, 100% 0, 100% 100%, 0 100% );
clip-path: polygon( 20% 0, 100% 0, 100% 100%, 0 100% );
}
<div class="clipped-img">
<img src="http://placehold.it/500x300/FC0/">
<img src="http://placehold.it/500x300/CC0/">
</div>

How to get Different type triangle shapes in css?

Presently I am working on different types of triangle shapes by using border-bottom, border-top, border-left, border-right. Up to this I am getting OK with background color.
But I need to get this shapes by placing background images(without cutting any background images). I tried to do this by using border but no luck.
Example for this
You have 2 ways to get this effect:
The first one is supported only in WebKit, and you will need only one div.
The second one is supported in all modern browsers, but your HTML is less clean, and needs a helper div.
In the code below, test is the first example and test2 and inner2 the second example:
.test {
left: 0px;
top: 0px;
width: 400px;
height: 300px;
position: relative;
border: solid 1px black;
background-image: url(http://placekitten.com/440/330);
display: inline-block;
}
.test:after {
content: "";
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
background-image: url(http://placekitten.com/300/400);
background-size: cover;
-webkit-clip-path: polygon(0px 0px, 100% 100%, 0px 100%);
-moz-clip-path: polygon(0px 0px, 100% 100%, 0px 100%);
clip-path: polygon(0px 0px, 100% 100%, 0px 100%);
}
.test2 {
width: 400px;
height: 300px;
position: relative;
border: solid 1px black;
background-image: url(http://placekitten.com/440/330);
overflow: hidden;
display: inline-block;
}
.inner2 {
position: absolute;
width: 140%;
height: 100%;
left: 0px;
top: 0px;
-webkit-transform: rotate(37deg);
-webkit-transform-origin: top left;
transform: rotate(37deg);
transform-origin: top left;
overflow: hidden;
}
.inner2:after {
content: "";
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
background-image: url(http://placekitten.com/300/400);
background-size: cover;
-webkit-transform: rotate(-37deg);
-webkit-transform-origin: top left;
transform: rotate(-37deg);
transform-origin: top left;
}
<div class="test"></div>
<div class="test2"><div class="inner2"></div></div>
JSFiddle
The first example uses clipping to get the image cut in triangle shape (only the front image, the other remains rectangular).
The second example uses overflow hidden and a rotation to get the triangular shape. Then, you need the opposite rotation to get the image straight.
In the first example, you can do almost whatever shape you want. For instance,
-webkit-clip-path: polygon(0px 0px, 66% 33%, 33% 66%, 100% 100%, 0px 100%);
gives you this:
.test {
left: 0px;
top: 0px;
width: 400px;
height: 300px;
position: relative;
border: solid 1px black;
background-image: url(http://placekitten.com/440/330);
display: inline-block;
}
.test:after {
content: "";
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
background-image: url(http://placekitten.com/300/400);
background-size: cover;
-webkit-clip-path: polygon(0px 0px, 66% 33%, 33% 66%, 100% 100%, 0px 100%);
}
<div class="test"></div>
JSFiddle