我的按钮目标: - 当用户将鼠标悬停在按钮上时,它会变暗。 - 按钮将链接到与index.html相同的文件夹中的不同html文件
我的代码如下:
body {
background-image: url("res/images/space2.jpg");
}
div.wrapper {
width: 720px;
height: 576px;
margin-left: auto;
margin-right: auto;
}
div.banner {
width: 750px;
height: 160px;
position: relative;
top: 0px;
margin-left: auto;
margin-right: auto;
}
div.topnav {
border-radius: 25px;
background: #03023a;
padding: 20px;
width: 700px;
height: 50px;
position: fixed;
}
.button {
background-color: #050462;
border: none;
color: blue;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: #0a07ab;
color: black;
border: 2px solid #07057a;
}
.button1:hover {
background-color: #ffffff;
color: #ffffff;
}
.button2 {
background-color: #0a07ab;
color: black;
border: 2px solid #07057a;
}
.button2:hover {
background-color: #ffffff;
color: #ffffff;
}
.button3 {
background-color: #0a07ab;
color: black;
border: 2px solid #07057a;
}
.button3:hover {
background-color: #ffffff;
color: #ffffff;
}
div.maindiv {
width: 750px;
height: 97px;
position: relative;
top: 0px;
margin-left: auto;
margin-right: auto;
}
div.main {
border-radius: 25px;
background: url(res/images/space.jpg);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 700px;
height: 3000px;
text-align: center;
}
p.welcome {
margin-left: 15px;
margin-right: 15px;
text-indent: 16px;
}

<div class="wrapper">
<div class="banner">
<center>
<img src="res/images/topbanlogo.png" />
</center>
</div>
<div class="topnav">
<center>
<button class="button button1"><a href=
"index.html"><font color="white">Home</font></a></button>
<button class="button button2"><a href=
"downloads.html"><font color="white">Downloads</font>
<button class="button button3"><a href=
"downloads.html"></a><a href=
"downloads.html"></a><a href="uploads.html"><font color=
"white">Uploads</font></a></button></a>
</button>
</center>
</div>
<div class="maindiv"></div>
<div class="main">
<p class="welcome"></p>
<center>
<h1>
<font face="arial" color="white">Easy and simple file downloads.
</font>
</h1>
</center>
<p class="main"></p>
<center>
<p>
<font face="arial" color="white">At Kylosting, we strive to provide the easiest file hosting in the Blockland realm.
</font>
</p>
<p>
<font face="arial" color="white">
<font face="arial" color="white">ph</font>
</font>
</p>
<p>
<font face="arial" color="white">
<font face="arial" color="white">ph</font>
</font>
</p>
<p>
<font face="arial" color="white">
<font face="arial" color="white">ph</font>
</font>
</p>
</center>
</div>
<div class="footer"></div>
</div>
&#13;
如上所述,我对HTML缺乏经验并且将我的代码基于在线示例,所以可能存在一些我做过的noob错误。
答案 0 :(得分:0)
您的按钮工作正常#mainDiv
掩盖了您的#topNav
,因此无法将鼠标悬停在按钮上。您可能需要将topnav的z-index设置为1或2,如下所示:
div.topnav{
border-radius:25px;
background:#03023a;
padding:20px;
width:700px;
height:50px;
position:fixed;
z-index:2;
}
这里还有许多其他问题,你可能也想了解一下你的定位,但按钮工作得很好,只是它们被覆盖了。
答案 1 :(得分:0)
要让您的:hover
州工作,只需向固定z-index
添加.topnav
值,因为#myDiv
覆盖了div.topnav{
border-radius:25px;
background:#03023a;
padding:20px;
width:700px;
height:50px;
position:fixed;
z-index: 1; /*Added*/
}
,需要更高的堆栈索引才能识别你的悬停。
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" href="res/images/favicon.ico" />
<title>
Kylosting
</title>
<meta charset="utf-8" />
<style type="text/css">
/*<![CDATA[*/
body{
background-image: url("res/images/space2.jpg");
}
div.wrapper{
width:720px;
height:576px;
margin-left:auto;
margin-right:auto;
}
div.banner{
width:750px;
height:160px;
position:relative;
top:0px;
margin-left:auto;
margin-right:auto;
}
div.topnav{
border-radius:25px;
background:#03023a;
padding:20px;
width:700px;
height:50px;
position:fixed;
z-index: 1;
top: 20px;
}
.button{
background-color:#050462;
border:none;
color:blue;
padding:16px 32px;
text-align:center;
text-decoration:none;
display:inline-block;
font-size:16px;
margin:4px 2px;
-webkit-transition-duration:0.4s;
transition-duration:0.4s;
cursor:pointer;
}
.button1{
background-color:#0a07ab;
color:black;
border:2px solid #07057a;
}
.button1:hover{
background-color:#ffffff;
color:#ffffff;
}
.button2{
background-color:#0a07ab;
color:black;
border:2px solid #07057a;
}
.button2:hover{
background-color:#ffffff;
color:#ffffff;
}
.button3{
background-color:#0a07ab;
color:black;
border:2px solid #07057a;
}
.button3:hover{
background-color:#ffffff;
color:#ffffff;
}
div.maindiv{
width:750px;
height:97px;
position:relative;
top:0px;
margin-left:auto;
margin-right:auto;
}
div.main{
border-radius:25px;
background:url(res/images/space.jpg);
background-position: left top;
background-repeat: repeat;
padding:20px;
width:700px;
height:3000px;
text-align:center;
}
p.welcome{
margin-left:15px;
margin-right:15px;
text-indent:16px;
}
/*]]>*/
</style>
</head>
<body>
<div class="wrapper">
<div class="banner">
<center>
<img src="res/images/topbanlogo.png" />
</center>
</div>
<div class="topnav">
<center>
<button class="button button1"><a href=
"index.html"><font color="white">Home</font></a></button>
<button class="button button2"><a href=
"downloads.html"><font color="white">Downloads</font>
<button class="button button3"><a href=
"downloads.html"></a><a href=
"downloads.html"></a><a href="uploads.html"><font color=
"white">Uploads</font></a></button></a></button>
</center>
</div>
<div class="maindiv"></div>
<div class="main">
<p class="welcome"></p>
<center>
<h1>
<font face="arial" color="white">Easy and simple file
downloads.</font>
</h1>
</center>
<p class="main"></p>
<center>
<p>
<font face="arial" color="white">At Kylosting, we strive to provide the
easiest file hosting in the Blockland
realm.</font>
</p>
<p>
<font face="arial" color="white"><font face="arial"
color="white">ph</font></font>
</p>
<p>
<font face="arial" color="white"><font face="arial"
color="white">ph</font></font>
</p>
<p>
<font face="arial" color="white"><font face="arial"
color="white">ph</font></font>
</p>
</center>
</div>
<div class="footer"></div>
</div>
</body>
</html>
log