一部のCSSマージンが崩壊する理由と崩壊しない理由を見つけるために、いくつかのテストを実行しています。私は次のテストコードを持っています:
<div id="seconddiv" style="margin-top:10px; margin-bottom:10px;">
<p style="height:200px; margin-top:5px; margin-bottom:5px;">This is the first paragraph in the second div!This paragraph is 200px tall.</p>
<p style="height:300px; margin-top:5px; margin-bottom:5px;">This is the second paragraph in the second div!This paragraph is 300 px tall.</p>
<p style="height:400px; margin-top:5px; margin-bottom:5px;">This is the third paragraph in the second div!This paragraph is 400px tall.</p>
</div>
divの高さを正確に取得しようとしていますが、scrollHeightは「910px」を返します。何故ですか?マージンが含まれていないため、scrollHeightとして「900px」を期待していました。
マージンの一部が<p>
崩壊し、高さでカウントされましたか?なぜ他の人ではなく一部の人。マージンの高さのさまざまな組み合わせを試しましたが、何が起こっているのかを示す値はありません。