Попытка вертикально и горизонтально выровнять счетчик в корпусе начальной загрузки 4 карты.
Я пробовал my-auto и justify-content-center & align-items-center, я что-то упускаю.
Я проверил типы отображения и считаю, что мои отображения абсолютного значения верны.
Я также проверил свои позиции и считаю, что правильно использую flex.
Моя цель загрузить спиннер на тело на любую карту по вертикали и горизонтали.
Что я упускаю?
CodePen: https://codepen.io/sterling415/pen/xBERWV
HTML:
<div class = "card">
<h5 class = "card-header">Featured</h5>
<div class = "card-body justify-content-center align-items-center">
<div id = "overlay" onclick = "off()">
<div id = "justify-content-center align-items-center">
<div class = "spinner"></div>
</div>
</div>
<h5 class = "card-title">Special title treatment</h5>
<p class = "card-text">With supporting text below as a natural lead-in to additional content.</p>
<button type = "button" class = "btn btn-primary" onclick = "on()">Turn on overlay effect</button>
</div>
</div>
</div>
</div>
CSS:
.spinner {
height: 60px;
width: 60px;
margin: auto;
display: flex;
position: absolute;
-webkit-animation: rotation .6s infinite linear;
-moz-animation: rotation .6s infinite linear;
-o-animation: rotation .6s infinite linear;
animation: rotation .6s infinite linear;
border-left: 6px solid rgba(0, 174, 239, .15);
border-right: 6px solid rgba(0, 174, 239, .15);
border-bottom: 6px solid rgba(0, 174, 239, .15);
border-top: 6px solid rgba(0, 174, 239, .8);
border-radius: 100%;
}
@-webkit-keyframes rotation {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
}
}
@-moz-keyframes rotation {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(359deg);
}
}
@-o-keyframes rotation {
from {
-o-transform: rotate(0deg);
}
to {
-o-transform: rotate(359deg);
}
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
#overlay {
position: absolute;
display: none;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
}
JS:
function on() {
document.getElementById("overlay").style.display = "flex";
}
function off() {
document.getElementById("overlay").style.display = "none";
}



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Изменить <div id = "justify-content-center align-items-center"> на
<div class = "w-100 d-flex justify-content-center align-items-center">
Посмотрите это в действии ниже:
function on() {
document.getElementById("overlay").style.display = "flex";
}
function off() {
document.getElementById("overlay").style.display = "none";
}.spinner {
height: 60px;
width: 60px;
margin: auto;
display: flex;
position: absolute;
-webkit-animation: rotation .6s infinite linear;
-moz-animation: rotation .6s infinite linear;
-o-animation: rotation .6s infinite linear;
animation: rotation .6s infinite linear;
border-left: 6px solid rgba(0, 174, 239, .15);
border-right: 6px solid rgba(0, 174, 239, .15);
border-bottom: 6px solid rgba(0, 174, 239, .15);
border-top: 6px solid rgba(0, 174, 239, .8);
border-radius: 100%;
}
@-webkit-keyframes rotation {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
}
}
@-moz-keyframes rotation {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(359deg);
}
}
@-o-keyframes rotation {
from {
-o-transform: rotate(0deg);
}
to {
-o-transform: rotate(359deg);
}
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
#overlay {
position: absolute;
display: none;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
cursor: pointer;
}<link href = "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel = "stylesheet"/>
<div class = "container">
<div class = "row">
<div class = "card">
<h5 class = "card-header">Featured</h5>
<div class = "card-body justify-content-center align-items-center">
<div id = "overlay" onclick = "off()">
<div class = "w-100 d-flex justify-content-center align-items-center">
<div class = "spinner"></div>
</div>
</div>
<h5 class = "card-title">Special title treatment</h5>
<p class = "card-text">With supporting text below as a natural lead-in to additional content.</p>
<button type = "button" class = "btn btn-primary" onclick = "on()">Turn on overlay effect</button>
</div>
</div>
</div>
</div>Можете ли вы объяснить, почему это покрывает всю карту, а не только тело карты, хотя оверлейный div и spinner являются дочерними элементами тела карты?
Наложение имеет position: absolute с top: 0; left: 0; right: 0; bottom: 0;, и, поскольку его родитель, .card-body не имеет свойства position: relative;, оно абсолютно позиционировано относительно. первый родитель с position: relative, то есть .card, который расширяет его до полной высоты и ширины .card. Вы можете добавить position: relative; к .card-body и увидеть разницу
Используйте классы, а не идентификаторы для flex-команд Bootstrap.