CSS - Centering a page - then making the page 100% height

后端 未结 6 2047
名媛妹妹
名媛妹妹 2021-02-06 08:31

I\'m trying to center a page and then make it 100% in height. I have a div called \"content\" as the parent element of all elements in the HTML page. What do I need

6条回答
  •  别跟我提以往
    2021-02-06 09:26

    Ahah! Think I got it for now. This works in Firefox 3 and IE7. I will test on some other browsers later. I do still need to figure out adding some padding around my content.

    This requires this heirarchy on my page

    html  
    |__body  
         |__div id=container  
             |__div id=content  
    
        html
        {
            height: 100%;
        }
    
        body
        {
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    
        #container
        {
            position: absolute;
            text-align: center; 
            background-color: #000;
            width: 100%;
            height: 100%;
            left: 0px;
            right: 0px;
            top: 0px;
            bottom: 0px;    
        } 
    
        #content
        {
            text-align: left;
            background-color: #fff;
            margin: 0px auto;
            width: 830px; /* padding thing I'm working on */
            height: 100%;
        }
    

提交回复
热议问题