Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to center a div inside another div that covers all the page (not using flexbox)

I am trying to build a div that should cover all the visible page. Inside this div there should be another one placed in the center (horizontally and vertically). this is what I have done so far:

.spinner-box {
    background-color: #0F83E8;
    background-size: cover;
}

.spinner {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #0000cc;
    text-align: center;
}
<div class="spinner-box">
  <div class="spinner">
    my content
  </div>
</div>

The inner div is visible but I can’t the backgroud color of the outer one.
I know this question has been asked many times but i can’t find an example with a div covering all the page

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

body {
    margin: 0;
    padding: 0; 
}
.spinner-box {
    background-color: #0F83E8;
    background-size: cover;
    position: absolute;
    height: 100%;
    width:100%;
}

.spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #0000cc;
}
<div class="spinner-box">
      <div class="spinner">
        my content
      </div>
    </div>

You need to add some styles to .spinner-box:

.spinner-box {
    background-color: #0F83E8;
    background-size: cover;
    position: absolute;
    height: 100%;
    width:100%;
}

.spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #0000cc;
}
<div class="spinner-box">
      <div class="spinner">
        my content
      </div>
    </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading