要素に両方のクラスがある場合にのみ適用される CSS ルール [重複] 質問する

要素に両方のクラスがある場合にのみ適用される CSS ルール [重複] 質問する

次のようなマークアップがあるとします。

<div class="abc"> ... </div>
<div class="xyz"> ... </div>
<div class="abc xyz" style="width: 100px"> ... </div>

とクラス<div>の両方(最後のもの)を持つのみを選択し、そのインライン幅をオーバーライドして有効幅を 200 ピクセルにする方法はありますか?abcxyz

このようなもの:

[selector] {
  width: 200px !important;
}

ベストアンサー1

div.abc.xyz {
    /* declarations go here */
}

...または単に:

.abc.xyz {
    /* declarations go here */
}

おすすめ記事