search
HomeWeb Front-endHTML TutorialHtml Css for newbies, simply and quickly imitate Jingdong product classification navigation_html/css_WEB-ITnose

看一看最终的效果:

下面我们就按照分析→设计→实现 三大步骤来完成这个导航的效果,学会了之后,会发现大多数电商都是用这样的效果的。

我们先从把结构写好:一个nav包含上面一个div(全部商品分类),一个导航列表(ul li) 然后在每一个li里面都包含一个默认不显示的的大div(利用了绝对定位,这个div分成左边:小分类列表,右边图片广告)

因为我是用 纯css+html写的, 所以它的文件有:京东导航.html,main.css,cssreset.css(css文件放在css这个目录下面).

接着我们看具体的代码实现(这里我只写了家用电器的二级分类):
京东导航.html

<!doctype html><html><head><meta charset="utf-8"><title>京东导航</title><link href="css/cssreset.css" rel="stylesheet"><link href="css/main.css" rel="stylesheet"></head><body><nav><div class="all">    <a href="#">全部商品分类</a></div><ul>    <li class="nav_item"><a href="#">家用电器</a><span class="jt">></span>    <div class="sub_menu">            <div class="leftmenu">            <dl>                <dt><a href="#">大家电</a></dt>               <dd>                <a href="#" >平板电视</a>                <a href="#">空调</a>                <a href="#">冰箱</a>                <a href="#">洗衣机</a>                <a href="#">家庭影院</a>                <a href="#">DVD</a>                <a href="#">迷你音响</a>                <a href="#">烟机/灶具</a>                <a href="#"> 热水器</a>                <a href="#">消毒柜/洗碗机</a>                <a href="#">冷柜/冰吧</a>                <a href="#">酒柜</a>                <a href="#">家电配件</a>                </dd>            </dl>                   <dl>                <dt><a href="#">生活电器</a></dt>               <dd>                <a href="#">电风扇</a>                <a href="#">冷风扇</a>                <a href="#">净化器</a>                <a href="#">加湿器</a>                <a href="#">扫地机器人</a>                <a href="#">吸尘器</a>                <a href="#">挂烫机/熨斗</a>                <a href="#">插座</a>                <a href="#"> 电话机</a>                <a href="#">清洁机</a>                <a href="#">除湿机</a>                <a href="#">干衣机</a>                <a href="#">收录/音机</a>                </dd>            </dl>                    <dl>                <dt><a href="#">厨房电器</a></dt>               <dd>                <a href="#">电压力锅</a>                <a href="#">空调</a>                <a href="#">冰箱</a>                <a href="#">洗衣机</a>                <a href="#">家庭影院</a>                <a href="#">DVD</a>                <a href="#">迷你音响</a>                <a href="#">烟机/灶具</a>                <a href="#"> 热水器</a>                <a href="#">消毒柜/洗碗机</a>                <a href="#">冷柜/冰吧</a>                <a href="#">酒柜</a>                <a href="#">家电配件</a>                </dd>            </dl>                    <dl>                <dt><a href="#">个护健康</a></dt>               <dd>                <a href="#" >平板电视</a>                <a class="test" href="#">空调</a>                <a href="#">冰箱</a>                <a href="#">洗衣机</a>                <a href="#">家庭影院</a>                <a href="#">DVD</a>                <a href="#">迷你音响</a>                <a href="#">烟机/灶具</a>                <a href="#"> 热水器</a>                <a href="#">消毒柜/洗碗机</a>                <a href="#">冷柜/冰吧</a>                <a href="#">酒柜</a>                <a href="#">家电配件</a>                </dd>            </dl>                    <dl>                <dt><a href="#">五金家装</a></dt>               <dd>                <a href="#">平板电视</a>                <a href="#">空调</a>                <a href="#">冰箱</a>                <a href="#">洗衣机</a>                <a href="#">家庭影院</a>                <a href="#">DVD</a>                <a href="#">迷你音响</a>                <a href="#">烟机/灶具</a>                <a href="#"> 热水器</a>                <a href="#">消毒柜/洗碗机</a>                <a href="#">冷柜/冰吧</a>                <a href="#">酒柜</a>                <a href="#">家电配件</a>                </dd>            </dl>                  </div>            <div class="rightmenu">                 <dl>                        <dd>                            <a href="http://sale.jd.com/act/1XDZ6ShE5M7tTrl.html">                                <img  src="/static/imghwm/default1.png"  data-src="http://img10.360buyimg.com/vclist/jfs/t1198/21/1061230330/3619/48ee51cc/556ed3a0N9004a8f7.jpg"  class="lazy"    style="max-width:90%"  style="max-width:90%" title="by:罗坚元" alt="Html Css for newbies, simply and quickly imitate Jingdong product classification navigation_html/css_WEB-ITnose" >                            </a>                        </dd>                        <dd>                            <a href="http://sale.jd.com/act/v8kJIaPmsMGuebpH.html">                                <img  src="/static/imghwm/default1.png"  data-src="http://img11.360buyimg.com/vclist/jfs/t1531/43/307393451/3092/229dc57a/557194e1N0d5188f3.jpg"  class="lazy"    style="max-width:90%"  style="max-width:90%" title="by:罗坚元" alt="Html Css for newbies, simply and quickly imitate Jingdong product classification navigation_html/css_WEB-ITnose" >                            </a>                        </dd>                    </dl>            </div>        </div>    </li>           <li class="nav_item"><a href="#">手机</a>、<a href="#">数码</a>、<a href="#">京东通信</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">电脑</a>、<a href="#">办公</a><span class="jt">></span></li>    <li class="nav_item"><a href="#">家居</a>、<a href="#">家具</a>、<a href="#">家装</a>、<a href="#">厨具</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">男装</a>、<a href="#">女装</a>、<a href="#">内衣</a>、<a href="#">珠宝</a><span class="jt">></span></li>    <li class="nav_item"><a href="#">个护化妆</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">鞋靴</a>、<a href="#">箱包</a>、<a href="#">钟表</a>、<a href="#">奢侈品</a><span class="jt">></span></li>    <li class="nav_item"><a href="#">运动户外</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">汽车</a>、<a href="#">汽车用品</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">母婴</a>、<a href="#">玩具乐器</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">食品饮料</a>、<a href="#">酒类</a>、<a href="#">生鲜</a><span class="jt">></span></li>    <li class="nav_item"><a href="#">营养保健</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">图书</a>、<a href="#">音像</a>、<a href="#">数字商品</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">彩票</a>、<a href="#">旅行</a>、<a href="#">充值</a>、<a href="#">票务</a><span class="jt">></span></li>    <li class="nav_item"><a href="#"><a href="#">理财</a>、<a href="#">众筹</a>、<a href="#">白条</a>、<a href="#">保险</a><span class="jt">></span></a></li></ul></nav></body></html>

