本篇文章,我们应用浮动和无序列表来实现各个列表项由竖向排列转为水平排列,像一个导航菜单似的。
本文索引
第 1 步 - 没有 CSS 格式的无序列表项目
None
None CSS CODE
None
HTML CODE
<ul>
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 2 步 - 删除列表项前面的符号
None None
None CSS CODE
ul#navlist { list-style-type: none; }
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 3 步 - 删除列表项的内外边距
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 4 步 - 让各列表项水平排列
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
ul#navlist li { display: inline; }
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 5 步 - 让各列表项左浮动,并设置宽度
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
None ul#navlist li { display: inline; }
ul#navlist li a
{
float: left;
width: 5em;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 6 步 - 给各“a”元素添加背景色,文字颜色
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 7 步 - 给各“a”元素添加内边距
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
padding: 0.2em 1em;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 8 步 - 给各“a”元素添加下划线
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
padding: 0.2em 1em;
text-decoration: underline;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 9 步 - 给各“a”元素添加边框以分开各个列表项
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
padding: 0.2em 1em;
text-decoration: underline;
border-right: 1px solid #fff;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 10 步 - 给各“a”元素添加悬停效果
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
padding: 0.2em 1em;
text-decoration: underline;
border-right: 1px solid #fff;
}
ul#navlist li a:hover
{
background-color: #369;
color: red;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 11 步 - 让UL左浮动且宽度为满屏,以便着色
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
float: left;
width: 100%;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
padding: 0.2em 1em;
text-decoration: underline;
border-right: 1px solid #fff;
}
None ul#navlist li a:hover
{
background-color: #369;
color: red;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
第 12 步 - 给 UL 添加背景色
None None
None CSS CODE
ul#navlist {
padding: 0;
margin: 0;
list-style-type: none;
float: left;
width: 100%;
color: #fff;
background-color: #036;
}
None ul#navlist li { display: inline; }
None ul#navlist li a
{
float: left;
width: 5em;
color: #fff;
background-color: #036;
padding: 0.2em 1em;
text-decoration: underline;
border-right: 1px solid #fff;
}
None ul#navlist li a:hover
{
background-color: #369;
color: red;
}
None
HTML CODE
<ul id="navlist">
<li><a href="#">菜单 1</a></li>
<li><a href="#">菜单 2</a></li>
<li><a href="#">菜单 3</a></li>
</ul>
None
None None
油管频道👉 https://bit.ly/2XNfakc 看最新视频,白嫖最新节点!
请朋友们优先使用订阅,特别是手机用户,更方便更快捷!
-
👉Clash-meta 20.37版以后/Shadowrocket订阅:
https://drive.google.com/uc?export=download&id=1Yfumr9NXNg7_j1se0MjENW1SRIBdW33H
-
👉Clash-旧版 20.37版以前/Shadowrocket订阅:
https://drive.google.com/uc?export=download&id=1Yj2pDh7_34y_pgIcu-RNdmS1D3Y43sJ3
-
👉V2ray/IOS苹果V2Box/WinXray/Quantumult X订阅:
https://drive.google.com/uc?export=download&id=1YhPRs4o5Ly-aE5sFCXld2ESwAA6hFhlp
- 👉Clash-meta(点击下载后,本地导入)
- 👉 Clash-旧版(点击下载后,本地打开)
- 👉 IOS 苹果小火箭专用(点击自动下载,订阅地址请右键复制链接地址)
- 👉 V2ray/IOS苹果V2Box/winXray(点击下载后,本地打开)
0 评论