javascript - 我怎样才能让标志不超过固定的导航栏?

标签 javascript html css

如何让 Logo 不超过固定的导航栏?正如您在图像中看到的那样, Logo 越过固定的导航栏。如何使 div 不受固定导航栏的影响?无论如何,您是否可以让它不超过导航栏。当 Logo 位于导航栏前面时,您会在下面看到图像。 image

.content {
      width: 94%;
      margin: 4em auto;
      font-size: 20px;
      line-height: 30px;
      text-align: justify;
}

.logo {
      line-height: 60px;
      position: fixed;
      float: left;
      margin: 16px 46px;
      color: #fff;
      font-weight: bold;
      font-size: 20px;
      letter-spacing: 2px;
}

nav {
      position: fixed;
      width: 100%;
      line-height: 60px;
}

nav ul {
      line-height: 60px;
      list-style: none;
      background: rgba(0, 0, 0, 0);
      overflow: hidden;
      color: #fff;
      padding: 0;
      text-align: right;
      margin: 0;
      padding-right: 40px;
      transition: 1s;
}

nav.black ul {
      background: #fff;
}

nav ul li {
      display: inline-block;
      padding: 16px 40px;;
}

nav ul li a {
	font-family: 'Josefin Sans', sans-serif;
    font-size: 14px;
    color: #000;
    font-weight: 600;
    text-transform: uppercase;
	text-decoration: none;
}

.menu-icon {
      line-height: 60px;
      width: 100%;
      background: #000;
      text-align: right;
      box-sizing: border-box;
      padding: 15px 24px;
      cursor: pointer;
      color: #fff;
      display: none;
}
.slide-right {
    display: block;
    left: 30%;
	right:50%;
	top: 25%;
	position: absolute;
	-webkit-animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
	        animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
	  }
	  .image-desc {
		  width: 750px;
		  height: 100px;
		  left: 17%;
	      right:50%;
		  position: absolute;
	      top: 55%;
		  color: #fff;
	  }
	 .image-desc h1 {
    font-family: 'Josefin Sans', sans-serif;
    font-size: 30px;
    font-weight: 300;
    color: #555;
	-webkit-animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
	        animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
	  }
<header>
                  <nav>
                        <div class="menu-icon">
                              <i class="fa fa-bars fa-2x"></i>
                        </div>
                        <div class="logo">
                             <img src="/TeknikSnabben/assets/image/logo.png">
                        </div>
                        <div class="menu">
                              <ul>
                                    <li><a href="#">START</a></li>
                                    <li><a href="#">TJĂ„NSTER</a></li>
                                    <li><a href="#">OM OSS</a></li>
                                    <li><a href="#">KONTAKT</a></li>
                              </ul>
                        </div>
                  </nav>
				    <div class="slide-right" >
				 <img src="/TeknikSnabben/assets/image/logo2.png">
				  </div>
				  <div class="image-desc"><h1> VI HJÄLPER DIG MED DIN TEKNIK I HEMMET </h1>
				              </header>
				

最佳答案

给你的 nav 一个更高的 z-index 和一个背景色:

nav {
  position: fixed;
  width: 100%;
  line-height: 60px;
  z-index: 10;
    background-color: white;
}

.content {
  width: 94%;
  margin: 4em auto;
  font-size: 20px;
  line-height: 30px;
  text-align: justify;
}

.logo {
  line-height: 60px;
  position: fixed;
  float: left;
  margin: 16px 46px;
  color: #fff;
  font-weight: bold;
  font-size: 20px;
  letter-spacing: 2px;
}

nav {
  position: fixed;
  width: 100%;
  line-height: 60px;
  z-index: 10;
  background-color: white;
}

nav ul {
  line-height: 60px;
  list-style: none;
  background: rgba(0, 0, 0, 0);
  overflow: hidden;
  color: #fff;
  padding: 0;
  text-align: right;
  margin: 0;
  padding-right: 40px;
  transition: 1s;
}

nav.black ul {
  background: #fff;
}

nav ul li {
  display: inline-block;
  padding: 16px 40px;
  ;
}

nav ul li a {
  font-family: 'Josefin Sans', sans-serif;
  font-size: 14px;
  color: #000;
  font-weight: 600;
  text-transform: uppercase;
  text-decoration: none;
}

.menu-icon {
  line-height: 60px;
  width: 100%;
  background: #000;
  text-align: right;
  box-sizing: border-box;
  padding: 15px 24px;
  cursor: pointer;
  color: #fff;
  display: none;
}

.slide-right {
  display: block;
  left: 30%;
  right: 50%;
  top: 25%;
  position: absolute;
  -webkit-animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
  animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
}

.image-desc {
  width: 750px;
  height: 100px;
  left: 17%;
  right: 50%;
  position: absolute;
  top: 55%;
  color: #fff;
}

.image-desc h1 {
  font-family: 'Josefin Sans', sans-serif;
  font-size: 30px;
  font-weight: 300;
  color: #555;
  -webkit-animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
  animation: slide-right 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
}
<header>
  <nav>
    <div class="menu-icon">
      <i class="fa fa-bars fa-2x"></i>
    </div>
    <div class="logo">
      <img src="https://picsum.photos/80/80">
    </div>
    <div class="menu">
      <ul>
        <li><a href="#">START</a></li>
        <li><a href="#">TJĂ„NSTER</a></li>
        <li><a href="#">OM OSS</a></li>
        <li><a href="#">KONTAKT</a></li>
      </ul>
    </div>
  </nav>
  <div class="slide-right">
    <img src="https://picsum.photos/200/200">
  </div>
  <div class="image-desc">
    <h1> VI HJÄLPER DIG MED DIN TEKNIK I HEMMET </h1>
  </div>  
</header>

关于javascript - 我怎样才能让标志不超过固定的导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53732455/

相关文章:

CSS:将按钮列表水平放置在一个div中

javascript - 查找 Javascript 错误

javascript - 显示 div onscroll 但永久隐藏 div onclick

javascript - polymer :未捕获类型错误:无法读取未定义的属性 'persistent'

php - 使用 css 在 php/styling 中分配类

html - 无法用边框水平放置我的所有图片,其中一张不断被压低

html - 技巧网页设计(全屏和非全屏元素)

javascript - CodeceptJS/Puppeteer 无法识别 'if' 语句

javascript - 自动登录

CSS 中的 Python 变量