Non Gradient solution to avoid Jagged lines (Fiddle)
I was looking for something exactly like @Serg Hospodarets answer but I realized that gradient is creating a jagged line, probably a rendering issue of browser. So after some searching and fiddling I made this.
Summary:
I using a spacer technique answered here by Johan Rönnblom to calculate width relative to height by 1:1 ratio, then I am adding 2 boxes at the edge of div which have 50% of parent element height and width equal to that 50% creating perfect squares, then I am rotating sub element at 45deg creating the diagonal cuts.
Below is the complete code:
HTML
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro, esse assumenda corporis nemo perspiciatis dolorem vero consectetur asperiores necessitatibus, ea, saepe fugit alias, voluptatum blanditiis quia! Consequatur dolorem, consectetur adipisci.
<div class="u-prop">
<div class="wrap">
<img class="spacer" width="2048" height="2048" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
<div class="proportional"></div>
</div>
</div>
<div class="u-prop is--bot">
<div class="wrap">
<img class="spacer" width="2048" height="2048" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
<div class="proportional"></div>
</div>
</div>
</div>
SCSS:
body {
padding: 10px;
}
* {
box-sizing: border-box;
}
.box {
padding: 10px;
width: 500px;
position: relative;
background: #eee;
&:before {
content: '';
display: block;
width: 100%;
height: 100%;
border: 1px solid #000;
position: absolute;
top: 0;
left: 0;
box-sizing: border-box;
border-right: solid -0px transparent;
}
}
.u-prop {
position: absolute;
height: 50%;
width: 100%;
top: 0;
left: 100%;
&.is--bot {
top: 50%;
.proportional {
transform: rotate(-45deg);
transform-origin: bottom left;
&:before {
border-bottom: 1px solid #000;
border-top: none;
}
}
}
.spacer {
width: auto;
max-height: 100%;
visibility: hidden;
}
.proportional {
position: absolute;
top: 0;
left: 0px;
width: 150%;
height: 0;
padding-bottom: 100%;
background: #eee;
transform: rotate(45deg);
transform-origin: top left;
&:before {
content: '';
display: block;
width: 100%;
height: 100%;
border-top: 1px solid #000;
position: absolute;
top: 0;
left: 0;
box-sizing: border-box;
}
}
.wrap {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: auto;
max-width: 100%;
overflow: hidden;
}
}