悬停不使用背景图像

问题描述 投票:0回答:2

我有一个带有背景图片的网站但是当我添加一个css导航栏时,悬停标签不起作用。悬停元素可以处理背景图像,但是当我添加背景图像时,它就会产生影响

这是我的代码

HTML

<!DOCTYPE html>
<html>
<head>
    <title>Cool</title>
    <link href="stylesheet.css" "type= "text/css" rel= "stylesheet">
    <link rel="icon" type="image/png" href="icon2.jpg"/>
</head>
<body>
    <div id="background-image">
    <div id="background-overlay">
    <h1>Cool</h1>
            <h2>Vertical Navigation Bar</h2>

            <ul>
            <li><a href="#home">Home</a></li>
            <li><a href="#news">News</a></li>
            <li><a href="#contact">Contact</a></li>
            <li><a href="#about">About</a></li>
            </ul>

            <p>hi</p>
    </div>
    </div>  
</body>
</html>

CSS

*{
z-index:-8;
}
body{
margin:0px;
}
#backround-image{
background-image:url("background.jpg");
background-size:cover;
background-position:center center;
position:relative;
top: 0;
bottom :0;
height: 100vh;
z-index: -10;
}
#backround-overlay{
position: absolute;
background-color: rgba(0,0,0,0.5);
top: 0;
bottom: 0;
height: 100%;
width: 100%;
z-index:-9;
}
h1{
text-align:center;
font-family:arial black;


}
l{
float:left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #f1f1f1;
}

li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}

/* Change the link color on hover */
li a:hover{
background-color: red;
color: black;
}

谢谢你的帮助

托马斯

html css hover background-image
2个回答
0
投票

如果你删除position:relative;从背景图像中解决问题并且不会引起任何怪异。目前这似乎是不必要的造型。


0
投票

如果元素之前已经有了背景,那么看起来悬停对元素背景不起作用。但是,如果要更改元素的背景,可以通过更改其亮度,色调,饱和度来实现。这是一个例子:

          li a:hover {
             filter: brightness(50%);
          }             
© www.soinside.com 2019 - 2024. All rights reserved.