Daniele Brunengo
asked on
Problem with Bootstrap 4 and image centering
Hello, I have decided to build a website with Bootstrap 4, just to test it out.
I am having trouble with as simple a task as centering an image, though.
This is the full code:
And this is the test page on my server:
http://test.ilgufoblu.net/ferrari/prova.html
I haven't been able to find a single reason why this image shouldn't be centered, with the text-center class assigned to its containing div.
Can somebody help me understand this?
I am having trouble with as simple a task as centering an image, though.
This is the full code:
<!doctype html>
<html class="no-js" lang="it">
<head>
<title>Prova</title>
<!-- BOOTSTRAP 4 -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="js/vendor/modernizr-3.5.0.min.js"></script>
<script src="js/vendor/jquery-3.2.1.min.js"></script>
<script src="js/vendor/popper.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="text-center logo">
<img class="img-fluid" src="img/logo/logo800.png">
</div>
</div>
</div>
</div>
</body>
</html>
And this is the test page on my server:
http://test.ilgufoblu.net/ferrari/prova.html
I haven't been able to find a single reason why this image shouldn't be centered, with the text-center class assigned to its containing div.
Can somebody help me understand this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yeah - the xs has been dropped. Basically, Bootstrap is designed to be mobile first, so effectively, the xs size is the defualt, so there's no need to specify it. You only need to specify the breakpoints for larger sizes, so for columns, you have:
// single column on XS devices / 2 columns on SM
<div class="col col-sm-6">content</div>
<div class="col col-sm-6">content</div>
// 2 columns on XS / 3 columns on SM
<div class="col-6 col-sm-4">content</div>
<div class="col-6 col-sm-4">content</div>
<div class="col-6 col-sm-4">content</div>
// single column on XS devices / 2 columns on SM
<div class="col col-sm-6">content</div>
<div class="col col-sm-6">content</div>
// 2 columns on XS / 3 columns on SM
<div class="col-6 col-sm-4">content</div>
<div class="col-6 col-sm-4">content</div>
<div class="col-6 col-sm-4">content</div>
sorry - above code should be col-12, not col for the single col:
<div class="col-12 col-sm-6">content</div>
<div class="col-12 col-sm-6">content</div>
<div class="col-12 col-sm-6">content</div>
<div class="col-12 col-sm-6">content</div>
ASKER
Thanks again.
To center an image you will need Bootstrap helper
https://v4-alpha.getbootstrap.com/content/images/#aligning-images
To center an image here is the code
https://v4-alpha.getbootstrap.com/content/images/#aligning-images
To center an image here is the code
<img src="..." class="mx-auto d-block" alt="...">
or <div class="text-center">
<img src="..." alt="...">
</div>
ASKER