html - 在透明导航栏下方显示网站背景

标签 html css

我需要我的背景图像显示在我的网站透明导航栏下方。图像位于 .header div 下

http://prntscr.com/p2moi0

        <!Navigation Bar>
        <nav>
            <div class="navigation-bar">
                <img class="logo" src="images/logo-black.png">
                <a href="#">Home</a>
                <a href="#">Services</a>
                <a href="#">Pricing</a>
                <a href="#">faq</a>
                <a href="#">Contact</a>
            </div>
        </nav>

        <div class="header">
            <h1>Website development<br> made easy</h1>
            <h3>Not just a business but a reliable business partner</h3>
            <button type="button" class="button button-1">get started</button>
            <button type="button" class="button button-2">get a quote</button>
        </div>
    </body>
.header{
    background-image: url('images/main-background-header.png');
    background-position: center;
    height: 100%;
    background-repeat: no-repeat;
    position: relative;
    top: 0;
    text-align: center; 

    .navigation-bar {
    width: 100%;
    height: 80px;
    background-color: transparent;
    }

最佳答案

要使其正常工作,将 background div 添加到 header 中,height 等于 full header height + 你的导航栏高度 .你的 navbar 应该有一个 -1 的 z-index 并且 background div 应该有一个相对于 absolute 的位置 header :

*{
  margin:0;
  padding:0;
}

.image{
background-image: url('https://picsum.photos/800');
    background-position: center;
    height: calc(100% + 80px);
  width:100%;
    background-repeat: no-repeat;
    position: absolute;
  z-index:-1;
    top: -80px;
    text-align: center; 
}
    .navigation-bar {
    width: 100%;
    height: 80px;
    background-color: transparent;
    }

.header{
  position:relative;
  text-align:center;
  color:white;
  padding:10px 0px;
}
.navigation-bar{
  display:flex;
  background:rgba(255,255,255,0.5);
  align-items:center;
}
.navigation-bar img{
  margin-right:10px;
}

.navigation-bar a{
  margin-left:10px;
  color:white;
  padding:10px;
  text-decoration:none;
}
.navigation-bar a:hover{
  background-color:white;
  color:black;
}
       <!Navigation Bar>
        <nav>
            <div class="navigation-bar">
                <img class="logo" src="images/logo-black.png">
                <a href="#">Home</a>
                <a href="#">Services</a>
                <a href="#">Pricing</a>
                <a href="#">faq</a>
                <a href="#">Contact</a>
            </div>
        </nav>

        <div class="header">
          <div class="image"></div>
            <h1>Website development<br> made easy</h1>
            <h3>Not just a business but a reliable business partner</h3>
            <button type="button" class="button button-1">get started</button>
            <button type="button" class="button button-2">get a quote</button>
        </div>
    </body>

关于html - 在透明导航栏下方显示网站背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57821297/

相关文章:

javascript - 悬停时CSS缩放图像

javascript - 如何在使用 HTML5 pushState 更改浏览器 URL 时处理后退按钮

php - 设计用于 PHP 4 的旧 PhotoRate 2.0 现在不起作用

javascript - 绝对位置,可滚动元素,在内容下方,干扰主要内容的滚动

CSS @import 仅适用于 Retina 显示

javascript - 模拟 Android 浏览器中触摸事件的悬停行为

javascript - 如何在按钮单击事件中隐藏占位符?

javascript - firefox 中的输入按钮不起作用

html - 额外的黑色边框线

html - 如何将表格的文本链接右端与 td 元素对齐