2017-06-01 53 views
-1

我在我的網站上有一個adsense橫幅空間。 我爲空間系統自定義了最大高度和最大寬度的空間,以僅顯示最大940像素寬度和180像素高度的橫幅。現在我需要中心橫幅。 我嘗試使用align-items:center和justify-content:center。 我也嘗試了margin-left:auto和margin-right:auto。 始終在頁面邊緣左側顯示標題。DIV中的中心Adsense橫幅

代碼是這樣的:

<div id="footer_ad"> 
    <div style="max-height:180; max-width:940; margin-left: auto; margin-right: auto"> 
     <?php echo $footer_ad; ?> 
    </div> 
    <p>&nbsp;</p> 
</div> 

我認爲問題是 「父親」 的div ...

你能幫助我嗎?

+0

你是說你認爲的?‘父親’分區的問題,而你還沒有包括在這裏的定義 – Zack

+0

你能嘗試重現該問題在簡單的代碼片段你可以在這裏包含PHP嗎?包含它使我們不知道呈現的HTML中實際存在的是什麼。 – Zack

+0

是的,我試圖添加到第一個div。一樣。 – Weadom

回答

0

最好是使用柔性中心事業部......所以添加一些像這樣的事情你的CSS

.footer_ad { 
    height: yourheight; 
    max-width: yourmaxwidth; 
    margin: 40px auto 40px auto; 
    display: flex; 
} 

.center-ad { 
    margin: auto; 
} 

//Html should be like this 
<div class="footer_ad"> 
    <div class="center_ad"> 
     <?php echo $footer_ad; ?> 
    </div> 
</div> 
0

我解決問題... 是一個健忘:-( 我不會寫「PX 「 現在有了這個代碼工作:

<div id="footer_ad"> 
    <div style="max-height:180px; max-width:940px; margin-left: auto; margin-right: auto"> 
     <?php echo $footer_ad; ?> 
    </div> 
    <p>&nbsp;</p> 
</div>