在DIV内的中心Adsense横幅

时间:2017-06-01 19:10:13

标签: html css banner

我在我的网站上有一个adsense banner的空间。

我为力系统定制了最大高度和最大宽度的空间,只显示最大宽度为940px,高度为180px的横幅。现在我需要以横幅为中心。

我尝试使用align-items: centerjustify-content: center。 我还尝试使用margin-left: automargin-right: auto。 但横幅仍显示在页面边缘左侧。

HTML

<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的样式

2 个答案:

答案 0 :(得分:0)

最好是使用flex中心Div ...所以在你的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>

答案 1 :(得分:0)

我解决问题... 是一个健忘:-( 我不写&#34; px&#34; 现在使用此代码工作:

<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>
相关问题