Phrike Phrike - 4 months ago 29
HTML Question

Bootstrap columns will not align correctly, instead one is under the other

I hope someone can assist me. I am probably making a silly mistake, but I am following along with the Udacity video and the code looks identical. Thank you in advance.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Portfolio</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<img src="images/logo.jpg" alt="Udacity logo">
</div>
<div class="col-md-6">
<h1>John Doe</h1>
<h4>Front-end Ninja</h4>
</div>
</div>
</div>
</body>
</html>

Answer

The most likely reason is that your code is dependent upon browser window width - the code col-md-6 will only produce two columns on browser window width of 992px or wider.

Try replacing the class col-md-6 with col-sm-6 for both divs that use that class, that should ensure that even at smaller sizes, the columns display side-by-side.

Alternatively, make your screen wider to see how the columns move based upon screen width.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Portfolio</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/bootstrap.css">
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-sm-6">
                    <img src="images/logo.jpg" alt="Udacity logo">
                </div>
                <div class="col-sm-6">
                    <h1>John Doe</h1>
                    <h4>Front-end Ninja</h4>
                </div>
            </div>
        </div>
    </body>
</html>