問題:
I'm using Twitter Bootstrap 3, and I have problems when I want to align vertically two div
, for example — JSFiddle link :我正在使用 Twitter Bootstrap 3,當我想垂直對齊兩個div
時遇到問題,例如 - JSFiddle 鏈接:
<!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <div class="row"> <div class="col-xs-5"> <div style="height:5em;border:1px solid #000">Big</div> </div> <div class="col-xs-5"> <div style="height:3em;border:1px solid #F00">Small</div> </div> </div>
The grid system in Bootstrap uses float: left
, not display:inline-block
, so the property vertical-align
doesn't work. Bootstrap 中的網格系統使用float: left
,而不是display:inline-block
,因此屬性vertical-align
不起作用。 I tried using margin-top
to fix it, but I think this is not a good solution for the responsive design.我嘗試使用margin-top
來修復它,但我認爲這對於響應式設計來說不是一個好的解決方案。
解決方案:
參考一: https://stackoom.com/question/1ODQR參考二: vertical-align with Bootstrap 3