代码之家  ›  专栏  ›  技术社区  ›  bellotas

如何在HTML和CSS中创建固定页脚

  •  0
  • bellotas  · 技术社区  · 6 年前

    我为我的网站创建了一个固定页脚:

    html

    <div class=“card footerbf”>
    <div class=“card body space around”>
    按钮
    类型=“按钮”
    class=“buttonBF”按钮
    routerlink=“/myrouter”
    gt;
    <i class=“fa fa lock fa lg”></i>
    &按钮/按钮;
    按钮
    类型=“按钮”
    class=“buttonBF”按钮
    routerLink=“迈罗”
    gt;
    <i class=“fa fa globe fa lg”></i>
    &按钮/按钮;
    <button type=“button”class=“buttonbf”routerlink=“myroute”>
    <i class=“fa fa plus fa lg”></i>
    &按钮/按钮;
    按钮
    type=“按钮”
    class=“buttonBF”按钮
    routerLink=“迈罗”
    gt;
    <I class=“FA Home FA LG”></I>
    &按钮/按钮;
    &L/DIV & GT;
    &L/DIV & GT;
    < /代码> 
    
    

    css

    .footerbf{
    背景色:白色;
    文本对齐:居中;
    位置:固定;
    左:0;
    底部:0;
    宽度:100%;
    字体大小:1EM;
    }
    
    ButoBBF {
    背景色:白色;
    颜色:灰色;
    显示:内联块;
    边界:无;
    光标:指针;
    }
    < /代码> 
    
    

    问题是,当我滚动时,我的页脚会移动,即使应该是固定的。我附上一张图片来显示这个效果:

    .

    CSS

    .footerBF {
      background-color: white;
      text-align: center;
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      font-size: 1em;
    }
    
    .buttonBF {
      background-color: white;
      color: grey;
      display: inline-block;
      border: none;
      cursor: pointer;
    }
    

    问题是,当我滚动时,我的页脚会移动,即使应该是固定的。我附上一张图片来显示这种效果:

    1 回复  |  直到 6 年前
        1
  •  1
  •   Darren    6 年前

    固定底部导航栏有引导用户界面元素,每个元素 props 这样做…退房 Fixed bottom

    <nav class="navbar fixed-bottom">
      // Buttons
    </nav>
    

    但是,如果您希望问题中的当前代码按预期工作。我只要把 footer 具有 display: flex 给它一个 height justify-content align-items center .

    body {
      background: black;
      height: 2000px;
    }
    
    .footerBF {
      background-color: white;
      text-align: center;
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      font-size: 1em;
      height: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 1px solid #f1f1f1;
    }
    
    button {
      background-color: white;
      border: none;
      cursor: pointer;
    }
    <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet" />
    
    <body>
      <div class="card footerBF">
        <div class="card-body">
          <button type="button">
          <i class="fa fa-lock fa-lg"></i>
        </button>
          <button type="button">
          <i class="fa fa-globe fa-lg"></i>
        </button>
          <button type="button">
          <i class="fa fa-plus fa-lg"></i>
        </button>
          <button type="button">
          <i class="fa fa-home fa-lg"></i>
        </button>
        </div>
      </div>
    </body>