Html 如何将整页彩色背景添加到加载动画的单个元素中?

Html 如何将整页彩色背景添加到加载动画的单个元素中?,html,css,Html,Css,我有一个html div,用于加载屏幕元素。我需要添加一个完整的页面背景色。换句话说,我需要旋转图像位于纯色整页背景之上 而且,我只能使用一个元素。以下是我到目前为止的情况: .animsition-loading { background-image: url('../images/logo-loading.png'); width: 100px; height: 111px; background-repeat: no-repeat; backgrou

我有一个html div,用于加载屏幕元素。我需要添加一个完整的页面背景色。换句话说,我需要旋转图像位于纯色整页背景之上

而且,我只能使用一个元素。以下是我到目前为止的情况:

.animsition-loading {
    background-image: url('../images/logo-loading.png');
    width: 100px;
    height: 111px;
    background-repeat: no-repeat;
    background-size: contain;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-top: -16px;
    margin-left: -16px;
    -webkit-animation: spin1 .5s infinite linear;
    -moz-animation: spin1 .5s infinite linear;
    -o-animation: spin1 .5s infinite linear;
    -ms-animation: spin1 .5s infinite linear;
    animation: spin1 .5s infinite linear;
}

@-webkit-keyframes spin1 {
    0% { -webkit-transform: rotate(0deg);}
    100% { -webkit-transform: rotate(360deg);}
}
@-moz-keyframes spin1 {
    0% { -moz-transform: rotate(0deg);}
    100% { -moz-transform: rotate(360deg);}
}
@-o-keyframes spin1 {
    0% { -o-transform: rotate(0deg);}
    100% { -o-transform: rotate(360deg);}
}
@-ms-keyframes spin1 {
    0% { -ms-transform: rotate(0deg);}
    100% { -ms-transform: rotate(360deg);}
}
@-keyframes spin1 {
    0% { transform: rotate(0deg);}
    100% { transform: rotate(360deg);}
} 

您可以使用psuedo元素。如果容器覆盖了整个视口,则绝对将psuedo after元素放置在中心,如下所示:

.animation-loading{
    position: fixed;
    width: 100vw;
    height: 100vh;
    background-color: YOUR_COLOUR;
}    

.animation-loading::after{
    content: "";
    display: block;
    background-image: url('../images/logo-loading.png');
    width: 100px;
    height: 111px;
    background-repeat: no-repeat;
    background-size: contain;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -16px;
    margin-left: -16px;
    -webkit-animation: spin1 .5s infinite linear;
    -moz-animation: spin1 .5s infinite linear;
    -o-animation: spin1 .5s infinite linear;
    -ms-animation: spin1 .5s infinite linear;
    animation: spin1 .5s infinite linear;
}

@-webkit-keyframes spin1 {
    0% { -webkit-transform: rotate(0deg);}
    100% { -webkit-transform: rotate(360deg);}
}
@-moz-keyframes spin1 {
    0% { -moz-transform: rotate(0deg);}
    100% { -moz-transform: rotate(360deg);}
}
@-o-keyframes spin1 {
    0% { -o-transform: rotate(0deg);}
    100% { -o-transform: rotate(360deg);}
}
@-ms-keyframes spin1 {
    0% { -ms-transform: rotate(0deg);}
    100% { -ms-transform: rotate(360deg);}
}
@-keyframes spin1 {
    0% { transform: rotate(0deg);}
    100% { transform: rotate(360deg);}
} 

您可以使用此HTML加载循环:

<div id='loading-bg' style='display:none; position:fixed; z-index:9999; top:0; right:0; bottom:0; left:0; background-color:rgba(0,0,0,0.4); width:100%; height:100%;'><div id='floatingCirclesG' style='position:fixed; top:50%; left:50%; margin-left:-64px; margin-top:-64px;'><div class='f_circleG' id='frotateG_01'></div><div class='f_circleG' id='frotateG_02'></div><div class='f_circleG' id='frotateG_03'></div><div class='f_circleG' id='frotateG_04'></div><div class='f_circleG' id='frotateG_05'></div><div class='f_circleG' id='frotateG_06'></div><div class='f_circleG' id='frotateG_07'></div><div class='f_circleG' id='frotateG_08'></div></div></div>

…你完了!在这里拉小提琴:

不幸的是,没有。该示例将加载元素包装在一个div周围。包装器div是应用背景色的元素。
#floatingCirclesG{
position:relative;
width:128px;
height:128px;
-moz-transform:scale(0.6);
-webkit-transform:scale(0.6);
-ms-transform:scale(0.6);
-o-transform:scale(0.6);
transform:scale(0.6);
}

