How to display hr horizontally with flex?

后端 未结 2 991
旧巷少年郎
旧巷少年郎 2021-01-11 20:07

When using flexbox for styling, if the parent container is set to display: flex it will cause the


to be displayed vertically instead o
2条回答
  •  礼貌的吻别
    2021-01-11 20:42

    The reason for this is that default value of align-items is stretch so hr will get the same height as largest element in flex-container or in this case h2. And default value for justify-content is flex-start so width of hr is 0.

    Easy way to fix this is to use flex-wrap: wrap on parent element and flex: 0 0 100% on hr

    .container {
      display: flex;
      flex-wrap: wrap;
    }
    hr {
      flex: 0 0 100%;
    }

    Test


提交回复
热议问题