개발/CSS
[CSS] Pseudo Selector 정리
개발햄
2019. 9. 12. 22:35
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Selectors and Pseudo Selectors</title>
<style>
input[type="submit"]{
background-color: red;
}
input{
border: 1px solid yellow;
}
.box{
background-color: green;
display: block;
height: 100px;
border: 1px solid black;
}
/* 첫번째 자식*/
.box:first-child{
background-color: yellow;
}
/* n번째 자식*/
.box:nth-child(2n){
background-color: gold;
}
/* 마지막 자식*/
.box:last-child{
background-color: pink;
}
/* 형제 */
input + .box{
background-color: pink;
}
.box > .box{
/* 직계 */
background-color: yellowgreen;
width: 100px;
}
</style>
</head>
<body>
<div class="test">
<div class="box">1
<div class="box">1-1</div>
</div>
<div class="box">2</div>
<div class="box">3
<input type="text" >3-1
<input type="submit">3-2
</div>
<div class="box">4</div>
<div class="box">5</div>
<div class="box">6</div>
</div>
</div>
</body>
</html>