导航栏链接不会变小

Navbar links not getting smaller

我的导航栏出现问题,当我缩小浏览器选项卡后,文本保持相同大小,但徽标变得越来越小并消失。我怎样才能让它变得更小?如果需要更多信息,我会提供。这是我的问题的一些例子。 100% width page vs Page made smaller for smaller screens for example

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}


/* custom scroll bar */

::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
}

::selection {
  background: rgb(0, 123, 255, 0.3);
}

.content {
  max-width: 1250px;
  margin: auto;
  padding: 0 30px;
}


/* Nav start*/

.navbar {
  position: fixed;
  width: 100%;
  z-index: 2;
  padding: 25px 0;
  transition: all 0.3s ease;
  background-color: black;
}

.navbar.sticky {
  background: black;
  padding: 10px 0;
  box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.1);
}

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

.navbar .logo a {
  color: #fff;
  font-size: 30px;
  font-weight: 600;
  text-decoration: none;
}

.navbar .menu-list {
  display: inline-flex;
}

.menu-list li {
  list-style: none;
}

.menu-list li a {
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  margin-left: 20px;
  text-decoration: none;
  transition: all 0.3s ease;
}

.menu-list li a:hover {
  color: #007bff;
}

.banner {
  height: 100vh;
  background-position: center;
  background-attachment: fixed;
}

.about {
  padding: 30px 0;
}

.about .title {
  font-size: 38px;
  font-weight: 700;
}

.about p {
  padding-top: 20px;
  text-align: justify;
}

.icon {
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: none;
}

.menu-list .cancel-btn {
  position: absolute;
  right: 30px;
  top: 20px;
}

@media (max-width: 1230px) {
  .content {
    padding: 0 60px;
  }
}

@media (max-width: 1100px) {
  .content {
    padding: 0 40px;
  }
}

@media (max-width: 900px) {
  .content {
    padding: 0 30px;
  }
}

@media (max-width: 868px) {
  body.disabled {
    overflow: hidden;
  }
  .icon {
    display: block;
  }
  .icon.hide {
    display: none;
  }
  .navbar .menu-list {
    position: fixed;
    height: 100vh;
    width: 100%;
    max-width: 400px;
    left: -100%;
    top: 0px;
    display: block;
    padding: 40px 0;
    text-align: center;
    background: #222;
    transition: all 0.3s ease;
  }
  .navbar.show .menu-list {
    left: 0%;
  }
  .navbar .menu-list li {
    margin-top: 45px;
  }
  .navbar .menu-list li a {
    font-size: 23px;
    margin-left: -100%;
    transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  }
  .navbar.show .menu-list li a {
    margin-left: 0px;
  }
}

@media (max-width: 380px) {
  .navbar .logo a {
    font-size: 27px;
  }
}

.cta {
  padding: 9px 25px;
  background-color: rgba(0, 136, 169, 1);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: background-color 0.3s ease 0s;
}

.cta:hover {
  background-color: rgba(0, 136, 169, 0.8);
}


/* Nav end*/
<nav class="navbar">
  <div class="content">
    <div class="logo">
      <a href="/index.html"><img src="images/logo-villa-dor.jpg" width="100%"></a>
    </div>
    <ul class="menu-list">
      <div class="icon cancel-btn">
        <i class="fas fa-times"></i>
      </div>
      <li><a href="/fireplaces.html">Fireplaces</a></li>
      <li><a href="/floorings.html">Floorings</a></li>
      <li><a href="/iron_works.html">IronWorks</a></li>
      <li><a href="/ornaments.html">Ornaments</a></li>
      <li><a href="/Woodwork.html">Woodwork</a></li>
      <li><a href="/Radiators.html">Radiators</a></li>
      <li><a href="/luminairy.html">Luminary</a></li>
      <li><a href="/miscellaneous.html">Miscellaneous</a></li>
    </ul>
    <div class="icon menu-btn">
      <i class="fas fa-bars"></i>
    </div>
  </div>
</nav>

我认为你用错了@media

@media (max-width: 868px) 

表示当它的最大宽度为 868px 时将应用这些样式。所以对于小屏幕,你需要减小那里的字体大小。

@media (max-width: 868px) {
    .navbar .menu-list li a{
         font-size: 16px; // for example
         margin-left: -100%;
         transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 
         1.55);
    }
}

我发现您的样式中存在一些问题,这些问题已被证明对您的设计有问题。为了演示 media-queries 行为,我删除了你所有的 media queries,只做了一个指向你的 <ul> 和你的 徽标,似乎是这个例子中的焦点。

