我有这个装载机:
.loader_ajax_small {
border: 2px solid #f3f3f3 !important;
border-radius: 50%;
border-top: 2px solid #2D2D2D !important;
width: 29px;
height: 29px;
-webkit-animation: spin_loader_ajax_small 2s linear infinite;
animation: spin_loader_ajax_small 2s linear infinite;
}
@-webkit-keyframes spin_loader_ajax_small {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin_loader_ajax_small {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
但我无法理解如何在div中水平居中,例如:
正如你所看到的那样在左边但是我希望它居中,我怎么能这样做?
答案 0 :(得分:6)
在margin: 0 auto;
中为父级div中心添加了.loader_ajax_small
.loader {
border: 1px solid #ccc;
padding: 20px;
}
.loader_ajax_small {
border: 2px solid #f3f3f3 !important;
border-radius: 50%;
border-top: 2px solid #2D2D2D !important;
width: 29px;
height: 29px;
margin: 0 auto;
-webkit-animation: spin_loader_ajax_small 2s linear infinite;
animation: spin_loader_ajax_small 2s linear infinite;
}
@-webkit-keyframes spin_loader_ajax_small {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin_loader_ajax_small {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader">
<div class="loader_ajax_small"></div>
</div>
或display: flex;
.loader {
border: 1px solid #ccc;
padding: 20px;
display: flex;
justify-content: center;
}
.loader_ajax_small {
border: 2px solid #f3f3f3 !important;
border-radius: 50%;
border-top: 2px solid #2D2D2D !important;
width: 29px;
height: 29px;
-webkit-animation: spin_loader_ajax_small 2s linear infinite;
animation: spin_loader_ajax_small 2s linear infinite;
}
@-webkit-keyframes spin_loader_ajax_small {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin_loader_ajax_small {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader">
<div class="loader_ajax_small"></div>
</div>
答案 1 :(得分:1)
在margin:0 auto;
属性中添加.loader_ajax_small
。
.loader_ajax_small {
border: 2px solid #f3f3f3 !important;
border-radius: 50%;
border-top: 2px solid #2D2D2D !important;
width: 29px;
height: 29px;
margin:0 auto;
-webkit-animation: spin_loader_ajax_small 2s linear infinite;
animation: spin_loader_ajax_small 2s linear infinite;
}
@-webkit-keyframes spin_loader_ajax_small {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin_loader_ajax_small {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
&#13;
<div class="loader_ajax_small"></div>
&#13;
答案 2 :(得分:0)
将您的加载器margin
设置为auto
像这样的东西
margin:10px auto;