Reputation: 358
i want to create html page like this
i have created this with svg here is my code
<body>
<div style="width: 100%; background-image: url('https://t4.ftcdn.net/jpg/01/25/20/05/360_F_125200542_AyamLpAFVwGqUx2ntcrQpLQE3pde3h23.jpg'); background-repeat: no-repeat; background-size: cover;">
<svg viewbox="0 0 20 13.4">
<defs>
<clipPath id="top">
<polygon points="0 0, 9.9 0, 9.9 5, 0 8" />
</clipPath>
<clipPath id="right">
<polygon points="9.9 0, 9.9 5, 20 8, 20 0" />
</clipPath>
</defs>
<image xlink:href="http://i.imgur.com/RECDV24.jpg" x="0" y="0" height="13.4" width="20" clip-path="url(#top)"/>
<image xlink:href="http://i.imgur.com/5NK0H1e.jpg" x="0" y="0" height="13.4" width="20" clip-path="url(#right)"/>
</svg>
</div>
</div>
</body>
how i convert this to only html and css without svg tag
Upvotes: 3
Views: 990
Reputation: 150
Have you tried using the css property clip-path
?
https://developer.mozilla.org/fr/docs/Web/CSS/clip-path
I have made an example using clip-path here.
CSS
html, body { min-height: 100vh; margin: 0; }
body { position: relative; }
.shape {
height: 100vh;
position: absolute;
}
.a {
background: red;
left: 0;
top: 0;
width: 50%;
clip-path: polygon(0 0, 100% 0, 100% 30%, 0 100%);
z-index: 50;
}
.b {
background: green;
right: 0;
top: 0;
width: 50%;
clip-path: polygon(0 0, 0 30%, 100% 100%, 100% 0);
z-index: 50;
}
.c {
background: blue;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 40;
}
.img-container {
height: 100%;
width: 100%;
}
.img-container > img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
HTML
<div class="shape a">
<div class="img-container">
<img src="https://picsum.photos/200/300" alt="">
</div>
</div>
<div class="shape b">
<div class="img-container">
<img src="https://picsum.photos/200/300" alt="">
</div>
</div>
<div class="shape c">
<div class="img-container">
<img src="https://picsum.photos/200/300" alt="">
</div>
</div>
Upvotes: 1
Reputation: 274374
clip-path:polygon()
can easily do it:
html {
height:100%;
background:url(https://picsum.photos/id/104/800/800) center/cover;
}
html::before,
html::after {
content:"";
position:absolute;
top:0;
bottom:0;
width:50%;
}
html::before {
left:0;
background:url(https://picsum.photos/id/1016/800/800) center/cover;
clip-path:polygon(0 0,100% 0,100% 50%,0 80%);
}
html::after {
right:0;
background:url(https://picsum.photos/id/1019/800/800) center/cover;
clip-path:polygon(0 0,100% 0,100% 80%,0 50%);
}
You can apply to any html element:
.box {
height: 200px;
width: 300px;
position: relative;
background: url(https://picsum.photos/id/104/800/800) center/cover;
}
.box::before,
.box::after {
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 50%;
}
.box::before {
left: 0;
background: url(https://picsum.photos/id/1016/800/800) center/cover;
clip-path: polygon(0 0, 100% 0, 100% 50%, 0 80%);
}
.box::after {
right: 0;
background: url(https://picsum.photos/id/1019/800/800) center/cover;
clip-path: polygon(0 0, 100% 0, 100% 80%, 0 50%);
}
<div class="box"></div>
With CSS variables to be able to easily adjust the images:
.box {
height: 200px;
width: 300px;
position: relative;
background: var(--img-1) center/cover;
}
.box::before,
.box::after {
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 50%;
}
.box::before {
left: 0;
background: var(--img-2) center/cover;
clip-path: polygon(0 0, 100% 0, 100% 50%, 0 80%);
}
.box::after {
right: 0;
background: var(--img-3) center/cover;
clip-path: polygon(0 0, 100% 0, 100% 80%, 0 50%);
}
<div class="box" style="
--img-1:url(https://picsum.photos/id/104/800/800);
--img-2:url(https://picsum.photos/id/1016/800/800);
--img-3:url(https://picsum.photos/id/1019/800/800);
"></div>
<div class="box" style="
--img-1:url(https://picsum.photos/id/100/800/800);
--img-2:url(https://picsum.photos/id/17/800/800);
--img-3:url(https://picsum.photos/id/1015/800/800);
"></div>
Upvotes: 6