<!DOCTYPE html>
<html>
<head>
<title>line</title>
<meta charset="UTF-8">
<style>
.square{
height:200px;
width:200px;
background: coral;
margin: 20px auto;
position: relative;
}
</style></head>
<body>
<div class="container">
<div class="square">
</div>
</div></body>
</html>
- たとえばこの正方形の右側に赤い線を引いてみる。
<style>
.square{
height:200px;
width:200px;
background: coral;
margin: 20px auto;
position: relative;
}
.square:before{
content: "";
width:3px;
border-right: 3px solid red;
position: absolute;
right: -10px;
top: 0;
bottom: 0;
}
</style>
- 赤字の部分が肝です。top: 0; bottom: 0; とすると、疑似要素が直線に変身します。片方だけだとうまくいきません。
- dl, dt, dd と組み合わせるとおしゃれな表組みができそうです。