【问题标题】:add spacing between div elements在 div 元素之间添加间距
【发布时间】:2018-10-03 22:13:34
【问题描述】:

我想在这些 div 元素之间添加间距。 我该怎么做?

<div style="clear: left;">
  <p class="image"><img src="https://blog.proven.com/wp-content/uploads/zipsqaure.jpg" height="200" width="200" border="1px"></p>
  <p class="rating"><strong><font size="4">Proven Rating: <font color="#0077b3">★★★★★</font></font></strong></p>
  <p class="description">ZipRecruiter allows employers to post jobs within minutes and reach over 200 million active job seekers. </p>
</div>

<div style="clear: left;">
  <p class="image"><img src="https://blog.proven.com/wp-content/uploads/snag-1.png" height="200" width="200" border="1px"></p>
  <p class="rating"><strong><font size="4">Proven Rating: <font color="#0077b3">★★★★★</font></font></strong></p>
  <p class="description">Snagajob allows employers to reach over 80 million job seekers through their job board. It was founded in 1999 and continues to be one of the top job boards today, hosting one of the largest hourly employee networks on the web.</p>
</div>

【问题讨论】:

标签: html image spacing


【解决方案1】:

为每个元素定义一个边距或

使用类似这样的东西将其设置为 div 中的所有元素

div *{
    margin:10px;
}

【讨论】:

  • 这使用 descendant 选择器 ` `(空格),我想你想要 &gt; immediate child 选择器:div &gt; * { margin: 10px; }