.f_circleG{
position:absolute;
background-color:#c1c9ce;
height:23px;
width:23px;
-moz-border-radius:12px;
-moz-animation-name:f_fadeG;
-moz-animation-duration:0.64s;
-moz-animation-iteration-count:infinite;
-moz-animation-direction:linear;
-webkit-border-radius:12px;
-webkit-animation-name:f_fadeG;
-webkit-animation-duration:0.64s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:linear;
-ms-border-radius:12px;
-ms-animation-name:f_fadeG;
-ms-animation-duration:0.64s;
-ms-animation-iteration-count:infinite;
-ms-animation-direction:linear;
-o-border-radius:12px;
-o-animation-name:f_fadeG;
-o-animation-duration:0.64s;
-o-animation-iteration-count:infinite;
-o-animation-direction:linear;
border-radius:12px;
animation-name:f_fadeG;
animation-duration:0.64s;
animation-iteration-count:infinite;
animation-direction:linear;
}

#frotateG_01{
left:0;
top:52px;
-moz-animation-delay:0.24s;
-webkit-animation-delay:0.24s;
-ms-animation-delay:0.24s;
-o-animation-delay:0.24s;
animation-delay:0.24s;
}

#frotateG_02{
left:15px;
top:15px;
-moz-animation-delay:0.32s;
-webkit-animation-delay:0.32s;
-ms-animation-delay:0.32s;
-o-animation-delay:0.32s;
animation-delay:0.32s;
}

#frotateG_03{
left:52px;
top:0;
-moz-animation-delay:0.4s;
-webkit-animation-delay:0.4s;
-ms-animation-delay:0.4s;
-o-animation-delay:0.4s;
animation-delay:0.4s;
}

#frotateG_04{
right:15px;
top:15px;
-moz-animation-delay:0.48s;
-webkit-animation-delay:0.48s;
-ms-animation-delay:0.48s;
-o-animation-delay:0.48s;
animation-delay:0.48s;
}

#frotateG_05{
right:0;
top:52px;
-moz-animation-delay:0.56s;
-webkit-animation-delay:0.56s;
-ms-animation-delay:0.56s;
-o-animation-delay:0.56s;
animation-delay:0.56s;
}

#frotateG_06{
right:15px;
bottom:15px;
-moz-animation-delay:0.64s;
-webkit-animation-delay:0.64s;
-ms-animation-delay:0.64s;
-o-animation-delay:0.64s;
animation-delay:0.64s;
}

#frotateG_07{
left:52px;
bottom:0;
-moz-animation-delay:0.72s;
-webkit-animation-delay:0.72s;
-ms-animation-delay:0.72s;
-o-animation-delay:0.72s;
animation-delay:0.72s;
}

#frotateG_08{
left:15px;
bottom:15px;
-moz-animation-delay:0.8s;
-webkit-animation-delay:0.8s;
-ms-animation-delay:0.8s;
-o-animation-delay:0.8s;
animation-delay:0.8s;
}

@-moz-keyframes f_fadeG{
0%{
background-color:#123041}

100%{
background-color:#c1c9ce}

}

@-webkit-keyframes f_fadeG{
0%{
background-color:#123041}

100%{
background-color:#c1c9ce}

}

@-ms-keyframes f_fadeG{
0%{
background-color:#123041}

100%{
background-color:#c1c9ce}

}

@-o-keyframes f_fadeG{
0%{
background-color:#123041}

100%{
background-color:#c1c9ce}

}

@keyframes f_fadeG{
0%{
background-color:#123041}

100%{
background-color:#c1c9ce}

}