사이트 내 전체검색
검색목록
div :first-child and :last-child 처음 마지막 css 속성 처리
로빈아빠
https://cmd.kr/html/181 URL이 복사되었습니다.

본문

:first-child and :last-child

show page contents

How to select an element that is the first or last child of its parent.

The :first-child pseudo class means "if this element is the first child of its parent". :last-child means "if this element is the last child of its parent". Note that only element nodes (HTML tags) count, these pseudo-classes ignore text nodes.

Testsheet:

div#test p:first-child {text-decoration: underline;}
div#test p:last-child {color: red;}
This is the div id="test". The first paragraph should be underlined; the last red.

First paragraph.

Second paragraph.

Dynamic

What happens when we dynamically add paragraphs to the div? The browsers should re-evaluate the styles of all paragraphs.

Add paragraph at start or add paragraph at end of test div.

댓글목록

등록된 댓글이 없습니다.

Search

Copyright © Cmd 명령어 3.136.236.178