::before
疑似要素の使用に問題があります。私のペンでは、::before
と::after
セレクタを使用して、divsの傾斜エッジを与えています。最初のdivでは、これは正常に動作するようです。しかし、2番目のdivでは、傾斜はdivの幅の50%だけ伸びています。ここに私のコードだ:my :: before擬似要素が機能しないのはなぜですか?
.services {
text-align: center;
background: linear-gradient(to right, #F1F2B5 , #135058);
height: 250px;
width: 100%;
position: relative;
}
.services::before {
content: "";
background: linear-gradient(to right, #F1F2B5 , #135058);
width: 100%;
height: 200px;
transform: skewY(-5deg);
position: absolute;
top: -100px;
z-index: -1;
}
.flex {
display: flex;
width: 100%;
border: 1px solid red;
}
.box-alt {
width: 100px;
height: 100px;
background-color: blue;
border: 3px solid grey;
transform: rotate(45deg);
}
<div class="services">
<h2>Services</h2>
<hr />
<div class="flex">
<div class="box-alt">hi</div>
<div class="box-alt">hi</div>
<div class="box-alt">hi</div>
</div>
</div>
また、ここで私のペンへのリンクです:http://codepen.io/Hudson_Taylor11/pen/XpBMwM?editors=0100
':: before'は擬似クラスではなく、擬似**要素**です。ちょうどスティーン ' –