일반적으로 웹페이지의 레이아웃은 css의 display, float, position 등과 같은 속성을 사용해 구현하는데, 이러한 속성을 사용할 경우 레이아웃을 표현하는 것은 굉장히 복잡해 진다.
이러한 복잡한 레이아웃을 간단하게 구현할 수 있게 나온 것이 css3에 추가된 flexbox입니다. flexbox를 사용할 경우 요소의 크기와 순서를 유연하게 배치할 수 있다.
display: flex;
display: inline-flex;
flex-direction
flex-wrap
flec-flow
justify-content⭐⭐⭐
align-content
align-items
두 줄인 경우 align-items
align-content: space-between; → 반대축 끝에 items를 배치하고 간격 같게
align-content: center; → 반대축 중간에 items를 배치
확인
justify-content: center;
align-content: center;
order
flex-grow
flex-shrink
****flex 1 1 100px;**** ⭐
flex-basis
align-self
**flex: 1**
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>float</title>
<link rel="stylesheet" href="css/flex_ex3.css" />
</head>
<body>
<div id="wrap">
<div class="header">
<div class="nav">
<h1 class="logo"><a href="#">LOGO</a></h1>
<div class="gnb">
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">ADMIN</a></li>
<li><a href="#">SHOPMALL</a></li>
<li><a href="#">JOIN</a></li>
<li><a href="#">LOGIN</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="sections">
<div class="section sec1">SECTION1</div>
<div class="section sec2">SECTION2</div>
</div>
</div>
<div class="footer">
<div class="fcon">
주소
저작권
</div>
</div>
</div>
</body>
</html>
@import url(common/reset.css);
#wrap {
width: 100%;
height: auto;
border: 5px solid #000000;
box-sizing: border-box;
}
/* header시작 */
.header {
width: 100%;
height: auto;
/* border: 5px solid orange; */
box-sizing: border-box;
padding: 20px 0;
}
.header .nav {
max-width: 1200px;
height: auto;
margin: 0 auto;
box-sizing: border-box;
background-color: white;
display: flex;
justify-content: space-between;
}
.header .nav h1.logo {
width: 120px;
height: 60px;
/* border: 5px solid#c72c1b; */
box-sizing: border-box;
text-align: center;
line-height: 60px;
background-color: #333D79;
color: #FCF6F5;
}
.header .nav h1.logo a {
color: inherit;
/* 부모요소속성 상속 */
}
.header .nav .gnb {
width: 500px;
height: auto;
/* border: 5px solid white; */
}
.header .nav .gnb>ul {
display: flex;
justify-content: space-evenly;
}
.header .nav .gnb>ul>li {
width: 20%;
height: 60px;
/* border: 5px solid #c72c1b; */
box-sizing: border-box;
text-align: center;
line-height: 60px;
background-color: white;
/* 0.3초 동안 효과를 적용 */
transition: all 0.3s;
}
.header .nav .gnb>ul>li:hover {
background-color: #333D79;
font-size: 16px;
color: #FAEBEF;
/* 손모양 커서 */
cursor: pointer;
}
.header .nav .gnb>ul>li:hover a {
color: inherit;
}
.header .nav .gnb>ul>li a {
color: #222222;
}
/* container시작 */
.container {
/* clear:both; 성질을 없애준다.*/
width: 100%;
height: auto;
/* border: 5px solid #2BAE66; */
box-sizing: border-box;
/* background-color: #2BAE66; */
/* 위 좌/우 아래 */
padding: 30px 0 30px;
}
.container .sections{
width: 100%;
max-width: 1600px;
height: auto;
/* border: 5px solid black; */
box-sizing: border-box;
margin: 0 auto;
/* 위/아래 좌/우 */
padding: 20px 20px;
box-shadow: 2px 2px 8px #cccccc;
}
.container .sections .section{
/* !important 동일 스타일 설정이 우선 적용*/
border: 5px solid #333D79!important;
box-sizing: border-box;
font-size: 40px;
text-align: center;
}
.container .sections .section.sec1{
width: 100%;
height: 400px;
border: 5px solid #07553B;
box-sizing: border-box;
/* margin: 나하고 다른 컨텐츠와의 여백 */
/* 다른 컨텐츠 sec1을 기준으로 아래에 있음 */
margin-bottom: 20px;
line-height: 400px;
}
.container .sections .section.sec2{
width: 100%;
max-width: 1200px;
height: 300px;
margin: 0 auto;
line-height: 300px;
}
/* footer시작 */
.footer {
width: 100%;
height: auto;
/* border: 5px solid #0063B2; */
box-sizing: border-box;
background-color: white;
}
.footer .fcon{
width: 100%;
max-width: 1200px;
height: 200px;
margin: 0 auto;
box-sizing: border-box;
color: black;
font-size: 30px;
text-align: center;
line-height: 200px;
}