LoginSignup
0
2

More than 3 years have passed since last update.

【備忘録:HTML/CSS】cssのストック集って持ってたほうがいいよね?-左右にボーダー編-

Posted at

よくある左右にボーダーつくやつ

スクリーンショット 2020-06-02 10.16.19.png
上記のようによく左右にボーダーがつく見出しやデザインがあります。

これまで、positionとbefore、afterで配置していたのですが、、、
flexを使用して簡単に、そしてテキスト増減を考慮した左右ボーダー見出しが作成できます!

index.html
<h2 class="m-heading2-border">左右にボーダー</h2>
style.scss
.m-heading2-border{
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  &:before{
    content: "";
    width: 100px;
    height: 1px;
    background: #000;
    margin-right: 10px;
  }
  &:after{
    content: "";
    width: 100px;
    height: 1px;
    background: #000;
    margin-left: 10px;
  }
}

見出し本体にflexをかけ、横、縦位置を中央にalign-items: center;、justify-content: center;をかけます。
そして見出しのbefore、afterでボーダーを表現します。
そ、それだけでできます。。
スクリーンショット 2020-06-02 10.21.32.png
こんな感じにテキストが多く入っても大丈夫ですし、
スクリーンショット 2020-06-02 10.22.12.png
こんな感じにテキストに改行が入ってもいけます!

これですと、cssも簡単ですし楽ですね!
みなさんぜひ使用してみてください。

参考元:
https://note.com/pulpstyle

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2