我试图设置3 div到屏幕的右边,水平堆叠,只是垂直堆叠在小屏幕上。justify-content-end在父母div上很好地工作,直到我在孩子中使用col,然后我失去了理由。为什么col-sm会拒绝使用正当理由呢?我怎么才能解决这个问题?
<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>
上面的代码工作得很好,也很合理,但是没有将项目垂直地堆放在小屏幕上。下面的代码必须这样做,但它就是做不到!
<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>
发布于 2022-08-26 21:07:48
使用col-auto而不是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>
https://stackoverflow.com/questions/73502447
复制相似问题