html - 调整页面大小时如何修复导航栏收缩高度

标签 html css

我正在编写一个复制桌面操作系统外观/感觉的应用程序,当页面调整高度时,页面底部的导航栏高度会缩小。它以某种方式收缩,以至于在某一点变得无法使用。

我已经尝试了一些 CSS 属性,例如使用:position: fixed、position: relative 和 position: absolute。 position: absolute 是所有这些中最好的尝试之一。如果我使用其他任何样式,无论您如何更改样式,导航栏都会停留在顶部。

     body {
        /* these are for the navbar */
        top: 100%;
        margin: 0px;
        padding: 0px;
        /* normal styles */
        font-family: "MS Sans Serif";
        color: white;
        background-color: #008080;
        font-size: 12px;
        /* without this, the page would go blank
        overflow: hidden;
        }
        ul {
        /* this is what works best */
        position: absolute;
        width: 100%;
        top: 96.17%;
        /* normal navbar styling.. */
        list-style-type: none;
        margin: 0px;
        padding: 0px;
        overflow: hidden;
        background-color: #ffffff;
    }

我希望导航栏能够根据需要正常向上移动,同时保持其属性。相反,导航栏会在调整页面大小时向上移动,但它会变得越来越薄,直到无法使用。 这是一个示例 gif:enter image description here

最佳答案

ul {
  display: flex;
  list-style: none;
  align-items: center;
  flex-flow: row;
  background: red;
  position: sticky;
  max-width: 100vw;
  width: 100%;
  color: wheat;
  height: 50px;
  justify-content: space-around;
}

@media screen and (max-width: 768px) {
  ul {
    transition: .2s all linear;
    height: 45px;
    max-width: -webkit-fill-available;
    width: 100%;
  }
}
<ul>
  <li>Home</li>
  <li>About</li>
  <li>Help</li>
  <li>Contact</li>
</ul>

关于html - 调整页面大小时如何修复导航栏收缩高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56890317/

相关文章:

html - Float Div 在没有内容时保持其宽度

css - 有没有办法只设置嵌套无序列表的父元素的样式?

html - 在 iphone 容器内制作屏幕截图滚动

CSS - 哪些代码渲染速度更快、效率更高?

html - 挣扎于嵌套的 flexbox 网格

html - css 没有在网页上显示背景封面

html - 单个容器中的两个 60% 元素

html - Twitter Bootstrap 不允许高度 :100% on small screens, 尝试了其他问题中描述的所有解决方案

html - 我可以将 'display:table' d div中的数据正确地导入Excel吗

javascript - 如何使用 React js POST JSON 数据?