0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CSSのborderプロパティ使いこなし術!基本からおしゃれな応用例まで

Posted at

はじめに

CSSのborderプロパティは、要素の枠線を簡単に装飾できる便利なプロパティです。
デザインにちょっとしたアクセントを加えたいときや、要素を視覚的に区切りたいときによく使われます。
この記事では、borderプロパティの基本から、ちょっとおしゃれな使い方、さらに応用例まで解説します。

使いどころ

  • ボタンやカードの枠線
  • セクションの区切り
  • 入力フォームの強調
  • テーブルの見やすさ向上
style.css
button {
  border: 2px solid #3498db;
  padding: 8px 16px;
  background: white;
  color: #3498db;
  border-radius: 4px;
}
index.html
<button>シンプルなボタン</button>

image.png

borderはシンプルですが、ユーザーの目線誘導やアクセント作りに役立ちます。

おしゃれな使い方

1. 枠線の色をグラデーションに

グラデーションをborderに直接指定することはできませんが、border-imageを使えば実現可能です。

style.css
.box {
  border: 4px solid;
  border-image: linear-gradient(90deg, #f093fb, #f5576c) 1;
  padding: 16px;
  background-color: white;
}
index.html
<button class="box">グラデーションボタン</button>

image.png

2. 片側だけ違う色に

style.css
.card {
  border-left: 5px solid #ffb347;
  border-top: 1px solid #e0dfdf;
  border-right: 1px solid #e0dfdf;
  border-bottom: 1px solid #e0dfdf;
  padding: 16px;
  width: 50%;
}
index.html
<div class="card">
  <h3>カードタイトル</h3>
  <p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
</div>

image.png

左だけ色を変えることで、カード型のデザインを強調できます。

3. 点線や二重線

style.css
.dotted-box {
  border: 2px dotted #2ecc71;
  padding: 12px;
  width: 25%;
}

.double-box {
  border: 4px double #e17055;
  padding: 12px;
  width: 25%;
  margin-top: 20px;
}
index.html
<div class="dotted-box">
  <h3>カードタイトル</h3>
  <p>テキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
</div>
<div class="double-box">
  <h3>カードタイトル</h3>
  <p>テキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
</div>

image.png

デザインに変化を持たせるときに便利です。

応用的な使い方

擬似要素と組み合わせて枠線風装飾

style.css
.fancy-border {
  position: relative;
  padding: 16px 24px;
  border: 2px solid #F3704B;
  width: 50%;
}
.fancy-border::before {
  content: "";
  position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border: 2px dashed #fdcb6e;
  pointer-events: none;
}
index.html
<div class="fancy-border">
  <h3>カードタイトル</h3>
  <p>テキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
</div>

image.png

疑似要素を使うことで、二重の枠線や装飾も表現できます。

最後に

borderプロパティは、基本的なプロパティながらも工夫次第で様々なデザインに応用できます。
「ちょっとデザインを変えたいな」と思ったとき、ぜひ活用してみてください!

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?