1. .ant-menu-vertical .ant-menu-submenu, .ant-menu-vertical-left .ant-menu-submenu, .ant-menu-vertical-right .ant-menu-submenu, .ant-menu-inline .ant-menu-submenu {
  2. padding-bottom: 0.02px;
  3. }

System A is antd v3.26.6 while system B is v3.19.8, I am migrating A to B and find the menu li margin collapsed after the migration, so I looked deeper, and found that the newer version of antd menu has a padding-bottom: 0.02px; while the older is 0.01px, and put this in chrome for test, you can see 0.02px is the minimal pixel for browser to prevent the collapse while causing no difference to our eyes. Interesting one. So I checked antd’s code base, and here I see this comment:

  1. // disable margin collapsed
  2. .@{menu-prefix-cls}-submenu {
  3. padding-bottom: 0.02px;
  4. }

So, this is a design change. But why 0.01px in the beginning, the related commit. So it’s initially supposed to avoid the collapse, but incurred a bug, and later fixed.

more about vertical margin collapse

ref: https://css-tricks.com/what-you-should-know-about-collapsing-margins/

  • collapse happens when two elements with margins sit with each other
  • if both margins are positive numbers, then the bigger one effectives the margin between, while the smaller one is ‘swallowed’, ie bigger margin = total vertical margin
  • if there is a negative margin, the final margin should be total vertical margin = positive margin + negative margin , like 50px + (-25px)
  • if both are negative, then total vertical margin = smaller negative margin , like -25px and -50px , then the total margin should be -50px

    when parents ground their children

    As long as something solid sits between these margins, the should not collapse.
    So, if children are nested one by one, one way to avoid collapse is to give a padding to each layer: ```html

    Collapsing Child Margins

Collapsed

Not Collapsed

  1. ```css
  2. /* PRESENTATIONAL STYLES */
  3. html {
  4. font-size: 16px;
  5. }
  6. body {
  7. background-color: #333;
  8. color: #fff;
  9. font-family: Helvetica;
  10. padding: 25px;
  11. text-align: center;
  12. }
  13. h1 {
  14. font-size: 2em;
  15. font-weight: 800;
  16. }
  17. /* DEMO STYLES */
  18. /* Parent */
  19. div {
  20. margin: 15px 0;
  21. }
  22. /* Add padding to the parent */
  23. .padding {
  24. padding: 20px 0;
  25. }
  26. /* Here come the children */
  27. .red {
  28. background-color: #ff6b6b;
  29. }
  30. .orange {
  31. background-color: #ff9e2c;
  32. }
  33. .yellow {
  34. background-color: #eeee78;
  35. }
  36. .green {
  37. background-color: #4ecd9d;
  38. }
  39. .blue {
  40. background-color: #4e97cd;
  41. }
  42. .purple {
  43. background-color: #6c4ecd;
  44. }

image.png