.templateCard {
width: 136px;
height: 260px;
display: inline-block;
margin-left: 3px;
margin-right: 3px;
margin-top: 10px;
}
#spinner {
margin: auto;
width: 20px;
height: 20px;
border: solid black;
}
<div id="card01" class="thumbnail templateCard">
<div id="spinner" class="ms-Spinner"></div>
<img src="/Content/img/template01.png" alt="...">
<div class="caption">
<h3>Rapport 1</h3>
</div>
</div>
I have this piece of code. I want the spinner-div to be centered both horizontally and vertically in the card01 div. I can only manage to center it horizontally. It seems like the problem is the two other div
s inside the card01-div
, as i can center the spinner in another empty div
(but not in this div container two additional div
s).
So I want the spinner to overlay the other content in card01
.
EDIT: and also, the card01-div
must not resize when the spinner appears!
You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.
Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "center." Step 4: Set the width of the image to a fixed length value.
Center Align Elements To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.
use position:relative/absolute
,
below are two examples,
.templateCard {
border: 1px dashed red;
/* demo */
width: 136px;
display: inline-block;
vertical-align: top;
margin-left: 3px;
margin-right: 3px;
margin-top: 10px;
position: relative;
}
#spinner {
margin: auto;
width: 20px;
height: 20px;
border: solid black;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0
}
#card02.templateCard {
height: 260px
}
<div id="card01" class="thumbnail templateCard">
<div id="spinner" class="ms-Spinner"></div>
<img src="//placehold.it/136" alt="...">
<div class="caption">
<h3>Rapport 1</h3>
</div>
</div>
<div id="card02" class="thumbnail templateCard">
<div id="spinner" class="ms-Spinner"></div>
<img src="//placehold.it/136x260" alt="...">
<div class="caption">
<h3>Rapport 1</h3>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With