2. CSS

CSS flex 태그: 자식 엘리먼트를 flex 컨테이너로 만들기

도피디 2024. 11. 19. 21:55
반응형

자식 엘리먼트에도 flex를 적용할 수 있다!

<!DOCTYPE html>
<html lang="kr">
<head>
<title>The Nick Times</title>
<style>
body {
height: 100vh;
margin: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
div {
display: flex;
justify-content: center;
align-items: center;
width: 300px;
font-size: 240px;
color: white;
height: 300px;
background-color: teal;
}
#second {
background-color: wheat;
}
</style>
</head>
<body>
<div>1</div>
<div id="second">2</div>
<div>3</div>
</body>
</html>

 

body: 부모 엘리먼트

(body 안에 있는) div: 자식 엘리먼트

 

 

 

 

결과

 

반응형

'2. CSS' 카테고리의 다른 글

CSS position fixed 사용하기  (0) 2024.11.24
CSS flex-wrap 사용하기  (0) 2024.11.19
CSS flex-direction 사용하기  (0) 2024.11.19
CSS flex box(플렉스 박스)의 특징2  (0) 2024.11.19
CSS flex box(플렉스 박스)의 특징1  (0) 2024.11.19