flexbox粘贴页眉和页脚问题

时间:2017-03-02 11:14:48

标签: html css html5 flexbox

我已经尝试了很多这样的事情,但这件事完全失败了。

使用flexbox,我试图使布局看起来和行为如下图所示:

enter image description here

而且,我猜最糟糕的部分是我无法取消附加页脚(类step-wrapper)。我必须将它保留在#app元素内。

现在的另一个问题是,当页面的高度小于page-container的页面时,标题将完全消失。

简化代码:

HTML              

        <header class="main-header-c">
            <nav class="navbar navbar-static-top" role="navigation">
                <div class="navbar-custom-menu">
                    <a href="#" class="logo">Logo</a>
                </div>
            </nav>
        </header>

       <div class="page-content">
           <div id="app">
                <ol class="step-indicator">
                   <li></li>
                   <li></li>
                </ol> 

                <div class="m-b-md">
                    <p>Content of tab</p>
                </div>

                <div class="step-wrapper active">
                    <button class="btn btn-primary" disabled="disabled">Next</button>
                </div>
            </div>
        </div>
    </div>
</body>

CSS

        html, body {
            background-color: #fff;
            color: #333;
            font-family: sans-serif;
            font-weight: 100;
            height: 100vh;
            margin: 0;
        }

        .full-height {
            height: 100vh;
        }

        .flex-center {
            align-items: center;
            display: flex;
            justify-content: center;
        }

        .position-ref {
            position: relative;
        }


        .page-content {
            text-align: center;
        }

        .m-b-md {
            margin-bottom: 30px;
        }

        .page {
            display: flex;
            flex-direction: column;
            flex: 1 1 auto;
            position: relative;/* need this to position inner content */
            overflow-y: auto;
            justify-content: space-around;
        }

        .main-header-c {
            flex: 1 1 auto;
            position: relative;/* need this to position inner content */
        }

        .step-wrapper {
            flex: 0 0 auto;
            align-self: flex-end;
        }

完整代码:http://codepen.io/AngelinCalu/pen/KWVYqd

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

不确定这是否属于您的目标:

基本上,我做了以下事情:

  • 让你的身体弯曲
  • 拆分出四个独立的组件 - 标题,子标题(步骤),内容和页脚
  • 使内容div增长以填充剩余的空间并给它溢出自动

&#13;
&#13;
$wizard-color-neutral: #ccc !default;
$wizard-color-active: #4183D7 !default;
$wizard-color-complete: #87D37C !default;
$wizard-step-width-height: 64px !default;
$wizard-step-font-size: 24px !default;
html {
  height: 100%;
}

body {
  padding: 0;
  margin: 0;
  background-color: #f6f6f6;
  font-family: 'Roboto', sans-serif;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

.container {
  width: 1000px;
  background-color: #fff;
}

#footer {
  text-align: center;
}

.step-wrapper {
  padding: 20px 0;
  display: none;
  background-color: #eee;
  border-top: 1px solid #ccc;
  &.active {
    display: block;
  }
}

.selected {
  background-color: $wizard-color-complete;
  &:hover {
    background-color: $wizard-color-complete !important;
  }
  &:active {
    background-color: $wizard-color-complete !important;
  }
  &:focus {
    background-color: $wizard-color-complete !important;
  }
}

.step-indicator {
  border-collapse: separate;
  display: table;
  margin-left: 0px;
  position: relative;
  table-layout: fixed;
  text-align: center;
  vertical-align: middle;
  padding-left: 0;
  padding-top: 20px;
  li {
    display: table-cell;
    position: relative;
    float: none;
    padding: 0;
    width: 1%;
    &:after {
      background-color: $wizard-color-neutral;
      content: "";
      display: block;
      height: 1px;
      position: absolute;
      width: 100%;
      top: $wizard-step-width-height/2;
    }
    &:after {
      left: 50%;
    }
    &:last-child {
      &:after {
        display: none;
      }
    }
    &.active {
      .step {
        border-color: $wizard-color-active;
        color: $wizard-color-active;
      }
      .caption {
        color: $wizard-color-active;
      }
    }
    &.complete {
      &:after {
        background-color: $wizard-color-complete;
      }
      .step {
        border-color: $wizard-color-complete;
        color: $wizard-color-complete;
      }
      .caption {
        color: $wizard-color-complete;
      }
    }
  }
  .step {
    background-color: #fff;
    border-radius: 50%;
    border: 1px solid $wizard-color-neutral;
    color: $wizard-color-neutral;
    font-size: $wizard-step-font-size;
    height: $wizard-step-width-height;
    line-height: $wizard-step-width-height;
    margin: 0 auto;
    position: relative;
    width: $wizard-step-width-height;
    z-index: 1;
    &:hover {
      cursor: pointer;
    }
  }
  .caption {
    color: $wizard-color-neutral;
    padding: 11px 16px;
  }
}

