【问题标题】:the css align-content property does not work with block containers [duplicate]css align-content 属性不适用于块容器[重复]
【发布时间】:2021-02-08 16:21:42
【问题描述】:

例如,css align-content 属性不适用于块容器

<html>
  <body>
    <div class="container">
      <div class="item">this is item</div>
    </div>
  </body>
</html>

css代码

.container{
  background-color:yellow;
  width:350px;
  height:200px;
  align-content:center;

}
.item{
  width:100px;
  background-color:gray;
}

edit my code on jsfiddle

css框对齐模块说明截图

enter image description here

【问题讨论】:

    标签: html css


    【解决方案1】:

    没有display: flexalign-itemsjustify-content 将无法工作。

    .container{
      background-color:yellow;
      width:350px;
      height:200px;
      display: flex; /* without display: flex, align-items and justify-content wont' work */
      align-items: center; /* to vertically center the content */
      justify-content: center; /* to horizontally center the content */
    }
    .item{
      width:100px;
      background-color:gray;
    }
    <div class="container">
      <div class="item">this is item</div>
    </div>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 2019-10-24
    • 1970-01-01
    • 2018-06-22
    • 2021-11-08
    • 1970-01-01
    相关资源
    最近更新 更多