Why is setting the top-margin of this child element pushing its parent container down with it?

后端 未结 4 825
别跟我提以往
别跟我提以往 2020-12-17 00:22

I have two divs:

S

4条回答
  •  余生分开走
    2020-12-17 01:06

    I would actually argue that this answer is better:

    https://stackoverflow.com/a/49075574/2387316

    Yes, I know it's my own answer, but I think it's important that we don't add random bits of padding, change box-sizing for no reason, add spurious elements to the DOM, or change display/padding simply to fix a display issue. Those solutions all cause problems on their own: SEO is worse, unpredictable box-sizing behavior when trying to do something else, annoyance caused by positioning and display changes, etc. This solution is good for SEO, is scalable, and has no other tangible effect when trying to do other things with your elements.

提交回复
热议问题