如何"附加"中心网站的广告元素?

时间:2015-04-28 01:40:29

标签: javascript jquery html css

也许这会是一个有点愚蠢的问题,但如果我有一个居中的网站(使用固定宽度+保证金:0自动)我该如何"附加"它的广告元素? (左摩天大楼)。

我做了什么,不喜欢的是,现在我有一个内容和广告所在的包装器。但是包装器的宽度必须大于内容(页面)。所以网站不再居中,当广告没有显示时(使用adblock和类似的东西),它看起来真的很难看。

JS是唯一的方法吗?

2 个答案:

答案 0 :(得分:0)

不知道'attach'是什么意思,但下面是我如何构建/构建它。

   <div id="container">
      <div class="column_left">I don't know what your using for ads, but you could place right here. Image, text, ad script?</div>
    <!-- just place your ad in the above div -->
      <div class="column_right">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div>
    </div>

<强> CSS:

#container {
    overflow: hidden;
    margin: 0 auto;
    width: 960px;
    position: relative;
}
.column_left {
    width: 200px;
    float: left;
    margin: 0 10px 0 0;
    background-color: #f7f7f7;
    border: 1px solid #f5f5f5;
}

.column_right { 
    width: 700px;
    float: left;
    background: #ddd;
}

http://jsfiddle.net/jkLMK/36/

答案 1 :(得分:0)

如果你想要下载脚本选项,你可以这样做:

 <div id="content" style="width: 960px; margin: 0 auto;">
  ...
 </div>

 <div id="ad" style="position: absolute; top: 0px; left: 0px;">
  ...
 </div>

 <script>

  window.onresize = function() {

    var contentWidth = 960;
    var marginWidth = (window.innerWidth - contentWidth) / 2;

    document.getElementById("ad").style.width = marginWidth + "px";

  };

  window.onresize();

 </script>