CSS : 대상 선택기
예시
활성 HTML 앵커 강조 표시:
:target
{
border: 2px solid #D4D4D4;
background-color: #e5eecc;
}
정의 및 사용
# 뒤에 앵커 이름이 있는 URL은 문서 내의 특정 요소로 연결됩니다. 연결되는 요소는 대상 요소입니다.
:target
선택기를 사용하여 현재 활성 대상 요소의 스타일을 지정할 수 있습니다 .
버전: | CSS3 |
---|
브라우저 지원
표의 숫자는 선택기를 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Selector | |||||
---|---|---|---|---|---|
:target | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS 구문
:target {
css declarations;
}
더 많은 예
예시
탭 메뉴 만들기:
.tab div {
display: none;
}
.tab div:target {
display: block;
}
예시
모달 만들기(대화 상자):
/* The modal's background */
.modal {
display: none;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}
/* Display the modal when targeted */
.modal:target {
display: table;
position: absolute;
}
/* The modal box */
.modal-dialog {
display: table-cell;
vertical-align: middle;
}
/* The modal's content */
.modal-dialog .modal-content {
margin: auto;
background-color: #f3f3f3;
position: relative;
padding: 0;
outline: 0;
border: 1px #777 solid;
text-align: justify;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}