簡體   English   中英

div內的左/右浮動按鈕

[英]Left/Right float button inside div

如何讓按鈕只在 div 區域浮動?

這是我的示例 CSS 和 HTML。

 .test { width: 60%; display: inline; overflow: auto; white-space: nowrap; margin: 0px auto; }
 <div class='test'> <div style='float: left;'> <button>test</button> </div> <div style='float: right;'> <button>test</button> </div> </div>

我希望它是這樣的。

在此處輸入圖片說明

將 display:inline 更改為 display:inline-block

.test {
  width:200px;
  display:inline-block;
  overflow: auto;
  white-space: nowrap;
  margin:0px auto;
  border:1px red solid;
}

您可以在.test使用justify-content: space-between ,如下所示:

 .test { display: flex; justify-content: space-between; width: 20rem; border: .1rem red solid; }
 <div class="test"> <button>test</button> <button>test</button> </div>


對於那些想要使用 Bootstrap 4 的人可以使用justify-content-between

 div { width: 20rem; border: .1rem red solid; }
 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" /> <div class="d-flex justify-content-between"> <button>test</button> <button>test</button> </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM