html - 半透明导航栏,背景图片在 : css, 后面 没有 javascript

标签 html css

<分区>

有点新手,但尝试做一些我认为会很简单的事情;我想要一个没有边距的全屏背景图片,可以缩放到屏幕大小(我正在使用背景:封面;目前)但我想在图片顶部放置一个半透明的导航栏顶部,包含一个水平菜单。

到目前为止,我已经有了导航栏,但图片要么位于导航栏上方,要么位于其下方,而不是直接位于顶部。这样做的最佳方法是什么,是 z-index 值,还是我应该做一些简单的事情来将一个 div (.nav) 放在另一个 (.background-img) 上?

非常感谢任何帮助,抱歉,如果这有点含糊,但我是 html 和 css 的新手!!

最佳答案

尝试使用 position:fixed; 如果你还没有。做这样的事情:

div.background-img {
    background-image: url('background.png');
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    left:0;
    right:0;
    bottom:0;
    background-size:cover;
}
div.nav {
    position: fixed;
    background: rgba(255, 255, 255, 0.7);
    top: 0;
    left: 0;
    right:0;
    padding: 16px;
}

观看演示 ​​here

关于html - 半透明导航栏,背景图片在 : css, 后面 没有 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25083836/

相关文章:

jquery - 伪类 :empty and :not(:empty) - make it hide() and show() regarding content (jquery, mvc 5, asp.net, css)

html - iOS选择圆 Angular 背景色

html - 有相对于​​ root 的链接?

html - Bootstrap 3 选择下拉错位

html - 在创建特定的固定 CSS 网格布局方面寻求帮助

css - 使用 Blueprint CSS,我们如何设置 3 列的样式,每列 300 像素宽,中间有 15 像素的边距或填充?

html - 对齐表格单元格中的按钮标签

jquery - 一个 div 中的多个 div——水平滚动

html - meteor - 更改不同模板的 HTML <head> 部分的内容?

javascript - 摆脱嵌入式媒体的额外间距?