Stack/CSS
[CSS] float 연습
7ingout
2022. 4. 8. 16:04
float clear 자세히 주말에 공부해보자
float: 요소가 왼쪽, 오른쪽으로 떠 있도록 지정
left / right
clear: 요소의 왼쪽 오른쪽에 부동 요소를 허용하지 않도록 지정
left / right / both
1) display
2) float
3) flexbox
4) gridbox
1. float.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
#container {
background: pink;
width: 1000px;
margin: 0 auto;
}
.item {
background: tomato;
width: 200px;
height: 200px;
border: 3px solid #333;
float:left;
}
/* #clear{
float: none;
clear: left;
} */
#container2 {
width: 1000px;
height: 400px;
background-color: blue;
}
#container p {
clear:left;
}
</style>
</head>
<body>
<!-- div>(div>{box$})*4 -->
<div id="container">
<div class="item">box1</div>
<div class="item">box2</div>
<div class="item">box3</div>
<div class="item" id="clear">box4</div>
</div>
<div id="container2">
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
<p>div입니다.</p>
</div>
</body>
</html>
2. float_header.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
#header {
width: 1000px;
background: pink;
margin: 0 auto;
}
h1{
float: left; /*뒤에 있던 ul이 위로 올라옴 */
}
ul {
float: right;
}
.clearboth{
clear: both; /* 보통 이거 만들어서 양쪽을 제거,, 이게 무슨 말이지 */
}
li{
float:left;
}
</style>
</head>
<body>
<div id="header">
<h1>Green</h1>
<ul>
<li><a href="#">menu1</a></li>
<li><a href="#">menu2</a></li>
<li><a href="#">menu3</a></li>
<li><a href="#">menu4</a></li>
</ul>
<p class="clearboth"></p>
</div>
</body>
</html>