gpt4 book ai didi

css - Bootstrap3 pills, hover li items with CSS

转载 作者:太空宇宙 更新时间:2023-11-04 01:15:52 25 4
gpt4 key购买 nike

<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu 1
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Submenu 1-1</a></li>
<li><a href="#">Submenu 1-2</a></li>
<li><a href="#">Submenu 1-3</a></li>
</ul>
</li>

悬停(子菜单)时是否可以使用 CSS 更改 li 元素的背景颜色?

最佳答案

我还不能对 SO 发表评论,所以我需要发布一个正常的答案。如果您可以为每个菜单级别提供自己的级别,请查看以下内容:

* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

nav, .content {
max-width:960px; /* an arbitrary width */
margin: 0 auto; /* center the elements */
}

nav {
margin-top:20px; /* just a little bit of margin */
background: #292929;
}

.top-nav {
font-size:0; /* eliminates whitespace from inline-block*/
}

.top-nav li {
display:inline-block; /* blocks just line up without floats */
width:20%; /* Just a number */
background: #292929;
position:relative; /* sets positioning context for 2nd level menu */
}

.top-nav > li.active > a {
color:green; /* just an active class - not required */
}

.top-nav > li a {
text-decoration:none; /* removes underline */
font-size:24px; /* re-establish a font-size */
line-height:1.5em; /* centers the text vertically*/
text-align:center; /* centeres the text horizontally */
display:block; /* links now fill the block*/
color:lightgrey;

}


.top-nav > li > a {
/* groove type border effect */
border-left: 1px solid black;
border-right: 1px solid #3c3c3c;
border-bottom: 1px solid black;
border-top: 1px solid #3c3c3c;
}


.top-nav > li > a:hover,
.sub-nav > li > a:hover,
.tert-nav > li > a:hover{
/* hover color for links */
color:red;
}

.sub-nav { /* just a class name for 2nd level menus */
position:absolute;
/* positions the menu UNDER the list item*/
width:100%;
/* makes the width of the menu the same as the list item */
visibility:hidden;
/* hides the menu until needed */

}

.top-nav li:hover .sub-nav {
visibility:visible;
/* shows the submenu when the list item is hovered */

}

.sub-nav > li, .sub-nav > li a{
display:block;
width:100%;
position:relative;
/* sets positioning context for 3rd level menu */
background:lightblue;
/* something different for example */
color:black;
}

.sub-nav > li > a {
/* jsut some styling */
border: 1px solid #3c3c3c;
border-top:none;
}

.sub-nav > li:last-child a {
border-bottom: 1px solid #3c3c3c;
}

.tert-nav {
position:absolute; /* positions the 3rd level menu */
width:100%;
visibility:hidden; /* hides the menu until required */
}

.sub-nav li:hover .tert-nav {
visibility:visible; /* shows the menu when list item is hovered */
display:block;
width:100%;
position:absolute; /* positions the list items of 3rd level menu */
top:0; /* lines up the menu with the list item */
left:100%; /* pushes the list item over to the right side */
margin-top:-1px; /* aligning after borders */
border-left:1px solid transparent; /* just add a gap */
}

.tert-nav > li, .tert-nav > li > a {
display:block;
width:100%;
background:#bada55; /* another level, another color */
}

.tert-nav > li > a {
/* jsut some styling */
border: 1px solid #3c3c3c;
border-bottom:none;
}

.tert-nav > li:last-child a {
border-bottom: 1px solid #3c3c3c;
}

.content {
height:250px;
background:lightgrey;
padding:10px;
}
<nav>
<ul class="top-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a>
<ul class="sub-nav">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
</li>
<li><a href="#">Clients</a>
<ul class="sub-nav">
<li><a href="#">Item 1</a>
<ul class="tert-nav">
<li><a href="#">Sub-Item 1.1</a></li>
<li><a href="#">Sub-Item 1.2</a></li>
<li><a href="#">Sub-Item 1.3</a></li>
<li><a href="#">Sub-Item 1.4</a></li>
</ul>
</li>
<li><a href="#">Item 2</a>
<ul class="tert-nav">
<li><a href="#">Sub-Item 2.1</a></li>
<li><a href="#">Sub-Item 2.2</a></li>
<li><a href="#">Sub-Item 2.3</a></li>
<li><a href="#">Sub-Item 2.4</a></li>
</ul>
</li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
</li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
<div class="content">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>

希望对您有所帮助!

关于css - Bootstrap3 pills, hover li items with CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50172627/

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