0

如何在全屏 html5 游戏中居中放置广告?我的游戏设计为在玩游戏时在浏览器上全屏显示。我希望我的广告始终位于中心,无论它是否在平板电脑/PC/等上播放。

那么如何让我的广告居中呢?

这是我的广告代码

<div id="goog" style="position:absolute; left:0; top:10;">

<script type="text/javascript">
<!--
google_ad_client = "ca-pub-xxxxxxxxx";

google_ad_slot = "xxxxxxxx";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>

我试过这个document.getElementById("goog").align = 'center';,但它不起作用。

4

1 回答 1

1

你可以试试这个

改变<div id="goog" style="position:absolute; left:0; top:10;">

<div id="goog" style="position:absolute; left:50%; top:50%;margin-top:-125px;margin-left:-175px;width:350px;height:250px;">

或者

<style>
    #goog { position:absolute; left:50%; top:50%;margin-top:-125px;margin-left:-175px;width:350px;height:250px; }
</style>

然后是html

<div id="goog">

于 2013-07-10T11:00:28.763 回答