この特定の例では、blockquote にパディングを追加したように聞こえます (おそらく、背景色または境界線もあると見栄えが良くなります)。blockquote にはデフォルトで margin-bottom があるため、padding-bottom と margin-下は一緒に追加されています。
これに対処する私の現在のお気に入りの方法は次のとおりです。
サスの使用:
p, blockquote, .other-margined-elements {
margin: 1rem 0;
&:first-child {
margin-top: 0;
}
&:last-child {
margin-bottom: 0;
}
}
生成された CSS:
p, blockquote, .other-margined-elements {
margin: 1em 0;
}
p:first-child, blockquote:first-child, .other-margined-elements:first-child {
margin-top: 0;
}
p:last-child, blockquote:last-child, .other-margined-elements:last-child {
margin-bottom: 0;
}
この方法では、リストに追加する要素を特定するだけです。私の現在のリストは次のとおりです: h1, h2, h3, h4, h5, h6, p, ul, ol, dl, table, blockquote, div, section, article, aside, fieldset
上記のコードが少しやり過ぎだと思われる場合は、これを行う他の方法があります。
blockquote > :first-child {
margin-top: 0;
}
blockquote > :last-child {
margin-bottom: 0;
}
:first-child
および疑似クラスのおかげで、:last-child
すべての組み合わせを書き出す必要はありません。