2021/02/18

横線にテキストを乗せるデザインのcss







ボーダーで線をひいて、中の要素の位置をずらして、その線の上に乗せるかたちで実現してます。


See the Pen 横線にタイトルを載せるデザイン by takapen (@takapen) on CodePen.








title 1

title 2





.title-1 {
  margin: 40px 0 50px;
  width: 100%;
  border-bottom: 1px solid #333;
  position: relative;
  display: flex;
  justify-content: center;
}
.title-1 span {
  padding: 0 20px;
  font-size: 20px;
  font-weight: bold;
  background: #fff;
  position: absolute;
  vertical-align: center;
  top: -.8em;
}


.title-2 {
  margin: 40px auto 50px;
  width: 200px;
  border-bottom: 1px solid #333;
  position: relative;
  display: flex;
  justify-content: center;
}
.title-2 span {
  padding: 0 20px;
  font-size: 20px;
  font-weight: bold;
  background: #fff;
  position: absolute;
  vertical-align: center;
  top: -.8em;
}