请查看我在 /* Media Start/* Media End */ 之间所做的 CSS 更改。另外,我的建议是,如果您要调整导航栏,则使用 display: flex; 而不是 inline-flex。然后您可以添加 justify-content: space-between; 以正确对齐您的 nav 组件。接下来,这只是出于偏好,但我不建议将 li'smargin-left 间隔开,因为那样你会在“壁炉”<li> 上得到左边距,这只是不必要的边距。我使用 gap: 10px; 作为替代。

请同时查看徽标的更改。有了这个正确的 media-queries 结构,我相信你会更容易操作。在无法看到您的图片或图片大小的情况下,很难为您提供准确的 height & width,因此请根据需要调整 25px。最后,在徽标或图像上设置 font-sizes 没有用,除非图像或徽标的包含父级 div 中有文本元素。

* {
     margin: 0;
     padding: 0;
     box-sizing: border-box;
     font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
 ::-webkit-scrollbar {
     width: 10px;
}
 ::-webkit-scrollbar-track {
     background: #f1f1f1;
}
 ::-webkit-scrollbar-thumb {
     background: #888;
}
 ::selection{
     background: rgb(0,123,255,0.3);
}
 .content{
     max-width: 1250px;
     margin: auto;
     padding: 0 30px;
}
/* Nav start*/
 .navbar{
     position: fixed;
     width: 100%;
     z-index: 2;
     padding: 25px 0;
     transition: all 0.3s ease;
     background-color: black;
}
 .navbar.sticky{
     background: black;
     padding: 10px 0;
     box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.1);
}
 .navbar .content{
     display: flex;
     align-items: center;
     justify-content: space-between;
}
 .navbar .logo a{
     color: #fff;
     font-size: 30px;
     font-weight: 600;
     text-decoration: none;
}
 .navbar .menu-list{
     display: flex;
     justify-content: space-between;
     gap: 10px;
}
 .menu-list li{
     list-style: none;
}
 .menu-list li a{
     color: #fff;
     font-size: 18px;
     font-weight: 500;
     text-decoration: none;
     transition: all 0.3s ease;
}
 .menu-list li a:hover{
     color: #007bff;
}
 .banner{
     height: 100vh;
     background-position: center;
     background-attachment: fixed;
}
 .about{
     padding: 30px 0;
}
 .about .title{
     font-size: 38px;
     font-weight: 700;
}
 .about p{
     padding-top: 20px;
     text-align: justify;
}
 .icon{
     color: #fff;
     font-size: 20px;
     cursor: pointer;
     display: none;
}
 .menu-list .cancel-btn{
     position: absolute;
     right: 30px;
     top: 20px;
}
 .cta {
     padding: 9px 25px;
     background-color: rgba(0, 136, 169, 1);
     border: none;
     border-radius: 50px;
     cursor: pointer;
     transition: background-color 0.3s ease 0s;
}
 .cta:hover {
     background-color: rgba(0, 136, 169, 0.8);
}
/* Nav end*/

/* Media Start */

@media only screen and (max-width: 800px) {
  ul.menu-list li a {
    font-size: 10px;
  }
  
  .logo {
    width: 25px;
    height: 25px;
  }
}

/* Media End */
<nav class="navbar">
        <div class="content">
          <div class="logo">
            <a href="/index.html" ><img src="images/logo-villa-dor.jpg" width="100%"></a>
          </div>
          <ul class="menu-list">
            <div class="icon cancel-btn">
              <i class="fas fa-times"></i>
            </div>
              <li><a href="/fireplaces.html">Fireplaces</a></li>
              <li><a href="/floorings.html">Floorings</a></li>
              <li><a href="/iron_works.html">IronWorks</a></li>
              <li><a href="/ornaments.html">Ornaments</a></li>
              <li><a href="/Woodwork.html">Woodwork</a></li>
              <li><a href="/Radiators.html">Radiators</a></li>
              <li><a href="/luminairy.html">Luminary</a></li>
              <li><a href="/miscellaneous.html">Miscellaneous</a></li>
          </ul>
          <div class="icon menu-btn">
            <i class="fas fa-bars"></i>
          </div>
        </div>
      </nav>

编辑:

.navbar .content {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    align-content: center;
}

然后我会像这样添加两个媒体查询:

@media only screen and (max-width: 1060px) {
    .menu-list li a {
      font-size: 13px;
    }
}

@media only screen and (max-width: 945px) {
    .menu-list li a {
       font-size: 11.5px;
    }
}