gpt4 book ai didi

html - 将 ul li 从水平更改为垂直

转载 作者:太空宇宙 更新时间:2023-11-04 02:23:07 24 4
gpt4 key购买 nike

我正在尝试做一个菜单,当窗口宽度调整到一个小分辨率时会出现。下面是 HTML 和 CSS 在下面

<nav>
<a id="menu-dropdown"><img src="http://localhost/influenza/logo/menu.png" /></a>
<ul>
<li><a class="tab-click" href="http://localhost/influenza/index.php">Home</a></li>
<li><a href="http://localhost/influenza/articles.php">Articles</a></li>
<li><a href="http://localhost/influenza/webinars.php">Webinars</a></li>
</ul>
</nav>

CSS:

nav ul
{
list-style:none;
}
nav li{
display:inline;
line-height:1.5px;
}
nav li:not(:first-child) > :only-child,
nav ul > :first-child a{
text-decoration:none;
font-size:1.4em !important;
outline:1px solid blue;
padding:8px;
letter-spacing:0.9px;
margin-left:18px;
}
nav li:not(:first-child) > :only-child{
color:blue;
}
nav ul > :first-child a{
color:white !important;
background:blue;
}

水平输出:

Home    Articles    Webinars

如何将列表恢复为垂直,然后将“ul”位置设置为绝对位置并使“nav a”可见。该列表应如下所示垂直显示

Home
Articles
Webinars

最佳答案

nav{
position:relative;
}
nav ul
{
position:absolute;
top:40px; /* this height is same as the menu.png */
left:0;
z-index:999;
list-style:none;
}
nav li{
list-style:none;
display:block;
}
nav ul li a{
display:block;
}
nav li:not(:first-child) > :only-child,
nav ul > :first-child a{
text-decoration:none;
font-size:1.4em !important;
outline:1px solid blue;
padding:8px;
letter-spacing:0.9px;
margin-left:18px;
}
nav li:not(:first-child) > :only-child{
color:blue;
}
nav ul > :first-child a{
color:white !important;
background:blue;
}
<nav>
<a id="menu-dropdown"><img src="http://localhost/influenza/logo/menu.png" /></a>
<ul>
<li><a class="tab-click" href="http://localhost/influenza/index.php">Home</a></li>
<li><a href="http://localhost/influenza/articles.php">Articles</a></li>
<li><a href="http://localhost/influenza/webinars.php">Webinars</a></li>
</ul>
</nav>

关于html - 将 ul li 从水平更改为垂直,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37779996/

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