LoginSignup
15

More than 5 years have passed since last update.

CSSで複数の属性セレクタを指定する

Last updated at Posted at 2015-10-16

CSSで属性セレクタを指定する。

属性が一つの場合

div[data-color="red"]{
    background-color: red;
}

属性が2つの場合

div[data-color="red"][data-size="small"]{
    background-color: red;
    font-size: 10px;
}

JSでも使える

var colorVal = 'red';
var sizeVal = 'small';

$('div[data-color="' + colorVal + '"][data-size="' + sizeVal + '"]').show();

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
15