Nick.S Nick.S - 3 months ago 15
HTML Question

Centering images in a Bootstrap carousel?

As the title states I am having trouble getting images to center in my bootstrap carousel. The 4 images are 640x480 and keep aligning to the left of the carousel. I have uploaded my code to codepen and if anyone can help me with this problem, it'd be greatly appreciated. I have had a look at some solutions on stackoverflow but I haven't been able to fix the problem.

http://codepen.io/omfggrenade/pen/wWOKER


<body>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1 align="center">The Big Cats</h1>
</div>
</div>
<div class="container">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
<li data-target="#carousel-example-generic" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="http://placehold.it/640x480">
</div>
<div class="item">
<img src="http://placehold.it/640x480">
</div>
<div class="item">
<img src="http://placehold.it/640x480">
</div>
<div class="item">
<img src="http://placehold.it/640x480">
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div> <!-- /container -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

Answer

Using Adam Azad's comment, there's working example:

<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
<div class="container">
		<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
				<!-- Indicators -->
				<ol class="carousel-indicators">
					<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
					<li data-target="#carousel-example-generic" data-slide-to="1"></li>
					<li data-target="#carousel-example-generic" data-slide-to="2"></li>
					<li data-target="#carousel-example-generic" data-slide-to="3"></li>
				</ol>
				<!-- Wrapper for slides -->
				<div class="carousel-inner">
					<div class="item active">
						<img class="center-block" src="http://placehold.it/640x480?text=Slide+1">
					</div>
					<div class="item">
						<img class="center-block" src="http://placehold.it/640x480?text=Slide+2">
					</div>
					<div class="item">
						<img class="center-block" src="http://placehold.it/640x480?text=Slide+3">
					</div>
					<div class="item">
						<img class="center-block" src="http://placehold.it/640x480?text=Slide+4">
					</div>
				</div>
				<!-- Controls -->
				<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
					<span class="glyphicon glyphicon-chevron-left"></span>
				</a>
				<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
					<span class="glyphicon glyphicon-chevron-right"></span>
				</a>
	</div>
</div> <!-- /container -->

Codepen: http://codepen.io/bra1N/pen/QEoyLL

Comments