[CSS] Pure CSS realizes three-level navigation (template)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:42:55
Original
1633 people have browsed it

I used to think that the implementation of cascading navigation should be very simple, just use the hover attribute of CSS to implement it, so I didn’t pay too much attention to practice. But in a recent interview, when I was asked this question, I realized that there are many things that cannot be taken for granted. It is not only OK to know the general idea, but also requires actual hands-on ability.

Later, I actually implemented the cascading menu and took this opportunity to make it into a template to learn with everyone.

The following is the HTML part:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>纯css级联导航</title></head><body>    <div class="main">    	<ul class="one-nav">    		<li>    			<a href="javascript:;">一级导航</a>    			<ul class="two-nav">    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    			</ul>    		</li>    		<li>    			<a href="javascript:;">一级导航</a>    			<ul class="two-nav">    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    			</ul>    		</li>    		<li>    			<a href="javascript:;">一级导航</a>    			<ul class="two-nav">    				<li><a href="javascript:;">二级导航</a></li>    				<li>    					<a href="javascript:;">二级导航></a>    					<ul class="three-nav">    						<li><a href="javascipt:;">三级导航</a></li>    						<li><a href="javascipt:;">三级导航</a></li>    						<li><a href="javascipt:;">三级导航</a></li>    					</ul>    				</li>    				<li><a href="javascript:;">二级导航</a></li>    			</ul>    		</li>    		<li>    			<a href="javascript:;">一级导航</a>    			<ul class="two-nav">    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    			</ul>    		</li>    		<li>    			<a href="javascript:;">一级导航</a>    			<ul class="two-nav">    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    			</ul>    		</li>    		<li>    			<a href="javascript:;">一级导航</a>    			<ul class="two-nav">    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li><a href="javascript:;">二级导航</a></li>    				<li>    					<a href="javascript:;"><二级导航</a>    					<ul class="three-nav">    						<li><a href="javascipt:;">三级导航</a></li>    						<li><a href="javascipt:;">三级导航</a></li>    						<li><a href="javascipt:;">三级导航</a></li>    					</ul>    				</li>    			</ul>    		</li>    	</ul>    </div></body></html>
Copy after login

CSS part:

body,div,ul,li,a{margin: 0;padding: 0;text-decoration: none;}	/* 一级导航 */	.one-nav li{list-style-type: none;float: left;width: 16.57%;text-align: center;background-color: #3391E6;border-right: 1px solid white;cursor: pointer;height: 30px;line-height: 30px;}	.one-nav li:nth-last-child(1){border-right: none;}	.one-nav li a{color: white;}	.one-nav li:hover .two-nav{display: block;}	.one-nav li:hover{background-color: #4260D7;}	/* 二级导航 */	.two-nav {display: none;}	.two-nav li{width: 100%;}	.two-nav li:hover .three-nav{display: block;position: relative;}	/* 三级导航 */	.three-nav{position: absolute;width:100%;left: 100%;bottom: 100%;}	/* 最右边的三级导航显示在左边 */	.one-nav li:nth-last-child(1)  .two-nav li  .three-nav li{width: 100%;position:relative;right: 200%;}
Copy after login

The rendering is as follows:

The example is relatively simple, but often the simpler things require more down-to-earth practice and experience, life is like this ,mutual encouragement.


Author: Zhizhi

Sign: The road is long and long, I will search up and down.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template