Home >Web Front-end >CSS Tutorial >Pure CSS to realize label navigation production_Experience exchange

Pure CSS to realize label navigation production_Experience exchange

WBOY
WBOYOriginal
2016-05-16 12:06:261848browse

After searching on the Internet, I didn't see many tutorials or instructions on making label navigation purely using CSS. Most of them involve the writing of JS. This is really not considerate for many people who are learning CSS. Since no one has done it, let me try it first! The CSS label navigation I am doing here is a green navigation with pure CSS, no JS, and no background image. This article is suitable for beginners, experts can pass by, haha!


[Ctrl A Select all Note:If you need to introduce external Js, you need to refresh to execute]

Copy code The code is as follows:

.mainNav{  
 margin:0 20px;  
 height:47px;  
 border-bottom:2px solid #000;  
}  
ul{  
 margin:20px;  
 margin-bottom:0;  
 padding-left:20px;  
 list-style-type:none;  
 font-size:12px;  
 position:absolute;  
}  
ul li{  
 float:left;  
 margin-right:5px;  
}  
ul li a{  
 display:block;  
 width:100px;  
 line-height:25px;  
 text-align:center;  
 color:#999;  
 background-color:#FC0;  
 border:2px solid #000;  
}  
ul li a:hover{  
 height:27px;  
 background-color:#F60;  
 border-bottom:none;  
}  
#nav01 ul li a#nav001,  
#nav02 ul li a#nav002,  
#nav03 ul li a#nav003{  
 width:100px;  
 height:27px;  
 color:#FFF;  
 background-color:#F60;  
 border:2px solid #000;  
 border-bottom:none;  
}  
.con{  
 margin:0 20px;  
 padding:20px;  
 color:#FFF;  
 background-color:#F60;  
 border:2px solid #000;  
 border-top:none;  


复制代码 代码如下:

  
    
  
          
    
 


In fact, the key point is the position:absolute command in ul. Due to the use of this CSS attribute, the content of the ul navigation becomes a layer display, which is equivalent to floating on the browser. In order to prevent the following content from filling up the content of the ul part, a div is placed outside the ul, which helps the ul occupy space. This div also serves as the ul background. The key to label navigation is the bottom border. After reading it all, you will find that it is actually very simple, but the key is to have an idea. alright! Keep learning!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn