gpt4 book ai didi

javascript - jQuery .css() 函数和位置 : fixed table 出现问题

转载 作者:行者123 更新时间:2023-11-30 08:52:38 26 4
gpt4 key购买 nike

我正在尝试让一个悬停在页面顶部的表格在您将鼠标悬停在它上面时改变颜色。我在 div 上使用以下 CSS:

#navbar {
width: 100%;
margin: 0;
position: fixed;
top: 0px;
border-spacing: 0;
}

#navbar td {
width: 20%;
background: #3399ff;
padding: 10px;
text-align: center;
font-size: 24px;
font-family: "Verdana", sans-serif;
font-variant: small-caps;
}

#navbar td:hover {
cursor: pointer;
}

这是表格本身:

<table id="navbar">
<tr>
<td data-href="/">
<div>
Home
</div>
</td>
<td data-href="/tribes">
<div>
Tribes
</div>
</td>
<td data-href="/minecraft">
<div>
Minecraft
</div>
</td>
<td data-href="/dynmap">
<div>
Dynmap
</div>
</td>
<td data-href="/links">
<div>
Links
</div>
</td>
</tr>
</table>

这是javascript:

$(document).ready(function () {
$('#edit').click(function () {
$('#editformdiv').slideToggle();
$('#password').focus();
});

$("#navbar td").click(function () {
location.href = this.getAttribute("data-href");
});

$("#navbar td").mouseenter(function () {
$(this).css('background','#33ccff')
});

$('#navbar td').mouseleave(function () {
$(this).css('background','#3399ff');
});
});

这有效,表格卡在页面顶部。但是,表格单元格在悬停时不会改变颜色。我该如何解决这个问题,以便表格单元格在悬停时改变颜色?

编辑:这是整个页面:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home</title>
<script src="/jquery-1.9.1.min.js"></script>
<script src="/scripts.js"></script>
<link rel="stylesheet" type="text/css" href="/stylesheet.css">

<style>
#editcontainer {
width: 100%;
margin-left: auto;
margin-right: auto;
position: fixed;
bottom: 0px;
margin-bottom: 0;
}

#edit {
padding: 4px;
width: 100px;
background-color: #3399ff;
margin-bottom: 0;
text-align: center;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
margin-left: auto;
margin-right: auto;
}

#editformdiv {
margin-top: 0;
border: 2px solid #3399ff;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom: 0;
margin-left: auto;
margin-right: auto;
display: none;
width: 300px;
background-color: white;
}

#editform {
text-align: center;
}

#edit:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table id="navbar">
<tr>
<td data-href="/">
Home
</td>
<td data-href="/tribes">
Tribes
</td>
<td data-href="/minecraft">
Minecraft
</td>
<td data-href="/downloads">
Downloads
</td>
<td data-href="/links">
Links
</td>
</tr>
</table>

<div class="spacer"></div>


<div class="spacer"></div>

<div id="editcontainer">
<div id="edit">EDIT</div>
<div id="editformdiv">
<table id="editform">
<form name="login" method="post" action="edit.php">
<tr>
<td><b>Login</b></td>
<td></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Login"></td>
<td></td>
</tr>
</form>
</table>
</div>
</div>
</body>
</html>

这是整个 CSS 表:

body {
margin: 0;
width: 100%;
font-family: "Verdana", sans-serif;
font-size: 14px;
}

#navbar {
width: 100%;
margin: 0;
position: fixed;
top: 0px;
border-spacing: 0;
}

#navbar td{
width: 20%;
background-color: #3399ff;
padding: 10px;
text-align: center;
font-size: 24px;
font-family: "Verdana", sans-serif;
font-variant: small-caps;
}

#navbar td:hover {
cursor: pointer;
background-color: #33ccff;
}

.spacer {
opacity: 0;
height: 50px;
}

.text {
width: 65%;
padding: 5px;
border: 2px solid #3399ff;
border-radius: 5px;
margin: 10px auto;
}

div h2 {
font-size: 18px;
font-weight: normal;
text-align: center;
}

.text p:last-child {
color: gray;
text-align: center;
}

最佳答案

尝试使用 background-color 而不仅仅是 background

另外,我能知道你为什么不把它放在你的 CSS :hover 中吗?会更好。

关于javascript - jQuery .css() 函数和位置 : fixed table 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16424452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com