Zeddrix Fabian
Zeddrix Fabian

Reputation: 2566

How to align image and text properly in bootstrap?

This is my code:

<section class="jumbotron text-center">
  <div class="container">
    <div class="col-md-12">
      <div class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
        <div class="col p-4 d-flex flex-column position-static">
          <div class="col-auto d-none d-lg-block">
            <img class="img-fluid text-left" src="{% static 'Zedd.jpg' %}" height="300" width="300" />
            <h1>Hi! I'm Zedd!</h1>
            <p class="lead text-muted">How are you? My full name's Zeddrix Fabian. I am currently learning Django as I make this tutorial--that's the truth. Here are my hobbies and my projects.</p>
            <p>
              <a href="mailto:[email protected]" class="btn btn-primary my-2">Email me</a>
            </p>
          </div>
        </div>
      </div>
    </div>
</section>

I want to have something like this (the top left side only with the "Hi! I'm Zedd!"):

enter image description here

And yet I keep getting this:

enter image description here

When I tried this snippet:

<div class="col-auto d-none d-lg-block">
              <img class="img-fluid text-left d-inline" src="{% static 'Zedd.jpg' %}" height="300" width="300" />
              <h1 class="d-inline">Hi! I'm Zedd!</h1>
              <p class="lead text-muted d-inline">How are you? My full name's Zeddrix Fabian. I am currently learning Django as I make this tutorial--that's the truth. Here are my hobbies and my projects.</p>
              <p class="d-inline">
                  <a href="mailto:[email protected]" class="btn btn-primary my-2">Email me</a>
              </p>
          </div>

This was the outcome: enter image description here

What to do?

Upvotes: 1

Views: 2023

Answers (2)

teddcp
teddcp

Reputation: 1624

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Template</title>

    <!-- Font Awesome 4.7 -->
    <link
      href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
      rel="stylesheet"
      integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
      crossorigin="anonymous"
    />

    <!-- bootstrap 4.4 -->
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
      integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
      crossorigin="anonymous"
    />

    <!-- Custom Style Sheet  -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <section class="jumbotron text-center">
      <div class="container">
        <div
          class="row no-gutters border rounded overflow-hidden  mb-4 shadow-sm h-md-250 align-items-center"
        >
          <div class="col-md-4 mb-3 ">
            <img
              class="img-fluid"
              src="https://images.unsplash.com/photo-1542156822-6924d1a71ace?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80"
            />
          </div>
          <div class="col-md-8 d-flex flex-column text-center p-2 justify-content-center">
            <h1>Hi! I'm Zedd!</h1>
            <p class="lead text-muted">
              How are you? My full name's Zeddrix Fabian. I am currently
              learning Django as I make this tutorial--that's the truth. Here
              are my hobbies and my projects.
            </p>
            <p>
              <a
                href="mailto:[email protected]"
                class="btn btn-primary my-2"
                >Email me</a
              >
            </p>
          </div>
        </div>
      </div>
    </section>

    <!-- Bootstrap js ,popper js and jquery  -->
    <script
      src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
      integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
      integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
      integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
      crossorigin="anonymous"
    ></script>

    <!-- Custome js  -->
    <script src="script.js"></script>
  </body>
</html>

Snaps

img

Upvotes: 3

Syed Khizaruddin
Syed Khizaruddin

Reputation: 435

h1 and p tags are block level element i.e they take whole width of viewport

you must use d-inline class on h1 and on p tags

<div class="col-auto d-none d-lg-block">
    <img class="img-fluid text-left d-inline" src="{% static 'Zedd.jpg' %}" height="300" width="300" />
    <h1 class="d-inline">Hi! I'm Zedd!</h1>
    <p class="lead text-muted d-inline">How are you? My full name's Zeddrix Fabian. I am currently learning Django as I make this
        tutorial--that's the truth. Here are my hobbies and my projects.</p>
    <p class="d-inline">
        <a href="mailto:[email protected]" class="btn btn-primary my-2">Email me</a>
    </p>
</div>

Upvotes: 2

Related Questions