【发布时间】:2018-02-24 05:15:29
【问题描述】:
我正试图了解 CSS。 我找到了一个我想使用的导航菜单,但有些东西还不能正常工作,还有很多让我困惑的东西。
这部分代码中li出现两次有什么原因吗?
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
这部分我完全不明白。 这是否意味着只有选择器的悬停状态,还是意味着 ul、li 和选择器的悬停状态?
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
我一直在关注 w3schools 的 css 教程,但我没有看到任何解释我不理解的东西的东西。 完整代码在这里
/*horizontal navigation style*/
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
padding:0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: left;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding: 10px 0;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
@media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
【问题讨论】:
-
请也发布 HTML 代码。以便我们提供帮助。
-
由于多个选择器可以组合在一起共享同一个声明,选择器必须用逗号分隔。只需查看列表中的最后一个选择器并从右到左阅读。至于不同的模式,这里有一个很好的阅读:w3.org/TR/CSS21/selector.html#pattern-matching
标签: css css-selectors