我在我的標題下添加了一個小部件區域,我嘗試將它置於標誌下方。居中標題下的div
我試圖在#header-sidebar
上添加display: block
和margin:0 auto
或text-align: center
,但它不起作用。此外,我試圖改變HTML代碼的結構,而不是隻做CSS調整,但仍然是左邊的#header-sidebar
堆棧,而不是居中。
這裏是我的代碼:
HTML代碼:
<header id="header">
<div class="header-container">
<a href="javascript:;" class="show-on-phone show-on-tablet" id="phone-toggle-menu"></a>
<a href="#" class="logo"><img style="vertical-align: middle;" src="#"></a>
<nav> //here is the navigation, hidden in mobile view </nav>
<div id="header-sidebar" class="header-widget-area">
<div class="textwidget">
//some widget here
</div>
<div class="mlp_language_box">
// some other widget here
</div>
</div>
</div>
</header>
CSS代碼:
header#header {
position: relative;
z-index: 300;
height: 70px;
line-height: 70px;
display: block;
}
header#header #phone-toggle-menu {
left: 20px;
margin-left: 0;
position: absolute;
}
header#header .header-container {
max-width: 1200px;
margin: 0 auto;
}
header#header .logo {
width: 100%;
float: none;
box-sizing: border-box;
text-align: center;
position: absolute;
}
你希望自己的標誌,是絕對的定位? – Chetan
@Chetan如果我不這樣做,它不會在移動設備的切換按鈕旁邊對齊中心。至少,我找不到方法 – Tasos
@Tasos,你還可以分享'#header-sidebar'或'.header-widget-area'的css代碼嗎? –