【问题标题】:Bug in navigation bar - Gap from top of viewport导航栏中的错误 - 视口顶部的间隙
【发布时间】:2019-04-17 00:47:49
【问题描述】:

我正在重新排列导航栏以在左侧显示图像,在右侧显示链接,并且我的导航栏出现了一些问题。

这个错误只出现在两个页面上,所以我想可能是因为我附加了不同的 CSS 文件。我查看了两者的代码,除了正文之外没有任何边距或填充。 栏也是固定的

我尝试了[导航栏按钮顶部和侧面的间隙][1],但没有帮助。 很抱歉,因为它有很多代码,非常感谢您的时间

 

   * {
      font-family: arial, sans-serif;
      box-sizing: border-box;
    }

    html,
    body {
      margin: 0;
      padding: 0;
    }

    a {
      text-decoration: none;
      color: black;
    }

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

    .nav {
      margin-left: auto;
      background-color: rgba(255, 255, 255, .8);
      border-radius: 0px;
      border: none;
      margin: 0;
      padding: 0;
      display: flex;
    }

    .item {
      color: black;
      font-weight: bold;
      text-transform: uppercase;
      font-size: 15px;
      margin-left: 30px;
      margin-right: 30px;
    }

    .submenu {
      display: none;
      flex-wrap: wrap;
      align-items: center;
      align-text: center;
      position: absolute;
      padding-top: 107px;
      padding: 10px;
      left: 0;
      right: 0;
      text-transform: uppercase;
      z-index: 1;
      background-color: #2F4F4F;
      color: white;
      justify-content: space-evenly;
    }

    .submenu li {
      margin-left: 6%;
      width: 19%;
      padding: 5px;
    }

    .item.has-children:hover .submenu {
      display: flex;
      align-items: center;
      flex-direction: row;
      justify-content: left;
      font-size: 15px;
      flex-wrap: wrap;
      flex: 1 1 calc(25% - 80px);
      color: black;
      background-color: rgba(255, 255, 255, .8);
    }

    ul {
      list-style: none;
      padding: 0;
    }

    * {
      text-align: center;
    }

    body {
      margin-top: 150px;
      color: #7a9ba6;
      font-size: 20px;
    }

    a body {
      color: #90949b;
      font-size: 20px;
      text-decoration: none;
    }

    h1 {
      font-size: 25px;
      color: #415b76;
    }

    .cyan {
      color: cyan;
      background-color: #233656;
      border-radius: 5px;
      padding: 3px;
    }

    .magenta {
      color: magenta;
      background-color: #233656;
      border-radius: 5px;
      padding: 3px;
    }

    .yellow {
      color: yellow;
      background-color: #233656;
      border-radius: 5px;
      padding: 3px;
    }

    .key {
      color: black;
      border-radius: 5px;
      padding: 3px;
    }
    <nav class="nav-wrapper">
      <a href="index.html" style="margin-left: 75px; margin-top: 7px;">
        <img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" align="left" />
      </a>

      <ul class="nav">
        <li class="item has-children"><a href="Printing.html">Printing</a>
          <!--		<ul class="submenu">
    				<li>Labels & Stickers</li>
    				<li>Banners</li>
    				<li>A-Frame</li>
    				<li>Menu Boards</li>
    				<li>Takeout Menus</li>
    				<li>Business Cards</li>
    				<li>Dine-In Menus</li>
    				<li>Posters</li>
    				<li>Envelopes</li>
    				<li>Chinese Wedding Cards</li>
    				<li>Flyers</li>
    				<li>Letterheads</li>
    				<li>Brochures</li>
    				<li>Vinyl</li>
    				<li>NCR Forms</li>
    				<li>Catalogues</li>
    			</ul> -->
        </li>
        <li class="item has-children"><a href="Graphic Design.html">Graphic Design</a>
          <!--		<ul class="submenu">
    				<li>Logo Design</li>
    				<li>Ads/Flyers/Promotions</li>
    				<li style="text-align: center;">Menu Boards<br>
    					(Digital & Boards)</li>
    				<li style="text-align: center;">Restaurant Menus<br>
    					(Takeout & Dine-In)</li>
    			</ul>-->
        </li>
        <li class="item has-children">Chinese Calendars
          <ul class="submenu">
            <li><a href="Calendars/Cane Wallscroll Calendars.html">Cane Wallscroll Calendars</a></li>
            <li><a href="Calendars/Wall Calendars.html">Wall Calendars</a></li>
            <li><a href="Calendars/Mini Calendars.html">Mini Calendars</a></li>
            <li><a href="Calendars/Desk Calendars.html">Desk Calendars</a></li>
            <li><a href="Calendars/Special Desk Calendars.html">Special Desk Calendars</a></li>
            <li><a href="Calendars/Red Packet.html">Red Packet</a></li>
            <li><a href="Calendars/More.html">More Calendars</a></li>
          </ul>
        </li>
        <li class="item" style="color: #4D4D4D;">FAQS</li>
        <li class="item"><a href="Contact Us.html">Contact Us</a></li>
      </ul>
    </nav>

    <body>

      <h1>What is offset printing?</h1>

      Offset printing refer to lithography in general. Which produce the highest quality output of any printing process available today.<br> Because of the fragility nature of the printing plate used in lithography, the process is best suit for short to medium
      run jobs.

      <h1>What is PMS?</h1>

      Pantone Matching System (PMS) is a standard set of color palette that was created to allow a way to describe a color.<br> For more information, see <a href="www.pantone.com" style="color: #4D4D4D;">www.pantone.com</a>.

      <h1>What is process colors?</h1>

      Process colors are <span class="cyan">Cyan</span>, <span class="magenta">Magenta</span>, <span class="yellow">Yellow</span> and <span class="key">Black</span>.<br> By overlapping dot patterns in those 4 colors, about 70% of all the visible colors can
      be reproduce.

      <h1>What is color matching?</h1>

      Since every monitor, graphic card, printer have their own characteristic when displaying color, the colors may look very different in different system.<br> In order to counter those short coming, color matching software is used to calibrate input/output
      devises like monitor, scanner, printer etc...<br> For more information, see <a href="www.datacolor.com" style="color: #4D4D4D;">www.datacolor.com</a>.

      <h1>How to send graphic files?</h1>

      We accept files in Press Quality PDF format (Hi-Res, CMYK).<br> Make sure you embed all fonts and graphics file you used with your document. A hardcopy print out would be very helpful.
  [1]: https://stackoverflow.com/questions/49276641/gaps-at-the-top-and-side-of-navigation-bar-buttons

