webかたつむり ウェブデザインを勉強中 ウェブ初心者のおぼえがき

webかたつむり

WEB制作会社のフォトグラファー

css chevron

  • shevronをcssで作ってみる。

<!DOCTYPE html>
<html>
<head>
<title>shevron</title>
<style>
.container{
width: 960px;
margin: 100px auto;
}
.chevron{
width: 100px;
height: 200px;
background: red;
}
.chevron:before{
display: block;
content:"";
width:0;
height:0;
border: 100px solid;
border-color: transparent blue transparent transparent ;
}

.chevron:after{
display: block;
content:"";
width: 0;
height: 0;
border: 100px solid;
border-color: transparent transparent transparent green;
}
*/
</style>
<meta charset="UTF-8">

</head>
<body>

<div class="container">
<div class="chevron">
</div>
</div>
</body>
</html>

 

  •  「:before」の三角形(透明部分があるから見えていないだけで、CSS的には正方形)は赤い長方形「.chevron」の左上の角にそろっている。

f:id:ohta-felica:20160917210128p:plain

  • 同様に「after:」

f:id:ohta-felica:20160917210213p:plain

  • その結果下のように見えます。

f:id:ohta-felica:20160917205746p:plain

 

  • ここから、positionでchevronを作っていきます。

<style>
.container{
width: 960px;
margin: 100px auto;
}
.chevron{
width: 100px;
height: 200px;
background: red;
position: relative;
}
.chevron:before{
display: block;
content:"";
width:0;
height:0;
border: 100px solid;
border-color: transparent transparent transparent blue ;
}

.chevron:after{
display: block;
content:"";
width: 0;
height: 0;
border: 100px solid;
border-color: transparent transparent transparent green;
position: absolute;
top: 0;
left: 100px;
}
</style>

 

f:id:ohta-felica:20160917210756p:plain

 

  • 色を合わせればできあがり。

f:id:ohta-felica:20160917210933p:plain