【问题标题】:How to locate a NAV with position:fixed; at the center?如何定位具有 position:fixed 的 NAV;在中心?
【发布时间】:2019-06-05 07:03:44
【问题描述】:

当我将其位置指定为固定时,导航会向左浮动。 如何将其移回中心?

.container {
        max-width: 2000px;
        text-align: center;
        color: rgb(177, 177, 179);
    }

nav {
        display: flex;
        justify-content: space-around;
        position: fixed; 
    }

我想将导航栏固定在中心。 但是当我将导航栏位置分配为固定时,它会浮动到左侧。

图片如下:

【问题讨论】:

  • 你能用 HTML 添加整个代码吗?或者 JSfiddle 中的相同情况
  • 你能查一下解决办法吗

标签: html css-position fixed


【解决方案1】:

尝试使用 CSS 的 left & right 属性。

nav {
  display: flex;
  justify-content: space-around;
  position: fixed;
  left: 0;
  right: 0;
}

参考:https://developer.mozilla.org/en-US/docs/Web/CSS/position#Fixed_positioning

【讨论】:

    【解决方案2】:

    将宽度 100% 添加到导航 https://jsfiddle.net/ulric_469/1826szqm/1/

    nav {
      display: flex;
      justify-content: space-around;
      position: fixed;
      align-items: center;
      width: 100%;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 2018-07-30
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多