Making a div that covers the entire page

后端 未结 6 1658
执笔经年
执笔经年 2020-12-02 10:02

I would like to make a div that covers the entire page. I put a css style with height:100% but this covers only the viewable area. I want it to also cover the area when I

相关标签:
6条回答
  • 2020-12-02 10:14
     <style type="text/css">
     html, body {
        margin:0;
        padding:0;
        height:100%; 
     } 
     #test { 
        position:absolute; 
        display:block;
        background:#ccc; 
        height:100%; 
        width:100%;
     }
     </style>
    
    0 讨论(0)
  • 2020-12-02 10:18

    Following css will do the required job.

    .overlay {
      background: #fff;
      position: fixed;
      bottom: 0;
      right: 0;
      left: 0;
      top: 0;
    }
    

    Sometimes We want to cover page body with an overlay until all resources of web page are not downloaded completely. And they we fade out this overlay to show the complete content of our web page. Following example is a little modification of above answers, In this example we show an overlay covering full body of page with css3 animation:

    For more animations, visit Here

    $(window).load(function() {
        $('.overlay').delay(1000).fadeOut(800);
    });
    .overlay {
      background: #fff;
      position: fixed;
      bottom: 0;
      right: 0;
      left: 0;
      top: 0;
    }
    .loading {
      position: absolute;
      top: 50%;
      left: 50%;
    }
    .loading-bar {
      display: inline-block;
      width: 4px;
      height: 18px;
      border-radius: 4px;
      animation: loading 1s ease-in-out infinite;
    }
    .loading-bar:nth-child(1) {
      background-color: #3498db;
      animation-delay: 0;
    }
    .loading-bar:nth-child(2) {
      background-color: #c0392b;
      animation-delay: 0.09s;
    }
    .loading-bar:nth-child(3) {
      background-color: #f1c40f;
      animation-delay: .18s;
    }
    .loading-bar:nth-child(4) {
      background-color: #27ae60;
      animation-delay: .27s;
    }
    
    @keyframes loading {
      0% {
        transform: scale(1);
      }
      20% {
        transform: scale(1, 2.2);
      }
      40% {
        transform: scale(1);
      }
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <div class="overlay">
      <div class="loading">
        <div class="loading-bar"></div>
        <div class="loading-bar"></div>
        <div class="loading-bar"></div>
        <div class="loading-bar"></div>
      </div>
    </div>
    <p>Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, </p>
    <p>Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, </p>
    <p>Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, </p>

    0 讨论(0)
  • 2020-12-02 10:20

    Here is a great article on how to do just that...

    http://james.padolsey.com/javascript/get-document-height-cross-browser/

    0 讨论(0)
  • 2020-12-02 10:24

    Use position:fixed this way your div will remain over the whole viewable area continuously ..

    give your div a class overlay and create the following rule in your CSS

    .overlay{
        opacity:0.8;
        background-color:#ccc;
        position:fixed;
        width:100%;
        height:100%;
        top:0px;
        left:0px;
        z-index:1000;
    }
    

    Demo: http://www.jsfiddle.net/TtL7R/1/

    0 讨论(0)
  • 2020-12-02 10:29
    html, body { height: 100%; }
    #page { min-height: 100% }
    
    0 讨论(0)
  • 2020-12-02 10:34

    I'm not sure what you're doing with this div, but you can style the element as well.

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