Is there a way to manage col-sm children with justify-content-end parent?

Viewed 37

I am trying to set 3 divs to the right of the screen, stacked horizontally, just to be stacked vertically on small screen. justify-content-end works perfectly on parent div until I use col-sm in children, then I lose the justification. Why would col-sm dismiss the use of justification? How can I solve this?

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

<div class="d-flex justify-content-end">
  <div class="order-1 p-2">Some action 1</div>
  <div class="order-2 p-2">Another action 2</div>
  <div class="order-3 p-2">Triple divs 3</div>
</div>

The code above works and justifies perfectly, but does not set items vertically stacked on small screens. The code below must do it but it just won't!

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

<div class="d-flex justify-content-end">
  <div class="order-1 p-2 col-sm">Some action 1</div>
  <div class="order-2 p-2 col-sm">Another action 2</div>
  <div class="order-3 p-2 col-sm">Triple divs 3</div>
</div>

1 Answers

Use col-auto instead of col-sm

<!DOCTYPE html>
<html>
<head>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
  <div class="d-flex justify-content-end">
    <div class="order-1 p-2">Some action 1</div>
    <div class="order-2 p-2">Another action 2</div>
    <div class="order-3 p-2">Triple divs 3</div>
  </div>
  
  <div class="row g-0 justify-content-end">
    <div class="order-1 p-2 col-sm-auto">Some action 1</div>
    <div class="order-2 p-2 col-sm-auto">Another action 2</div>
    <div class="order-3 p-2 col-sm-auto">Triple divs 3</div>
  </div>

</body>
</html>

Related