html怎么设置顶部导航栏,互联网常识:CSS+HTML如何实现顶部导航栏
本篇文章給大家介紹一下CSS+HTML實(shí)現(xiàn)頂部導(dǎo)航欄的方法。有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)大家有所幫助。
導(dǎo)航欄的實(shí)現(xiàn)、固定頂部導(dǎo)航欄、二級(jí)菜單實(shí)現(xiàn)
效果圖:
最近在使用這個(gè)導(dǎo)航欄的時(shí)候,發(fā)現(xiàn)頁(yè)面在放大和縮小的情況下,導(dǎo)航欄的布局和顯示都有些小問題,所以重新改了一下css部分的代碼,重新貼上來
新的代碼實(shí)現(xiàn)(優(yōu)化布局):
.top{
/* 設(shè)置寬度高度背景顏色 */
height: auto; /*高度改為自動(dòng)高度*/
width:100%;
margin-left: 0;
background:rgb(189, 181, 181);
position: fixed; /*固定在頂部*/
top: 0;/*離頂部的距離為0*/
margin-bottom: 5px;
}
.top ul{
/* 清除ul標(biāo)簽的默認(rèn)樣式 */
width: auto;/*寬度也改為自動(dòng)*/
list-style-type: none;
white-space:nowrap;
overflow: hidden;
margin-left: 5%;
/* margin-top: 0; */
padding: 0;
}
.top li {
float:left; /* 使li內(nèi)容橫向浮動(dòng),即橫向排列 */
margin-right:2%; /* 兩個(gè)li之間的距離*/
position: relative;
overflow: hidden;
}
.top li a{
/* 設(shè)置鏈接內(nèi)容顯示的格式*/
display: block; /* 把鏈接顯示為塊元素可使整個(gè)鏈接區(qū)域可點(diǎn)擊 */
color:white;
text-align: center;
padding: 3px;
overflow: hidden;
text-decoration: none; /* 去除下劃線 */
}
.top li a:hover{
/* 鼠標(biāo)選中時(shí)背景變?yōu)楹谏?*/
background-color: #111;
}
.top ul li ul{
/* 設(shè)置二級(jí)菜單 */
margin-left: -0.2px;
background:rgb(189, 181, 181);
position: relative;
display: none; /* 默認(rèn)隱藏二級(jí)菜單的內(nèi)容 */
}
.top ul li ul li{
/* 二級(jí)菜單li內(nèi)容的顯示 */
float:none;
text-align: center;
}
.top ul li:hover ul{
/* 鼠標(biāo)選中二級(jí)菜單內(nèi)容時(shí) */
display: block;
}
body{
background:#eff3f5;
}
- 一級(jí)菜單
- 一級(jí)菜單
- 一級(jí)菜單
- 一級(jí)菜單
- 一級(jí)菜單
一級(jí)菜單
- 二級(jí)菜單
- 二級(jí)菜單
下面的原來的代碼實(shí)現(xiàn)(頁(yè)面放大縮小的時(shí)候?qū)Ш桨媾虐嬗袉栴}):
.top{
/* 設(shè)置寬度高度背景顏色 */
height: 50px;
width:100%;
background:rgb(189, 181, 181);
position: fixed; /*固定在頂部*/
top: 0;/*離頂部的距離為0*/
}
.top ul{
/* 清除ul標(biāo)簽的默認(rèn)樣式 */
width: 80%;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.top li {
float:left; /* 使li內(nèi)容橫向浮動(dòng),即橫向排列 */
margin-right:50px; /* 兩個(gè)li之間的距離*/
}
.top li a{
/* 設(shè)置鏈接內(nèi)容顯示的格式*/
display: block; /* 把鏈接顯示為塊元素可使整個(gè)鏈接區(qū)域可點(diǎn)擊 */
color:white;
text-align: center;
padding: 14px 16px;
text-decoration: none; /* 去除下劃線 */
}
.top li a:hover{
/* 鼠標(biāo)選中時(shí)背景變?yōu)楹谏?*/
background-color: #111;
}
.top ul li ul{
/* 設(shè)置二級(jí)菜單 */
width: auto;
background:rgb(189, 181, 181);
position: absolute;
display: none; /* 默認(rèn)隱藏二級(jí)菜單的內(nèi)容 */
}
.top ul li ul li{
/* 二級(jí)菜單li內(nèi)容的顯示 */
margin-right:0;
float:none;
text-align: center;
}
.top ul li:hover ul{
/* 鼠標(biāo)選中二級(jí)菜單內(nèi)容時(shí) */
display: block;
}
- 一級(jí)菜單
- 一級(jí)菜單
- 一集菜單
- 一級(jí)菜單
- 一級(jí)菜單
一級(jí)菜單
- 二級(jí)菜單
- 二級(jí)菜單
總結(jié)
以上是生活随笔為你收集整理的html怎么设置顶部导航栏,互联网常识:CSS+HTML如何实现顶部导航栏的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 镜面反射原理以及实现
- 下一篇: 前端性能优化之浏览器渲染原理和关键渲染路