gpt4 book ai didi

html - 使用纯CSS创建三级菜单

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

我正在使用纯 CSS 来创建多级菜单。我使用以下代码生成代码:

html

<div class="main">
<ul class="mainnav">
<li><a href="/files/public/" ><i class="fa fa-home"></i></a></li>

<li class="hassubs"><a href="#">Master Entry <i class="fa fa-caret-down" aria-hidden="true"></i></a>
<ul class="dropdown">
<li class="subs hassubs"><a href="#">Master Entry</a>
<ul class="dropdown">

<li class="subs"><a href="/files/public/master_entry/create/">Size</a></li>
<li class="subs"><a href="/files/public/master_entry/index/">Color</a></li>
<li class="subs"><a href="/files/public/master_entry/index/">Unit</a></li>
<li class="subs"><a href="/files/public/master_entry/index/">Process Group</a></li>
</ul>
</li>
</ul>
</div>

我在代码中使用了以下 CSS:

.main{width: 100%; background: #eee;}
/*General Menu Styling*/
.mainnav{margin: 0 auto}
li{list-style: none;}
li a{text-decoration: none;}
.dropdown{position: absolute; width: 150px;top: 41px; opacity: 0;visibility: hidden;transition: ease-out .35s;-moz-transition: ease-out .35s;-webkit-transition: ease-out .35s;}
.mainnav li{float: left;padding: 4px;background: black;border-left: 1px dotted #fff;height:45px;}
.mainnav li:first-child{border: none;}
.mainnav li a{ display: block;padding: 8px 20px;color: #fff;font-family: arial;}
.mainnav li:hover{background: #E87944;transition: ease-in .35s;-moz-transition: ease-in .35s;-webkit-transition: ease-in .35s;}
.mainnav li:hover a{color: #fff;transition: ease-in .35s;-moz-transition: ease-in .35s;-webkit-transition: ease-in .35s;}
/*First Level*/
.subs {left: -45px;position: relative;top: 0px;width: 175px;border-left: none !important; border-bottom: 1px dotted #fff !important;}
.subs:last-child{border: none !important;}
.hassubs:hover .dropdown,.hassubs .hassubs:hover .dropdown{opacity: 1;visibility: visible; transition: ease-in .35s;-moz-transition: ease-in .35s;-webkit-transition: ease-in .35s;}
.mainnav li:hover ul a,.mainnav li:hover ul li ul li a{color: white;}
.mainnav li ul li:hover,.mainnav li ul li ul li:hover{background: #E87944;transition: ease-in-out .35s;-moz-transition: ease-in-out .35s;-webkit-transition: ease-in-out .35s;}
.mainnav li ul li:hover a,.mainnav li ul li ul li:hover a{color: white;transition: ease-in-out .35s;-moz-transition: ease-in-out .35s;-webkit-transition: ease-in-out .35s;}
/*Second Level*/
.hassubs .hassubs .dropdown .subs{left: 25px;position: relative;width: 165px;top: 0px;}
.hassubs .hassubs .dropdown{position: absolute;width: 150px;left: 120px;top: 0px;opacity: 0;visibility: hidden;transition: ease-out .35s;-moz-transition: ease-out .35s;-webkit-transition: ease-out .35s;}

我想在链接 size 下创建三级菜单。我如何修改相同的 css。

最佳答案

已创建三级菜单,希望有用。

<!DOCTYPE html>
<html>

<body>
<style>
.main {
width: 100%;
background: #eee;
}

/*General Menu Styling*/
.mainnav {
margin: 0 auto
}

li {
list-style: none;
}

li a {
text-decoration: none;
}

.dropdown {
position: absolute;
width: 150px;
top: 41px;
opacity: 0;
visibility: hidden;
transition: ease-out .35s;
-moz-transition: ease-out .35s;
-webkit-transition: ease-out .35s;
}

.mainnav li {
float: left;
padding: 4px;
background: black;
border-left: 1px dotted #fff;
height: 45px;
}

.mainnav li:first-child {
border: none;
}

.mainnav li a {
display: block;
padding: 8px 20px;
color: #fff;
font-family: arial;
}

.mainnav li:hover {
background: #E87944;
transition: ease-in .35s;
-moz-transition: ease-in .35s;
-webkit-transition: ease-in .35s;
}

.mainnav li:hover a {
color: #fff;
transition: ease-in .35s;
-moz-transition: ease-in .35s;
-webkit-transition: ease-in .35s;
}

/*First Level*/
.subs {
left: -45px;
position: relative;
top: 0px;
width: 175px;
border-left: none !important;
border-bottom: 1px dotted #fff !important;
}

.subs:last-child {
border: none !important;
}

.hassubs:hover .dropdown,
.hassubs .hassubs:hover .dropdown,
.hassubs .hassubs .dropdown .subs:hover .dropdown {
opacity: 1;
visibility: visible;
transition: ease-in .35s;
-moz-transition: ease-in .35s;
-webkit-transition: ease-in .35s;
}

.mainnav li:hover ul a,
.mainnav li:hover ul li ul li a {
color: white;
}

.mainnav li ul li:hover,
.mainnav li ul li ul li:hover {
background: #E87944;
transition: ease-in-out .35s;
-moz-transition: ease-in-out .35s;
-webkit-transition: ease-in-out .35s;
}

.mainnav li ul li:hover a,
.mainnav li ul li ul li:hover a {
color: white;
transition: ease-in-out .35s;
-moz-transition: ease-in-out .35s;
-webkit-transition: ease-in-out .35s;
}

/*Second Level*/
.hassubs .hassubs .dropdown .subs {
left: 25px;
position: relative;
width: 165px;
top: 0px;
}

.hassubs .hassubs .dropdown,.hassubs .hassubs .dropdown .subs .dropdown {
position: absolute;
width: 150px;
left: 120px;
top: 0px;
opacity: 0;
visibility: hidden;
transition: ease-out .35s;
-moz-transition: ease-out .35s;
-webkit-transition: ease-out .35s;
}
</style>
<div class="main">
<ul class="mainnav">
<li><a href="/files/public/">Home<i class="fa fa-home"></i></a></li>
<li class="hassubs"><a href="#">Master Entry <i class="fa fa-caret-down" aria-hidden="true"></i></a>
<ul class="dropdown">
<li class="subs hassubs"><a href="#">Sub Master Entry</a>
<ul class="dropdown">
<li class="subs">
<a href="/files/public/master_entry/create/">Size</a>
<ul class="dropdown">
<li class="subs"><a href="/files/public/master_entry/create/">Size 1</a></li>
<li class="subs"><a href="/files/public/master_entry/create/">Size 2</a></li>
</ul>
</li>
<li class="subs">
<a href="/files/public/master_entry/index/">Color</a>
<ul class="dropdown">
<li class="subs"><a href="/files/public/master_entry/create/">Red</a></li>
<li class="subs"><a href="/files/public/master_entry/create/">Green/a></li>
</ul>
</li>
<li class="subs"><a href="/files/public/master_entry/index/">Unit</a></li>
<li class="subs"><a href="/files/public/master_entry/index/">Process Group</a></li>
</ul>
</li>
</ul>
</li>
</div>

</body>

</html>

关于html - 使用纯CSS创建三级菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53880361/

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