css float 속성 문제 질문

css float 속성 문제 질문

작성일 2022.05.03댓글 1건
    게시물 수정 , 삭제는 로그인 필요







질문)
float 속성을 쓰면 붕 뜨는 효과가 생겨, 그 뒤로 오는 (float 속성을 안쓴) 태그들이 붕 떠있는 공간에 가서 자리를 채우는걸로 알고 있습니다.

현재 side와 header태그에 float 속성을 준 상태입니다.
뒤따라오는 content와 footer가 붕 떠있는 side의 부분과는 겹쳐있지만 왜 header 부분에는 겹치지 않는지 궁금합니다. 

header도 float 속성을 주었기 때문에 원래대로라면 
side와 header 둘 다에 가려져 content와 footer가 화면에 안보이게 되는게 맞지 않나요?


쉽고 자세한 설명 부탁드립니다~


코드 첨부하겠습니다.


  <style>
    body {background: #d1c4e9;}
    #wrap {width: 1000px; height: 900px; margin: 0 auto; font-size: 40px; color: #fff; text-align: center; text-transform: uppercase;}
    #side {float: left; width: 300px; height: 900px; line-height: 900px; background-color: #4527a0;}
    #header {float: left; width: 700px; height: 300px; line-height: 300px; background-color: #512da8;}
    #content {width: 700px; height: 300px; line-height: 300px; background-color: #5e35b1;}
    #footer {width: 700px; height: 300px; line-height: 300px; background-color: #673ab7}
  </style>
</head>
<body>
  <div id="wrap">
    <div id="side">side</div>
    <div id="header">header</div>
    <div id="content">content</div>
    <div id="footer">footer</div>
  </div>
</body>
</html>




#css float #css float 속성 #css float 가운데 정렬 #css float left #css float 해제 #css float clear #css floating #css float center #css floating button #css float bottom

profile_image 익명 작성일 -

1. 먼저 기존 코드가 header 와 겹쳐 있는지 확인해보기 위해 투명도와 배경색만 조금 손보고 확인해보면

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>css</title> <style> body {background: #d1c4e9;} #wrap {width: 1000px; height: 900px; margin: 0 auto; font-size: 40px; color: #fff; text-align: center; text-transform: uppercase;} #side {float: left; width: 300px; height: 900px; line-height: 900px; background-color: #4527a0; opacity: 0.5;} #header {float: left; width: 700px; height: 300px; line-height: 300px; background-color: #512da8; opacity: 0.5;} #content {width: 700px; height: 300px; line-height: 300px; background-color: /*#5e35b1*/red;} #footer {width: 700px; height: 300px; line-height: 300px; background-color: #673ab7;} </style> </head> <body> <div id="wrap"> <div id="side">side</div> <div id="header">header</div> <div id="content">content</div> <div id="footer">footer</div> </div> </body> </html>

#content 는 예상하시는 위치에 가 있는게, header 부분에 겹쳐 있는것이 맞습니다.

다만 float 속성을 지정한 side, header 엘리먼트에

content, footer 엘리먼트의 텍스트가 밀려 표기되고 있어 header 부분에 겹치지 않은것 처럼 보인 것입니다.

2. 겹쳐지는 대로 올바르게 표현하려면 position 속성을 이용하면 됩니다.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>css</title> <style> body {background: #d1c4e9;} #wrap { width: 1000px; height: 900px; margin: 0 auto; font-size: 40px; color: #fff; text-align: center; text-transform: uppercase; position: relative; } #side { width: 300px; height: 900px; line-height: 900px; background-color: #4527a0; opacity: 0.5; position: absolute; } #header { width: 700px; height: 300px; line-height: 300px; background-color: #512da8; opacity: 0.5; position: absolute; left: 300px; } #content {width: 700px; height: 300px; line-height: 300px; background-color: /*#5e35b1*/red;} #footer {width: 700px; height: 300px; line-height: 300px; background-color: #673ab7;} </style> </head> <body> <div id="wrap"> <div id="side">side</div> <div id="header">header</div> <div id="content">content</div> <div id="footer">footer</div> </div> </body> </html>

3. 아마도 예상하시는 내용일것 같은데 side 와 header 사이에 자연스럽게 끼우려면 display: inline-block; 속성을 지정하면 됩니다.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>css</title> <style> body {background: #d1c4e9;} #wrap {width: 1000px; height: 900px; margin: 0 auto; font-size: 40px; color: #fff; text-align: center; text-transform: uppercase;} #side {float: left; width: 300px; height: 900px; line-height: 900px; background-color: #4527a0; opacity: 0.5;} #header {float: left; width: 700px; height: 300px; line-height: 300px; background-color: #512da8; opacity: 0.5;} #header::after { content: ''; display: block; clear: left; } #content {width: 700px; height: 300px; line-height: 300px; background-color: /*#5e35b1*/red; display: inline-block;} #footer {width: 700px; height: 300px; line-height: 300px; background-color: #673ab7; display: inline-block;} </style> </head> <body> <div id="wrap"> <div id="side">side</div> <div id="header">header</div> <div id="content">content</div> <div id="footer">footer</div> </div> </body> </html>

css float 속성 문제 질문

질문) float 속성을 쓰면 붕 뜨는 효과가 생겨, 그 뒤로 오는... 확인해보면 css body {background: #d1c4e9;} #wrap {width: 1000px; height...

CSS float 질문

1 2 3 4 5 6 위와같은 html을 CSSfloat를 이용해 아래와 같이... ㅜㅜ 1 3 2 6 4 5 float:left 속성은 바로 앞의 박스에 가로로 붙는 성질이 있어서...

CSS float 관련 속성에 대한 질문

... float:left; } #main_gnb > ul.left > li { float: left; } #main_gnb a { display: block;... font-weight: bold; } 스타일 속성을 이렇게 지정했는데 밑에...

css float left,right 적용된 div...

css float left,right 적용된 div 중앙정렬질문 display inline block 쓰는거말고 div... float css 속성이 들어간 div 2개를 감싸는 외부 container div를 만드셔서...

html5 / css3 에서 float와 overflow...

저는 css시작한지 얼마되지않은 왕초보입니다 두가지 질문을 가지고 도움을 요청드립니다 ㅠ div { color: white } .d1 { float: left; margin-right: 7px; padding: 18px; background...

div의 float속성 사용과 css파일에...

... 첫번째 div 두번째 div 이때 속성css파일내 스타일 시트로 지정을 한 후 배열을 하면 줄이 바뀌어 배열되는데요.. 첫번째 div 두번째 div 왜그런지 알수 있을까요??????...

CSS float 과 Clear 에 대해서

... 저 CSS를 써야만 background-color 가 깔아집니다.... 싶어서 질문 합니다. float 의 고질적인 문제입니... 이플롯 속성을 그냥두면 height영역을 1로...