html,
body {
  background-color: #fff;
  color: #333;
  font-family: sans-serif;
  font-weight: 100;
  height: 100vh;
  margin: 0;
}

.full-height {
  height: 100vh;
}

.flex-center {
  align-items: center;
  display: flex;
  justify-content: center;
}

.position-ref {
  position: relative;
}

.page-content {
  text-align: center;
}

.m-b-md {
  margin-bottom: 30px;
}

.page {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  position: relative;
  /* need this to position inner content */
  overflow-y: auto;
  justify-content: space-around;
}

.main-header-c {
  position: relative;
  /* need this to position inner content */
}

.step-wrapper {
  flex: 0 0 auto;
  align-self: flex-end;
}

.navbar-static-top {
  z-index: 1000;
  border-width: 0 0 1px;
}

.navbar {
  position: relative;
  min-height: 50px;
  margin-bottom: 20px;
  border: 1px solid transparent;
}

.main-header-c .navbar {
  background-color: #fecb22;
}

.navbar:before,
.navbar:after {
  content: " ";
  display: table;
}

.navbar:after {
  clear: both;
}

.nav {
  margin-bottom: 0;
  padding-left: 0;
  list-style: none;
}

.main-header-c .logo {
  background-color: #fecb22;
  color: #1f2427;
  border-bottom: 0px solid transparent;
  font-family: 'Exo 2', sans-serif;
  text-transform: uppercase;
  display: block;
  float: left;
  height: 50px;
  font-size: 20px;
  line-height: 50px;
  text-align: center;
  width: 195px;
  padding: 0 15px;
  font-weight: 300;
  overflow: hidden;
}

.logo-mini {
  background-image: url(https://b.fastcompany.net/multisite_files/fastcompany/imagecache/inline-small/inline/2015/09/3050613-inline-i-2-googles-new-logo-copy.png);
  background-size: 100% auto;
  background-repeat: no-repeat;
  float: left;
  width: 45px;
  height: 45px;
  margin-top: 2.5px;
}

.main-header-c .navbar .nav > li > a {
  color: #fff;
}

.page-content {
  display:flex;
  flex-grow: 1;
  overflow:auto;
  align-items:center;
  justify-content:center;
}
&#13;
<header class="main-header-c">
  <nav class="navbar navbar-static-top" role="navigation">
    <div class="navbar-custom-menu">
      <div class="pull-left">
        <!-- Logo -->
        <a href="#" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
          <span class="logo-mini"> </span>
          <!-- logo for regular state and mobile devices -->
          <span class="logo-lg">Logo</span>
        </a>
      </div>
      <div class="pull-right">
        <ul class="nav navbar-nav">
          <li><a href="#" class="btn" style="padding:14px"><i class="fa fa-sign-out" aria-hidden="true"></i><span class="hidden-xs"> Sign Out</span></a></li>
        </ul>
      </div>
    </div>
  </nav>
</header>
<div id="sub-header">
  <ol class="step-indicator">
    <li class="active">
      <div class="step"><i class="fa fa-map-marker"></i></div>
      <div class="caption hidden-xs hidden-sm">
        Step 1: Start
      </div>
    </li>
    <li class="">
      <div class="step"><i class="fa fa-info-circle"></i></div>
      <div class="caption hidden-xs hidden-sm">
        Step 2: Basic Info
      </div>
    </li>
    <li class="">
      <div class="step"><i class="fa fa-graduation-cap"></i></div>
      <div class="caption hidden-xs hidden-sm">
        Step 3: Education
      </div>
    </li>
    <li class="">
      <div class="step"><i class="fa fa-briefcase"></i></div>
      <div class="caption hidden-xs hidden-sm">
        Step 4: Experience
      </div>
    </li>
    <li class="">
      <div class="step"><i class="fa fa-paper-plane"></i></div>
      <div class="caption hidden-xs hidden-sm">
        Step 5: Final Things
      </div>
    </li>
  </ol>
</div>

<div class="page-content">


  <div id="app">
    <!---->
    <div class="m-b-md">
      <h1>How should we call you?</h1>
      <p>
        <button value="Angelin" class="btn btn-default btn-lg" style="margin-right: 5px;"> John </button>
        <button value="Calu" class="btn btn-default btn-lg" style="margin-right: 5px;"> Doe </button>
      </p>
    </div>
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
    <!---->
  </div>
</div>
<footer id="footer">
  <div class="step-wrapper active">
    <button class="btn btn-primary">Back</button>
    <!---->
    <button class="btn btn-primary" disabled="disabled">Next</button>
    <!---->
  </div>
</footer>
&#13;
&#13;
&#13;

Updated Pen

<强>更新

New pen - 更接近您的HTML布局。我刚删除了整页包装器div并在.m-b-md div

中添加了内容div包装器