html - 为什么不显示: flex property being inherited to child divs?

标签 html css inheritance flexbox

我正在学习如何使用 flexbox,但无法让我的子 div 继承 display:flex 属性。

我尝试过使用 Chrome 和 Firefox,但在这两种浏览器中都遇到了相同的问题。我可以让 .menu 类继承该属性的唯一方法是在 .menu 类中显式包含“display:inherit”,即使我在父“.menu-container”类中设置了“display:flex”。

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.menu-container {
  color: #fff;
  background-color: #5995DA;  /* Blue */
  padding: 20px 0;
  display: flex;
  justify-content: space-between;
}

.menu {
  display: inherit; /* Why do I need this? I shouldn't, right? */
  border: 1px solid #fff;
  width: 900px;
}
    <div class='menu-container'>
      <div class='menu'>
        <div class='date'>Aug 14, 2016</div>
        <div class='signup'>Sign Up</div>
        <div class='login'>Login</div>
      </div>
    </div>

最佳答案

display: flex 仅用于特定类。 child 被单独视为 flex 元素。

Flexbox Explanations如果您有兴趣。

关于html - 为什么不显示: flex property being inherited to child divs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57104016/

相关文章:

html - 如何让两个单词排成一行

javascript - Canvas 绘制的图像大小与返回的数据不同

css - 我们如何更改 Bootstrap 弹出窗口中箭头的颜色?

c++ - 找出c++中两个对象类之间的继承关系

html - 打印时从 css 中删除某些样式

html - 使用 CSS 将 DIV 对齐到另一个包装器 DIV 的底部,用于社交共享图样式按钮

javascript - 为什么在添加 "overflow: auto"时拖放更顺畅?

html - 我有一个有 2 列的 flexbox,我可以让第二列在特定维度下位于第一列之下吗?

python - 在多个文件和目录中使用Python OOP时,有助于理解分层继承

c++ - 无法从 friend 类访问私有(private)和公共(public)成员