100% Stretch Content

I am trying to make a layout with header, content and footer. The footer should be at the bottom of the page (done). But my problem is how can I get 100% content between the header and footer. When my content is empty, I donโ€™t see it, but when I write some word in html in the content div, for example, โ€œhelloโ€, then the content will only be longer than the content in the content. You probably understand what I mean. Can someone explain what is wrong in my css code.

The title is red, green is the footer, cyan is the content, and blue is the container. The problem is that the content does not cover the container area.

t

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Praktika1</title> <link rel="stylesheet" href="style1.css" type="text/css" /> </head> <body> <div id="container"> <div id="header"> </div> <div id="content"> </div> <div id="footer"> </div> </div> </body> </html> 

CSS:

 @CHARSET "UTF-8"; *{padding:0; margin:0;} html,body{ height:100%; } #container{ width: 1024px; position:relative; background-color:#cce; margin: 0 auto; min-height:100%; } #header{ width: 1024px; height:100px; background-color: #CCC; } #content{ height:100%; width:1024px; background-color:yellow; } #footer{ width: 1024px; height: 100px; position:absolute; bottom:0; background-color: #ced; } 
+4
source share
4 answers

Lucky you. Yesterday I spent a lot of time figuring out a question like this.

http://andrew.x10.mx/rene/

html -

  <div id="container"> <div id="header"> <div id="header-content"> Hai der. I'm a header. </div> </div> <div id="content"> <h1>Content here</h1> <div id="footer"> <div id="footer-content"> I'm a footer lol </div> </div> </div> </div> 

css -

 html,body { height: 100%; margin: 0; padding: 0; text-align: center; } #header { background: #0f0; top: 0; left: 0; position: absolute; width: 100%; } #header-content { padding: 10px; } #container { background: #ff0; height:auto !important; height:100%; position:relative; width: 1024px; text-align: left; margin: 0 auto; min-height:100%; } #content { padding: 20px 10px; } #footer { background: #f00; bottom: 0; left: 0; position: absolute; width: 100%; text-align: center; } #footer-content { padding: 10px; } 
+2
source

It's hard to say without HTML, but I would try to add min-height from% 100 to #content

+1
source

One solution would be the following:

 #content{ background-color:yellow; position:absolute; top:100px; bottom:100px; width:100%; } 

You can use absolute positioning in all three parts of the page (title, content, footer):

Live demo: http://jsfiddle.net/bBEJ6/

+1
source

Your question is formulated very poorly, but from what I see, you want your content to fill 100% of your page, but you specified a specific width in the #content section using the width:1024px .

Try width:100% and make sure this solves your problem.

-1
source

Source: https://habr.com/ru/post/1336173/


All Articles