【问题讨论】:

    标签: html css


    【解决方案1】:

     
    
       * {
          font-family: arial, sans-serif;
          box-sizing: border-box;
        }
    
        html,
        body {
          margin: 0;
          padding: 0;
        }
    
        a {
          text-decoration: none;
          color: black;
        }
    
        .nav-wrapper {
          width: 100%;
          position: fixed;
          display: flex;
          top: 0;
          align-items: center;
          justify-content: space-between;
        }
    
        .nav {
          margin-left: auto;
          background-color: rgba(255, 255, 255, .8);
          border-radius: 0px;
          border: none;
          margin: 0;
          padding: 0;
          display: flex;
        }
    
        .item {
          color: black;
          font-weight: bold;
          text-transform: uppercase;
          font-size: 15px;
          margin-left: 30px;
          margin-right: 30px;
        }
    
        .submenu {
          display: none;
          flex-wrap: wrap;
          align-items: center;
          align-text: center;
          position: absolute;
          padding-top: 107px;
          padding: 10px;
          left: 0;
          right: 0;
          text-transform: uppercase;
          z-index: 1;
          background-color: #2F4F4F;
          color: white;
          justify-content: space-evenly;
        }
    
        .submenu li {
          margin-left: 6%;
          width: 19%;
          padding: 5px;
        }
    
        .item.has-children:hover .submenu {
          display: flex;
          align-items: center;
          flex-direction: row;
          justify-content: left;
          font-size: 15px;
          flex-wrap: wrap;
          flex: 1 1 calc(25% - 80px);
          color: black;
          background-color: rgba(255, 255, 255, .8);
        }
    
        ul {
          list-style: none;
          padding: 0;
        }
    
        * {
          text-align: center;
        }
    
        body {
          margin-top: 150px;
          color: #7a9ba6;
          font-size: 20px;
        }
    
        a body {
          color: #90949b;
          font-size: 20px;
          text-decoration: none;
        }
    
        h1 {
          font-size: 25px;
          color: #415b76;
        }
    
        .cyan {
          color: cyan;
          background-color: #233656;
          border-radius: 5px;
          padding: 3px;
        }
    
        .magenta {
          color: magenta;
          background-color: #233656;
          border-radius: 5px;
          padding: 3px;
        }
    
        .yellow {
          color: yellow;
          background-color: #233656;
          border-radius: 5px;
          padding: 3px;
        }
    
        .key {
          color: black;
          border-radius: 5px;
          padding: 3px;
        }
        <nav class="nav-wrapper">
          <a href="index.html" style="margin-left: 75px; margin-top: 7px;">
            <img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" align="left" />
          </a>
    
          <ul class="nav">
            <li class="item has-children"><a href="Printing.html">Printing</a>
              <!--		<ul class="submenu">
        				<li>Labels & Stickers</li>
        				<li>Banners</li>
        				<li>A-Frame</li>
        				<li>Menu Boards</li>
        				<li>Takeout Menus</li>
        				<li>Business Cards</li>
        				<li>Dine-In Menus</li>
        				<li>Posters</li>
        				<li>Envelopes</li>
        				<li>Chinese Wedding Cards</li>
        				<li>Flyers</li>
        				<li>Letterheads</li>
        				<li>Brochures</li>
        				<li>Vinyl</li>
        				<li>NCR Forms</li>
        				<li>Catalogues</li>
        			</ul> -->
            </li>
            <li class="item has-children"><a href="Graphic Design.html">Graphic Design</a>
              <!--		<ul class="submenu">
        				<li>Logo Design</li>
        				<li>Ads/Flyers/Promotions</li>
        				<li style="text-align: center;">Menu Boards<br>
        					(Digital & Boards)</li>
        				<li style="text-align: center;">Restaurant Menus<br>
        					(Takeout & Dine-In)</li>
        			</ul>-->
            </li>
            <li class="item has-children">Chinese Calendars
              <ul class="submenu">
                <li><a href="Calendars/Cane Wallscroll Calendars.html">Cane Wallscroll Calendars</a></li>
                <li><a href="Calendars/Wall Calendars.html">Wall Calendars</a></li>
                <li><a href="Calendars/Mini Calendars.html">Mini Calendars</a></li>
                <li><a href="Calendars/Desk Calendars.html">Desk Calendars</a></li>
                <li><a href="Calendars/Special Desk Calendars.html">Special Desk Calendars</a></li>
                <li><a href="Calendars/Red Packet.html">Red Packet</a></li>
                <li><a href="Calendars/More.html">More Calendars</a></li>
              </ul>
            </li>
            <li class="item" style="color: #4D4D4D;">FAQS</li>
            <li class="item"><a href="Contact Us.html">Contact Us</a></li>
          </ul>
        </nav>
    
        <body>
    
          <h1>What is offset printing?</h1>
    
          Offset printing refer to lithography in general. Which produce the highest quality output of any printing process available today.<br> Because of the fragility nature of the printing plate used in lithography, the process is best suit for short to medium
          run jobs.
    
          <h1>What is PMS?</h1>
    
          Pantone Matching System (PMS) is a standard set of color palette that was created to allow a way to describe a color.<br> For more information, see <a href="www.pantone.com" style="color: #4D4D4D;">www.pantone.com</a>.
    
          <h1>What is process colors?</h1>
    
          Process colors are <span class="cyan">Cyan</span>, <span class="magenta">Magenta</span>, <span class="yellow">Yellow</span> and <span class="key">Black</span>.<br> By overlapping dot patterns in those 4 colors, about 70% of all the visible colors can
          be reproduce.
    
          <h1>What is color matching?</h1>
    
          Since every monitor, graphic card, printer have their own characteristic when displaying color, the colors may look very different in different system.<br> In order to counter those short coming, color matching software is used to calibrate input/output
          devises like monitor, scanner, printer etc...<br> For more information, see <a href="www.datacolor.com" style="color: #4D4D4D;">www.datacolor.com</a>.
    
          <h1>How to send graphic files?</h1>
    
          We accept files in Press Quality PDF format (Hi-Res, CMYK).<br> Make sure you embed all fonts and graphics file you used with your document. A hardcopy print out would be very helpful.
    enter code here
    

    只需将top:0 添加到`.nav-wrapper 看这里不错。差距消失了

    【讨论】:

      【解决方案2】:

      我可以看到顶部边距为 150 像素的主体;

      body {
          margin-top: 150px;
          color: #7a9ba6;
          font-size: 20px;
      }
      

      这可能是问题

      【讨论】:

      • 但这不仅适用于身体吗?导航是固定的,html边距设置为0
      【解决方案3】:

      我不确定我是否清楚地了解您想要实现的目标。

      如果您希望导航栏始终固定在顶部。您可以将top: 0 放在具有position: fixed.nav-wrapper 上,否则它将设置在与其父级相同的位置,即具有margin-top: 150pxbody

      https://codepen.io/krugtep/pen/GLyvLW

      【讨论】:

        【解决方案4】:

        nav 是 body 的子节点,所以即使 position: fixed;您必须设置 top: 75px 或您希望元素与页面顶部的任何距离。否则会受到 body margin-top 的影响。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-08-22
          • 2014-09-03
          • 1970-01-01
          • 1970-01-01
          • 2014-01-12
          • 2016-01-23
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多