.dropdown:hover .dropbtn{...}
中的转换正在改变页面大小,当.nav li a:hover {...}
上的悬停没有做好时。
我试图改变位置,但它没有帮助。我不知道还能做些什么来解决这个问题。
html, body {
margin: 0;
padding: 0;
}
.container {
max-width: 940px;
margin: 0 auto;
padding: 5px;
}
.header {
background-color: #333;
}
.nav {
list-style-type: none;
margin: 0;
padding: 20px 0;
letter-spacing: 2.6px;
}
.nav li {
display: inline-block;
}
.nav li a {
text-decoration: none;
color: #fff;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 12px;
margin-right: 25px;
text-transform: uppercase;
}
.dropdown {
background-color: #333;
position: relative;
display: inline-block;
}
.dropbtn {
text-decoration: none;
background-color: #333;
color: #fff;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 12px;
margin-right: 25px;
border: none;
cursor: pointer;
text-transform: uppercase;
letter-spacing: 2.6px;
}
.dropdown-content {
display: none;
position: fixed;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #ffffff;
color: #333;
transition: 0.6s;
padding: 24px 10px;
}
.nav li a:hover {
transition: 0.6s;
background-color: #ffffff;
color: #333;
font-weight: 900;
padding: 24px 10px;
font-size: 12px;
cursor: pointer;
}

<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Raleway:400, 600" rel="stylesheet">
<link href="stylesheet.css" type="text/css" rel="stylesheet">
<script type='text/javascript' src='script.js'></script>
<script src="jquery-3.1.1.min.js"></script>
<title>Smart-Home</title>
</head>
<body>
<div class="header">
<div class="container">
<ul class="nav">
<li><a href ="indexKontakt.html"> O firmie </a></li>
<div class="dropdown">
<li><a class="dropbtn" href ="indexKontakt.html"> Produkty </a></li>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<li><a href ="indexKontakt.html"> Nasi partnerzy </a></li>
<li><a href ="indexKontakt.html"> Kontakt </a></li>
</ul>
</div>
</div>
</body>
</html>
&#13;
答案 0 :(得分:2)
以下是更新的代码段
html, body {
margin: 0;
padding: 0;
}
.container {
max-width: 940px;
margin: 0 auto;
padding: 5px;
}
.header {
background-color: #333;
}
.nav {
list-style-type: none;
margin: 0;
padding: 20px 0;
letter-spacing: 2.6px;
}
.nav li {
display: inline-block;
}
.nav li > a {
text-decoration: none;
color: #fff;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 12px;
margin-right: 25px;
text-transform: uppercase;
}
.dropdown {
background-color: #333;
position: relative;
display: inline-block;
}
.dropbtn {
text-decoration: none;
background-color: #333;
color: #fff;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 12px;
margin-right: 25px;
border: none;
cursor: pointer;
text-transform: uppercase;
letter-spacing: 2.6px;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #ffffff;
color: #333;
transition: 0.6s;
padding: 24px 10px;
}
.nav li > a:hover {
transition: 0.6s;
background-color: #ffffff;
color: #333;
font-weight: 900;
padding: 24px 10px;
font-size: 12px;
cursor: pointer;
}
&#13;
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Raleway:400, 600" rel="stylesheet">
<link href="stylesheet.css" type="text/css" rel="stylesheet">
<script type='text/javascript' src='script.js'></script>
<script src="jquery-3.1.1.min.js"></script>
<title>Smart-Home</title>
</head>
<body>
<div class="header">
<div class="container">
<ul class="nav">
<li><a href ="indexKontakt.html"> O firmie </a></li>
<li><div class="dropdown">
<a class="dropbtn" href ="indexKontakt.html"> Produkty </a>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</li>
<li><a href ="indexKontakt.html"> Nasi partnerzy </a></li>
<li><a href ="indexKontakt.html"> Kontakt </a></li>
</ul>
</div>
</div>
</body>
</html>
&#13;
答案 1 :(得分:1)
请注意实际的变化是......
来自:<button class="dropbtn" href ="indexKontakt.html"> Produkty </button>
于:<a class="dropbtn" href="indexKontakt.html"> Produkty </a>
应该指出的是那个班级&#39; dropbtn&#39;应该删除,并通过ul li
和a
元素完成样式。
还应该注意,可以避免在ul li中嵌套div,并且在他们自己的div容器中通常不需要顶级下拉。
我相信这会更有帮助,因为它有助于了解错误或问题。