console
<div class="container">
上边是斜的
</div>
@function get-tilted-height($angle) {
$a: (100% / 1%);
$A: (90deg - $angle);
$c: ($a / sin($A));
$b: sqrt(pow($c, 2) - pow($a, 2));
@return (abs($b) * 1%);
}
@mixin tilted($angle, $color, $position: 'top', $pseudo: 'before') {
$height: get-tilted-height($angle);
position: relative;
background-color: $color;
&::#{$pseudo} {
content: '';
padding-top: $height;
position: absolute;
left: 0;
right: 0;
@if ($position == 'top') {
bottom: 100%;
background-image: linear-gradient($angle, $color 50%, transparent 50%);
} @else {
top: 100%;
background-image: linear-gradient($angle, transparent 50%, $color 50%);
}
}
}
*, ::before, ::after {
box-sizing: inherit;
}
body {
background-color: rgb(223, 231, 238);
}
.container {
@include tilted(3deg, rgb(255, 255, 255));
padding: 0 1em;
width:80%;
margin: 100px auto;
filter: drop-shadow(0 1em 1em rgba(0, 0, 0, 0.1));
}