I am using Bootstrap 4 carousel and I am trying to center an image both vertically and horizontally. The following is my code together with the styling:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://placehold.it/200x200/c0392b/000">
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
#myCarousel {
height: 100%;
width: 100%;
}
.carousel-indicators {
margin-bottom: 8px;
}
.carousel-indicators>li {
width: 10px;
height: 10px;
border-radius: 100%;
}
.carousel-inner {
height: 100%;
background-color: #213B74;
}
.carousel-item {
text-align: center;
}
.carousel-item img {
display: block;
margin: auto;
}
For now, I have only added one carousel item for testing. The image is being centered horizontally. However, I have tried to set the display attribute for the image to block and its margin to auto but it's still not being centered vertically. Can someone tell me what am I doing wrong, please?
I have tried looking into other questions related to this, but I still didn't find the answer that I'm looking for. In case this question is a duplicate, I would gladly appreciate if you could tell me which answer should I be looking into.
Thanks