속성 선택자 (attribute selector)

김예희·2023년 7월 10일
0

[attr]

css에 "tag 이름[속성]" 을 넣으면 html의 특정 속성을 지정할 수 있다.

ex) [html]

<a href="http://example.com" target="_blink">link</a>

[css]

a[target] {color: hotpink;]}

-> a 태그 중 target 속성을 갖고있는 요소만 선택


[attr="value"]

attr의 값이 특정 value인 요소를 선택한다.

[css]

a[href="https://example.org] {color: indigo;}

*Input의 type은 여러가지 이므로 type 선택자를 쓸 때 구체적으로 value까지 적어준다.

input[type="submit"] {background-color: green;}

[attr^=value]

value로 시작하는 요소를 선택한다.

a[href^="https://"] {color:red;}

=> https만 지정되고 http는 지정이 안됨.


[attr$=value]

value로 끝나는 요소를 선택한다.

a[href$=".com"] {color: silver;}

=> .com으로 끝나는 value만 지정된다. 나머지 .org 등등은 지정이 안된다.


[attr*=value]

value를 적허도 하나 포함하는 요소를 지정한다.

a[href*="example"] {color:sienna;}

=> example이 포함되어 있는 value만 지정된다.

0개의 댓글