Javascript 如何在 DIV 之间添加空格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5901443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:26:15  来源:igfitidea点击:

How to add space between DIVs?

javascriptcsshtml

提问by Frank Rizzo

I have a WordPress generated page where I want to place AdSense below the header of the page. See image at http://imgur.com/WPXeG

我有一个 WordPress 生成的页面,我想将 AdSense 放在页面标题下方。请参阅http://imgur.com/WPXeG 上的图片

I want to create some white space between the header and the AdSense ad. I've tried adding margin-top and padding to the div that contains the AdSense ad (as noted below) - all to no avail.

我想在标题和 AdSense 广告之间创建一些空白。我尝试向包含 AdSense 广告的 div 添加 margin-top 和 padding(如下所述) - 都无济于事。

<div style="text-align: center; margin-top: 5px; padding: 13px 0 10px 0;">
  <script type="text/javascript"><!--
    google_ad_client = "**************";
    google_ad_slot = "**************";

What do I have to do provide some white space between the header and the AdSense ad?

我该怎么做才能在标题和 AdSense 广告之间留出一些空白?

P.S. The site is http://phoneswithwindows.com/

PS 网站是http://phoneswithwindows.com/

回答by Eineki

put in your css

放入你的css

#access {
  margin-bottom: 5px; /* or whatever */
}

回答by isra17

I added margin-top: 5pxon the <ins>element inside the div and it work. If you could add an id to the div you use this css rule:

我在 div 内margin-top: 5px<ins>元素上添加了它,它可以工作。如果您可以向 div 添加一个 id,则可以使用此 css 规则:

div#adds > ins{
    margin-top: 5px;
}

回答by Shauna

Your #accessdiv has float:left;on it, so you will need to add clear:left(or clear:both) on the div containing the ad, so they don't overlap.

您的#accessdivfloat:left;上有,因此您需要在包含广告的 div 上添加clear:left(或clear:both),这样它们就不会重叠。

If you look at your page with Firebug, or the developer tools in your favorite browser, you can see that your ad div actually sits above and layered below your header divs, and when you add clear: both, it will move down to where it should be.

如果您使用 Firebug 或您喜欢的浏览器中的开发人员工具查看您的页面,您会发现您的广告 div 实际上位于标题 div 的上方和下方,并且当您添加 时clear: both,它会向下移动到应有的位置。

回答by Rob

Have you tried adding the following

您是否尝试添加以下内容

<div style="clear:both;"></div>

after the header div?

在标题div之后?

This way the header float (if it had a float) is cleared and the Ad div below should now utilise the padding

这样头浮动(如果它有浮动)被清除,下面的广告 div 现在应该使用填充

回答by Amjad Masad

Add a margin-bottomto the div with id "access"

将 a 添加margin-bottom到 id 为“access”的 div