Link to home
Start Free TrialLog in
Avatar of Daniele Brunengo
Daniele BrunengoFlag for Italy

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:

<!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>

Open in new window


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
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniele Brunengo

ASKER

Thanks! But has the xs label been dropped altogether, or just for a 12 column row, where it actually is no use?
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>
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>
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
<img src="..." class="mx-auto d-block" alt="...">

Open in new window

or
<div class="text-center">
  <img src="..." alt="...">
</div>

Open in new window