【问题标题】:Navbar links not getting smaller导航栏链接没有变小
【发布时间】:2022-01-12 20:41:55
【问题描述】:

我的导航栏出现问题,一旦我将浏览器选项卡变小,文本会保持相同大小,但徽标会越来越小并消失。我怎样才能让它变得更小?如果需要更多信息,我会提供给他们。以下是我的问题的一些示例。 100% width pagePage 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>

【问题讨论】:

    标签: html css image navbar


    【解决方案1】:

    我认为您使用 @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);
        }
    }
    

    【讨论】:

    • Mh 好像没有修复它,在这里我做了一个记录,以便更清楚地了解情况。 youtu.be/drRPmEHCVsQ 所以在这里你可以看到文本没有调整,只有图像可以。我试过你的遮阳篷,但没有修好。
    【解决方案2】:

    我发现您的样式中有一些问题已被证明对您的设计有问题。为了演示 media-queries 的行为,我删除了你所有的 media queries 并只创建了一个指向你的 &lt;ul&gt; 和你的 logo,这似乎是这个例子中的焦点.

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

    请同时查看徽标的更改。有了media-queries 的正确结构,我相信您操作起来会容易得多。由于无法看到您的图像或其大小,因此很难为您提供准确的height &amp; 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;
        }
    }
    

    【讨论】:

    • 感谢您的回复,另一方面,一旦文本变小,文本大小也需要更改,在这种情况下不会。总体而言,似乎没有任何变化,因为当标签缩小并且文本保持其大小时,徽标仍然变小(我觉得它过分了)。
    • @Zcel 您指的是哪个文本? nav links文本“壁炉、地板”等在 800 像素及以下从 18px 更改为 10px。你的标志的高度和宽度是多少?有了这些信息,我可以根据您的需要调整答案。如果您无法向我提供此信息,您能否提供指向实时前端的链接,以便我获得该问题的准确版本?​​
    • 我指的是“壁炉、地板”等文字。徽标的尺寸为 760x260 像素。我也认为这是您所说的字体结束链接prod.liveshare.vsengsaas.visualstudio.com/…
    • 另外,通过更改上面 awnser 中的媒体,汉堡菜单也无法正常工作
    • @Zcel 该链接给了我一个 404。您可以尝试上传您的文件here,这将为您提供临时托管,我可以在其中看到前端。完成后请评论该链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多