htmlcssbootstrap-4bootstrap-5hbs

Get the 'card-title' to start just above a div


I want the 'title' to start right above 'first yeah', the image should also start there enter image description here

I've tried several ways (and with some classes) but I haven't succeeded

The card code:

<div class="card border-dark">
   <div class="card-body" style="background-color: #706747;">
      <h1 class="card-title">
         <p class="text-body">
            <img src="/assets/logo.gif" alt="" width="60" height="48" class="d-inline-block">
            {{cosos}} title
         </p>
      </h1>
      <br>
      <div class="d-flex flex-nowrap bd-highlight justify-content-center">
         <div class="order-1 p-2 bd-highlight">First flex item</div>
         <div class="order-2 p-2 bd-highlight">Second</div>
         <div class="order-3 p-2 bd-highlight">Third</div>
         <div class="order-4 p-2 bd-highlight">Final yup</div>
      </div>
   </div>
</div>

I'm using Bootstrap 5 for everything, I have no classes or styles of my own


Solution

  • Step 1: remove class justify-content-center and add p-2 after class card-title. Now you will see your logo.gif and title will align with first nav bar item.

    Step 2: Add place-self: center; to the div with class card-body.

    Step 3: Assign background-color: #706747; to the class card, remove from card-body div.

    The updated HTML will be like this:

    <div class="card border-dark" style="background-color: #706747;">
      <div class="card-body" style="place-self: center;">
        <h1 class="card-title p-2">
          <p class="text-body">
            <img src="/assets/logo.gif" alt="" width="60" height="48" class="d-inline-block"> {{cosos}} title
          </p>
        </h1>
        <div class="d-flex flex-nowrap bd-highlight ">
          <div class="order-1 p-2 bd-highlight">First flex item</div>
          <div class="order-2 p-2 bd-highlight">Second</div>
          <div class="order-3 p-2 bd-highlight">Third</div>
          <div class="order-4 p-2 bd-highlight">Final yup</div>
        </div>
      </div>
    </div>