gpt4 book ai didi

javascript - CSS NavBar 过渡问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:58:49 24 4
gpt4 key购买 nike

我的导航栏悬停效果特别是过渡有问题(第 109/110 行)。本质上,我希望鼠标悬停在哪个链接上以提高(边距增加 2%),而其他链接保持边距为 0。问题是,每当我将鼠标悬停在其中任何一个上时,所有链接边距都会增加 2%。如果我违反了任何发帖规则和/或如果这个问题根本不清楚,这是我第一次发帖,对于困惑的代码深表歉意。我玩了一会儿,想不通。此外,如果它更简单,我可以弄清楚如何使用 javascript 来完成它。
干杯

<!DOCTYPE html>
<html>

<head>
<title>
Atticus Products
</title>

<script src="http://code.jquery.com
/jquery-1.9.1.js">
</script>
<script>


/*

$(document).ready(function(){
$("a").hover(function(){
$("a").animate({up:'250px'});
});
});
*/
</script>



<style>
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
font-size:100%;
background-color:#6ec247;
font-family: CaeciliaLTStd75Bold,Helvetica,Arial,Sans-serif;
}


#wrapper {
margin: 0 auto;
width: 50%;
height: 100%;
position: relative;
}

/*Header: Contains Logo and NavBar*/
#header {
border-bottom: 8px solid #f2f2f2;
overflow:hidden;
height: auto;
position:relative;
clear:both;
height:auto;
margin:0;
display:block;
}

#logoName {

max-width: 100%;
width:40%;
float:left;
height:150px;
}

#logoName a {
position:absolute;
bottom:0;
color:#FFFFFF;
text-decoration: none;
font-size:3em;
font-weight: bold;
}


/*NavBar*/
#nav {
margin: 0;
padding: 0;
list-style: none;
text-align: right;
right:0;
width:60%;
float:right;
position:absolute;
bottom:0;
}

#nav li {
display: inline;


}

#nav li a {
display: inline-block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
font-size:1em;
margin-bottom:0;
}


#nav li a:hover {
color: #c00;
background-color: #000000;
opacity:0.5;
transition-property: margin-bottom;
transition-duration:4s;
margin-bottom:2%
/*this is where the problem is*/
}


/*Content: Contains Container1, LogoWords and Logo1*/

#content {
height: 60%;
text-align: center;
/*background-color: #4d8e2f;*/
color:#FFFFFF;
margin:0;
top:0;
display:relative;
font-weight: bold;
}

#container1 {
display: block;
max-width: 100%;
position:relative;
height:40.5%;
width:100%;
margin:0;
background-color:#6ec247 ;
z-index:0;
border-bottom: 8px solid #f2f2f2;
}

#logoWords{
z-index:1;
display:block;
position:absolute;
width:auto;
height:auto;
top:18.5%;
right:0;
color:#FFFFFF;
text-decoration: none;
font-size:2.5em;
font-weight: bold;
text-align:left;
}



#logo1 {
display:block;
z-index:1;
position:absolute;
left:0;
top:18.5%;
width:auto;
height:auto;
}



#content{
background-color:#6ec247 ;
}


#content p {
margin:0;
}


#footer {
height:10%;
width: 100%;
position: absolute;
bottom: 0;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}




</style>
</head>
<body>

<div id="wrapper">
<div id="header">


<ul id="nav">
<li><a href="index.html">About</a></li>
<li><a href="ourapproach.html">Our Approach</a></li>
<li><a href="careers.html">Careers</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>



<div id="logoName">
<a href="index.html">Atticus <br>Products</br></a>
</div>




</div>

<div id="content">

<div id="container1">
</div>

<img id="logo1" src="image/justlogo.png" alt="logo" width="207"
height="214">

<div id="logoWords">
<p><br>We find the people</br> that make your company succeed</p>
</div>



<div id="content">
<p>
<br>Careers with Atticus</br>

</p>
</div>
</div>


<div id="footer">
<p>bam</p>
</div>

</div>
</body>
</html>

最佳答案

您的问题出在您的 jQuery 中。因为你有 $('a').animate 它会影响页面上的每个 a 元素。您可以通过将 'a' 更改为不带引号的 'this' 来解决这个问题。

$(document).ready(function(){
$("a").hover(function(){
$(this).animate({up:'250px'});
});
});

这只会影响悬停的元素。祝你好运。

关于javascript - CSS NavBar 过渡问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16681999/

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