How to make the height REALLY 100%

后端 未结 6 2032
一生所求
一生所求 2021-01-15 03:29

in CSS when you set something\'s width or height to 100% it really only sets it to 100% of the browser window. Is there any way to make it 100% of the whole page?

Le

相关标签:
6条回答
  • 2021-01-15 03:37

    When you set the width or height to 100%, it's 100% of the size of it's parent element. So, what you need is an element around all the content of the page, and set the size of a child in that element.

    Edit:
    If you set the height of the outermost element in the body to 100%, what happens depends on the markup version you are using. In HTML the parent of the body element is the viewport and the height is 100% by default, so your element will be the size of the window. In XHTML the parent of the body element is the html element, and the height of the body element is the height of the actual content in the page.

    0 讨论(0)
  • 2021-01-15 03:38

    I will complete everyones answer....You need to make a style for the body and apply a margin:0; padding:0;

    like this:

    body{
     margin:0;
     padding:0;
    }
    

    after this you can apply a width:100% and a height:100% to every DIV you like.

    good luck

    0 讨论(0)
  • 2021-01-15 03:40

    100% width will be the width of the browser window if the element is not sized absolutely (e.g. 600px) or contained within another sized element.

    The height of the page is determined by how much space the content takes up vertically.

    So if you want something to cover a certain amount of space, create an element (i.e. a <div>) that has width and height set in pixels or ems, then the elements inside of it set to 100% will fill to that.

    0 讨论(0)
  • 2021-01-15 03:54

    Simply apply position:fixed to the element. If this is an overlay:

    #overlay 
    {
        position: fixed;
        top: 0;
        left: 0;
        width:100%;
        height:100%; 
    }
    

    Note: fixed is not supported by IE6

    0 讨论(0)
  • 2021-01-15 03:59

    If it's an overlay, you can consider the following CSS snippet:

    #overlay 
    {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }
    

    This presumes that there are other elements on the page to define it's dimensions

    0 讨论(0)
  • 2021-01-15 04:01

    It depends, if you put some element inside a div and table/div's and div's height is let's suppose 500px then the element within it with height 100% will be as much as this div.

    If you want make some element fit the whole page, you will have to put it under an element having the actual 100% with of the browser eg this is usually main containing table or parent div.

    EDIT:

    I have not tried below, but you can also do it this way using absolute positioning:

    <style type="text/css">
    div
    {
      position:absolute;
      top:0px;
      left:0px;
      width:100%;
      height:100%;
    }
    </style>
    

    But this approach is not always that ideal. If you are sure, you can implement that :)

    0 讨论(0)
提交回复
热议问题