main.css

/* CSS Document */nav{ position:absolute; left:100px; top:100px; border:1px solid #b61d1d; }/*全部商品分类*/.all{ width:190px; height:44px; line-height:44px; background:#b1191a; padding:0 10px; }    .all a{ color:white; font-size:16px; }/*导航菜单*/.nav_item{ width:190px; height:31px; line-height:31px; color:white; background:#b61d1d; padding:0 10px; }ul li a{color:white;}.jt{ color:white; float:right; width:12px; padding-top:10px; font: 13px consolas; }    /*hover*/ul li:hover { background:white; }ul li:hover a{ color:#b61d1d; }    /*submenu*/.sub_menu{ display:none; width:790px; position:absolute; left:210px; top:44px; background:#f7f7f7; }ul li:hover .sub_menu{display:block;}.leftmenu{ width: 550px; overflow:hidden; float:left; }.leftmenu dl{ overflow:hidden; display:block; margin: 20px 0; }.leftmenu dl dt{ float:left; font-weight:bold; color:#737373; padding:0 8px; }.leftmenu dl  dd  a{ color: #737373; float:left; height:20px; line-height:20px; padding:0 10px; border-left: 1px solid #e0e0e0; font-size:12px; margin-top:5px; }.rightmenu{ float:right; }.rightmenu dl { margin-top:20px; }.rightmenu dl dd { padding:0; margin-bottom:2px; }

cssreset.css

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre, form,fieldset,input,textarea,p,blockquote,th,td { padding: 0; margin: 0; border: none; font-family: "Microsoft YaHei", "微软雅黑", "SimSun", "宋体"; font-size: 14px; } ol,ul{ list-style: none; }fieldset,img{ border:0; }h1,h2,h3,h4,h5,h6 { font-weight: normal; font-size: 100%; } a{ text-decoration: none; color: #737373; }img, iframe { border: none; text-decoration:none; } 

看到代码后,其实里面包含了很多细节的处理,例如:列表有一个红色的边框,每个大分类后都有一个箭头等等,不过做起来还是比较简单的。

本文作者By: 罗坚元 :

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
Beyond HTML: Essential Technologies for Web DevelopmentBeyond HTML: Essential Technologies for Web DevelopmentApr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor