繁体   English   中英

固定导航栏即使使用 position 也不起作用:固定在 css

[英]Fixed navigation bar would not work even using position: fixed in css

我在将固定导航置于页面顶部时遇到问题。 我已经尝试过 position: fixed with top: 0 and width: 100%,但是在导航栏底部放置引导程序的图像是重叠的。 这是我的 HTML 和 CSS 的完整代码。几个小时以来一直试图通过资源找到这个问题,但我仍然不知道问题出在哪里。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<link rel="stylesheet" href="testing.css">
<!--SOCIAL MEDIA ICON STYLESHEET-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>J[a]Son | Art & Code </title>
<div class="top">
  <div class = "center">
    <h><a href="J.html">J[a]son</a></h>
    <p>Personal Blog</p>
  </div>
    <div class = "top">
      <div class = "logos">
        <a href="https://www.facebook.com/jason.ahn.129/" class="fa fa-facebook"></a>
        <a href="https://www.linkedin.com/in/jasonja-ahn/" class="fa fa-twitter"></a>
      </div>
      <div class = "nav">
        <ul>
          <li><a href="J.html">HOME</a></li>
          <li><a href="#photography">PHOTOGRAPHY</a></li>
          <li><a href="#coding">CODING</a></li>
          <li><a href="#about">ABOUT</a></li>
        </ul>
      </div>
    </div>
</div>
前面一个后面一个

这是 CSS:

 body { background-color: rgb(241, 233, 233); } html, body { height: 90%; margin: 0; padding: 0; }.top { margin: auto; padding: 0.5em; overflow: hidden; background-color: #0a0908; width: 100%; top: 0; position: fixed; display: block; /*position: -webkit-sticky; position: sticky;*/ font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; }.top p { color: white; font-size: 10px; font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif }.center { text-align: center; }.center a{ color: rgb(224, 224, 228); font-size: 1.5em; }.center a:hover{ text-decoration: none; color: rgb(224, 224, 228); }.nav a { color: white; }.nav ul { list-style-type: none; display: inline-block; }.nav li { display: inline; }.nav { float: right; }.logos { float: left; }.logos a { color: white; }.top { clear: both; overflow: hidden; }.nav li a { color: white; text-align: center; padding: 20px 15px; text-decoration: none; font-size: 13px; position: relative; }.nav li a:hover::after, a:focus::after { opacity: 1; transform: translateY(-2px); }.nav li a::after { position: absolute; top: 100%; left: 0; width: 100%; height: 1px; background: white; content: ''; opacity: 0; transition: opacity 0.2s, transform 0.2s; transform: translateY(4px); }.testing { padding: 0; display: block; margin: auto; max-height: auto; max-width: 50%; } img { display: block; margin-left: auto; margin-right: auto; width: auto; height: 600px; }.carousel-inner p { text-align: center; }.carousel-control-prev-icon { background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23000' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E"); }.carousel-control-next-icon { background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23000' viewBox='0 0 8 8'%3E%3Cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E"); }

尝试将z-index:100添加到导航栏,使其位于所有其他元素的前面。 此外,如果您将z-index添加到其他元素,则该数字应低于 100 或您为z-index指定的数字

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM