3 回答
TA貢獻1845條經驗 獲得超8個贊
嘗試這個:
.navbar {
position: relative;
}
.brand {
position: absolute;
left: 50%;
margin-left: -50px !important; /* 50% of your logo width */
display: block;
}
將徽標居中放置徽標寬度的50%,減去徽標寬度的一半,這樣在放大和縮小時就不會出現問題。
TA貢獻2016條經驗 獲得超9個贊
最簡單的方法是CSS轉換:
.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}
演示:http : //codepen.io/candid/pen/dGPZvR
居中背景徽標引導3
這種方法也適用于徽標的動態大小的背景圖像,并允許我們利用文本隱藏類:
CSS:
.navbar-brand {
background: url(http://disputebills.com/site/uploads/2015/10/dispute.png) center / contain no-repeat;
transform: translateX(-50%);
left: 50%;
position: absolute;
width: 200px; /* no height needed ... image will resize automagically */
}
HTML:
<a class="navbar-brand text-hide" href="http://disputebills.com">Brand Text
</a>
我們也可以使用flexbox。但是,使用此方法,我們必須移至navbar-brand之外navbar-header。這種方式很棒,因為現在我們可以并排放置圖像和文本了:
bootstrap 3徽標居中
.brand-centered {
display: flex;
justify-content: center;
position: absolute;
width: 100%;
left: 0;
top: 0;
}
.navbar-brand {
display: flex;
align-items: center;
}
演示:http://codepen.io/candid/pen/yeLZax
要僅在移動設備上獲得這些結果,只需將上述css包裝在媒體查詢中:
@media (max-width: 768px) {
}
- 3 回答
- 0 關注
- 668 瀏覽
相關問題推薦
添加回答
舉報
