【问题标题】:CSS Navigation - way without flexCSS 导航 - 没有 flex 的方式
【发布时间】:2018-03-22 03:22:31
【问题描述】:

如果没有display: flex;flex: 1 0 0;,此示例是否低于realizable

如何将.navigation 的高度设置为 100% 但自动减去 SignOut 的高度?我试过 calc(100% - SignOutHeight) 但 SignOutHeight 可以是动态的...只有 flex 模型提供此选项或存在不同的方式?

jsfiddle

https://jsfiddle.net/Lny303nh/3/

    body {
      margin: 0;
    }

    * {
      box-sizing: border-box;
    }

    .experiment {
      background: #f00;
      display: flex;
      flex-direction: column;
      height: 100%;
      padding-bottom: 16px;
      padding-top: 16px;
      position: fixed;
      width: 320px;
    }
    
    .navigation {
      flex: 1 0 0;
      overflow: auto;
    }
    
    .navigation__links {
      padding-left: 16px;
      padding-right: 16px;
    }
    
    .navigation__link {
      background: #f00;
      color: #fff;
      padding: 16px;
    }
    
    .navigation__link_active {
      background: #fff;
      color: #000;
    }
    <div class="experiment">
      <div class="navigation">
        <div class="navigation__links">
          <div class="navigation__link">
            Name
          </div>
          <div class="navigation__link">
            Sign In
          </div>
          <div class="navigation__link navigation__link_active">
            Sign Up
          </div>
        </div>
      </div>
    
      <div class="navigation__links">
        <div class="navigation__link">
          Sign Out
        </div>
      </div>
    </div>

【问题讨论】:

  • 当 flex 提供了一个更简单且支持良好的解决方案时,为什么还要使用 css 表?
  • 如果你不想使用 flex,为什么不直接使用浮点数呢?应用浮动:左;到所有 navBar 元素将垂直对齐它们。
  • @JaredBledsoe 你能把 jsfiddle 的例子发给我吗?

标签: html css flexbox


【解决方案1】:

这是一个根据要求使用 CSS 浮动的示例,使用 % 宽度,因此它是响应式的。如果您希望它们像图像中那样垂直,只需删除浮动:left;

.navSection {
    float: left;
    width: 20%;
}
.navSection:nth-child(odd) {
    background-color: red;
}
.navSection:nth-child(even) {
    background-color: blue;
}

 
<p class="navSection">Section 1</p>
<p class="navSection">Section 2</p>
<p class="navSection">Section 3</p>
<p class="navSection">Section 4</p>
<p class="navSection">Section 5</p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 2016-05-16
    相关资源
    最近更新 更多