Remove margin from bootsrap grid column inside listed card

Viewed 65

I want to make a card like this card-i-want

but I get a margin like this. enter image description here

How can I do it? Here is the Codepen Link Or:

body{
    font-family: 'Catamaran', sans-serif;
    letter-spacing: 1px;
}
.hotel-li {
    margin: 0;
}
.hotel-header{
    margin-bottom: 0;
}
.hotel-desc {
    margin-bottom: 0;
}
<!DOCTYPE html>
<html>
  <head>
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Catamaran:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  </head>
  <body>
    <div class="w-75 mx-auto card bg-dark text-white"><div class="card-header text-center border-white">Hotels</div><ul class="list-group list-group-flush"><li class="hotel-li list-group-item bg-dark border-white row"><div class="col-md-4"><h3 class="hotel-header">hotell</h3><p class="hotel-desc">dfsfdsfdsfdsfdsfdsfds</p></div><div class="col-md-4"><button class="btn btn-outline-light mx-2">Edit</button><button class="btn btn-outline-danger">Delete</button></div></li><li class="hotel-li list-group-item bg-dark border-white row"><div class="col-md-4"><h3 class="hotel-header">hotel 2</h3><p class="hotel-desc">random text</p></div><div class="col-md-4"><button class="btn btn-outline-light mx-2">Edit</button><button class="btn btn-outline-danger">Delete</button></div></li></ul></div>
  </body>
</html>
Thanks for helping

3 Answers

You can use : d-flex justify-content-between align-items-center on the li and remove additional classes on children :)

CODEPEN LINK: https://codepen.io/emmeiWhite/pen/jOMjbZb

 <li class="hotel-li list-group-item bg-dark border-white row d-flex justify-content-between align-items-center">

  <div>
    <h3 class="hotel-header">hotell</h3>
    <p class="hotel-desc">dfsfdsfdsfdsfdsfdsfds</p>
  </div>

  <div>
    <button class="btn btn-outline-light mx-2">Edit</button>
    <button class="btn btn-outline-danger">Delete</button>
  </div>
</li>

You can make use of the inbuilt Bootstrap flex classes: https://getbootstrap.com/docs/4.0/utilities/flex/. I have commented the extra code added.

Instead of col-4, Try for col-6 based on your layout.

body {
  font-family: 'Catamaran', sans-serif;
  letter-spacing: 1px;
}

.hotel-li {
  margin: 0;
}

.hotel-header {
  margin-bottom: 0;
}

.hotel-desc {
  margin-bottom: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="w-75 mx-auto card bg-dark text-white">
  <div class="card-header text-center border-white">Hotels</div>
  <ul class="list-group list-group-flush">
    <li class="hotel-li d-flex align-items-center list-group-item bg-dark border-white"> <!-- d-flex to convert it into flexbox container, align-items-center to align the items vertically -->
      <div class="col-6">
        <h3 class="hotel-header">hotell</h3>
        <p class="hotel-desc">dfsfdsfdsfdsfdsfdsfds</p>
      </div>
      <div class="col-6 d-flex justify-content-end"><button class="btn btn-outline-light mx-2">Edit</button><button class="btn btn-outline-danger">Delete</button></div> <!-- justify-content-end to move the content to the end horizontally -->
    </li>
    <li class="hotel-li d-flex align-items-center list-group-item bg-dark border-white">
      <div class="col-6">
        <h3 class="hotel-header">hotel 2</h3>
        <p class="hotel-desc">random text</p>
      </div>
      <div class="col-6 d-flex justify-content-end"><button class="btn btn-outline-light mx-2">Edit</button><button class="btn btn-outline-danger">Delete</button></div>
    </li>
  </ul>
</div>

please try 
    <div class="container-fluid">
    <div class="row">
    <div class="col-6"></div>
    <div class="col-6 d-flex justify-content-end"></div>
    <button></button>
</div>
</div>

By using bootstrap you may get the desired output

https://getbootstrap.com/docs/5.0/utilities/flex/#enable-flex-behaviors
Related