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
>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>