2. CSS

CSS 특정 영역을 지정해서 변경하기

도피디 2024. 11. 29. 20:45
반응형
<!DOCTYPE html>
<html lang="kr">
<head>
<title>The Nick Times</title>
<style>
body {
height: 1000vh;
margin: 50px;
}
span {
color: tomato;
}
</style>
</head>
<body>
<div>
<span>hello</span>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod commodi e
sequi ipsam odio dolorem. <span>inside</span>
</p>
</div>
</body>
</html>

 

 

결과

 


 

여기서 <p> 안에 있는 span을 바꾸려면 어떻게 해야 할까? 

<!DOCTYPE html>
<html lang="kr">
<head>
<title>The Nick Times</title>
<style>
body {
height: 1000vh;
margin: 50px;
}
span {
color: tomato;
}
p span {
color: teal;
}
</style>
</head>
<body>
<div>
<span>hello</span>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod commodi e
sequi ipsam odio dolorem. <span>inside</span>
</p>
</div>
</body>
</html>

 

p span {

color: teal;

=>  부모인 p를 쓴 다음에 자식인 span 을 쓰면 : p 안에 있는 span 을 가리키게됨. 

 

 

 

결과

 

반응형