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?

More than 1 year has passed since last update.

子要素への一括スタイリング

Last updated at Posted at 2023-11-19

CSSセレクタ 「.test > *」 は、クラス名が .test である要素の直下に存在する全ての子要素にスタイルを一括で適用します。

・.test クラスに直接子要素として配置されているものに対象が限定される
・.test クラスの直下にある p、div、span などの子要素全てにスタイルが適用される
・.test クラスの直下にある子要素のみが対象。ネストされた要素は影響を受けない

同じスタイルを複数の子要素に適用したい場合、このセレクタを使用することで冗長なコードを避けられます。


HTMLの例

index.html
<div class="test">
  <p>子要素1</p>
  <div>子要素2</div>
  <span>子要素3</span>
</div>

CSSの例

style.css
.test > * {
  border: 1px solid #333;
  margin: 5px;
  padding: 10px;
}
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?