gpt4 book ai didi

html - 按内容显示下拉菜单宽度

转载 作者:行者123 更新时间:2023-11-28 02:44:00 25 4
gpt4 key购买 nike

我有一个下拉菜单,我想更改它,下拉菜单的宽度将按内容显示。我想改变,那个下拉菜单<li>将仅在主线下的一排 <li>彼此相邻。

我在 jsfiddle 上有它,我在那里使用了 sass。 http://jsfiddle.net/hhkrp71f/3/

这是我的解决方案:

.header__links {
float: right;
margin-top: 40px;
}
.header__links nav ul {
list-style: none;
margin: 0;
padding: 0;
}
.header__links nav ul li {
font-weight: 100;
font-style: italic;
color: red;
float: left;
margin-left: 25px;
}
.header__links nav ul li a {
color: red;
text-decoration: none;
}
.header__links nav ul li a:hover {
color: red;
transition: color 0.7s ease;
}
.header__links nav ul li:hover ul {
visibility: visible;
opacity: 1;
filter: alpha(opacity=100);
}
.header__links nav ul li ul {
visibility: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: 500ms ease;
-moz-transition: 500ms ease;
-o-transition: 500ms ease;
transition: 500ms ease;
position: absolute;
margin: 0;
padding: 20px 0 0;
}
.header__links nav ul li ul li {
margin: 0;
padding: 10px;
background-color: blue;
}
<div class="header__links">
<nav>
<ul>
<li><a href="#">Test</a>
<ul>
<li><a href="#">Test Test Test</a></li>
<li><a href="#">Test Test</a></li>
<li><a href="#">Test Test Test</a></li>
<li><a href="#">Test Test</a></li>
</ul>
</li>
<li><a href="#">Test</a></li>
<li><a href="#">Test</a></li>
<li><a href="#">Test</a></li>
</ul>
</nav>
</div>

最佳答案

right: 0 添加到您的内部 ul

.header__links {
float: right;
margin-top: 40px;
}
.header__links nav ul {
list-style: none;
margin: 0;
padding: 0;
}
.header__links nav ul li {
font-weight: 100;
font-style: italic;
color: red;
float: left;
margin-left: 25px;
}
.header__links nav ul li a {
color: red;
text-decoration: none;
}
.header__links nav ul li a:hover {
color: red;
transition: color 0.7s ease;
}
.header__links nav ul li:hover ul {
visibility: visible;
opacity: 1;
filter: alpha(opacity=100);
}
.header__links nav ul li ul {
visibility: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: 500ms ease;
-moz-transition: 500ms ease;
-o-transition: 500ms ease;
transition: 500ms ease;
position: absolute;
margin: 0;
padding: 20px 0 0;
right: 0;
}
.header__links nav ul li ul li {
margin: 0;
padding: 10px;
background-color: blue;
}
<div class="header__links">
<nav>
<ul>
<li><a href="#">Test</a>
<ul>
<li><a href="#">Test Test Test</a></li>
<li><a href="#">Test Test</a></li>
<li><a href="#">Test Test Test</a></li>
<li><a href="#">Test Test</a></li>
</ul>
</li>
<li><a href="#">Test</a></li>
<li><a href="#">Test</a></li>
<li><a href="#">Test</a></li>
</ul>
</nav>
</div>

关于html - 按内容显示下拉菜单宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47011523/

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