更改段落之间和段落内部的间距

Dan*_*Dan 6 css spacing paragraph

我找到了与此类似的主题,但是我找不到要在Wordpress中更改的特定CSS。如果您转到我的主页博客

我想更改段落之间和段落之间的间距。不确定我需要在CSS中修改哪个元素。

找到的line-height属性.body,但似乎并没有达到我的期望。

Dav*_*542 9

在段落之间,您应该margin为该元素设置一个。您可以在段落内的行之间使用line-height。例如:

p {
  line-height: 32px;   /* within paragraph */
  margin-bottom: 30px; /* between paragraphs */
  }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


Nat*_*e K 7

添加 margin-bottom: 30px 可以解决问题,但您也或多或少地锁定了最后一段下方的下一个元素的间距,也以 30px 间距开始。段落之间的间距可能会与段落本身的行高匹配(或接近),这可能与下一类型元素的间距不同。

例如,假设您有一个对话框,其内容区域末尾有一个段落,下一个元素是对话框的页脚区域(带有操作按钮)。如果创建的反向边距超出了对话框内容和页脚之间的预期值,那么您不会希望执行一些反向负边距。

p {
    line-height: 32px;

    &:not(:last-child)  {
        margin-bottom: 30px;
    }
}

// or space on top with a sibling selector:
p {
    line-height: 30px;

    + p {
        margin-top: 32px;
    }
}
////
// or if your line-height and paragraph spacing is the same:
////
$p-line-height: 30px;

p {
    line-height: $p-line-height;

    &:not(:last-child)  {
        margin-bottom: $p-line-height;
    }
}

// w/ space on top:

p {
    line-height: $p-line-height;
    + p {
        margin-top: $p-line-height;
    }
}
Run Code Online (Sandbox Code Playgroud)