我使用的是 Bootstrap 3,并且有 3 个不同大小的按钮。我试图使它们都具有相同的大小(基于最大的一个的大小),然后将它们全部居中放置在页面中间,并在它们之间留出空间。这些按钮要么最终大小不同,要么它们之间没有任何空间。我希望按钮是动态的,所以我不想让它们符合特定的 px 宽度。
失败的尝试 1:
<div class="container">
<div class="btn-group blocks" data-toggle="buttons">
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">Middle Button</button>
<button type="button" class="btn btn-default">Right</button>
</div>
</div>
.blocks,
.btn {
padding: 24px 12px;
margin: 5px 10px 5px 10px;
border-radius: 0;
}
.container {
background-color: pink;
display: flex;
justify-content: space-between;
flex-flow: row wrap;
}
失败的尝试 2:
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4 buttons-container">
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Left</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default middle-btn">Middle Button</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Right</button>
</div>
</div>
</div>
<div class="col-md-4"></div>
</div>
.btn {
padding: 24px 12px !important;
margin: 5px 10px 5px 10px;
border-radius: 0;
}
最佳答案
试试这个代码:
.blocks,
.btn {
padding: 24px 12px;
margin: 5px 10px 5px 10px;
border-radius: 0;
}
.blocks {width:100%;}
.btn {max-width:150px;width:100%;}
.container {
background-color: pink;
display: flex;
justify-content: space-between;
flex-flow: row wrap;
}
尝试 1:jsfiddle 链接:https://jsfiddle.net/Loxn91oq/4/ 对于尝试 2:jsfiddle 链接:https://jsfiddle.net/ogdfLq9c/
关于html - 如何使按钮大小相同并在页面上居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347894/