공부/HTML

[HTML5/CSS] FLOAT CLEAR 실습1

JangGiraffe 2015. 1. 15. 19:06

 

 

 

 

 

 

HTML 태그 내용

<html>
 <head>
  <title> float,clear test</title>
  <link type="text/css" rel="stylesheet" href="stylesheet.css">
 </head>
 <body>
  <div id="container">
       <div id="header">header</div>
       <div id="content">content</div>
       <div id="sideinfo">sideinfo</div>
       <div id="footer">footer</div>
  </div>
 </body>
</html>

CSS내용

#container { background-color:black; width:960px; margin:0 auto; padding: 10px;}
#header{ background-color: red; height: 100px;}
#content{ background-color: blue;float: left; width: 660px; height: 400px;}
#sideinfo{ background-color: green; float: left; width: 300px; height: 400px;}
#footer{ background-color: gray; clear:both; height: 100px;}
#div{font-size:72px; color:white;}

 

 공부를 하면서 안 내용

1. div는 너비가 작던 크던 한줄을 다 차지하는 특성이 있는데,(display속성이 block인것)
이때문에 여러개의 div를 만들면 div들이 붙지않고 한줄 한줄 표시된다.

 

[위의 스타일시트에서 float와 clear부분을 주석처리하면 div의 특성상 한줄 한줄 표시된다]

 

2. float는 left와 right의 속성을 줄 수 있는데 이속성은 block을 그 방향으로 차례대로 붙혀주는 기능이다.

[content와 sideinfo에 float:left속성을 줘서 둘이 차례대로 한 라인에 표시하게 할 수 있다]

 

 

3. clear는 float속성을 초기화하고 싶을 때 쓰는 기능이다. left,right,both 세가지 속성을 가지고있다.

각각의 속성을 초기화시켜주는건데 float를 이용해서 한 라인에 표시하다 밑에줄에 표시하고 싶을 때 이 기능을 쓴다.

[ex :content와 sideinfo는 2번째 라인에 표시하고 footer는 3번째 라인에 표시하고 싶을 때 footer에 clear 속성을 부여해준다]

반응형