- 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」の左上の角にそろっている。
- 同様に「after:」
- その結果下のように見えます。
- ここから、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>
- 色を合わせればできあがり。