DIV+CSS导航学习笔记

简介: 学习简单导航制作,常见导航有如下样式:w3school导航 网易首页导航 以上两种分别可以用ul和div来制作,直接上代码:test.html:<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html;c

学习简单导航制作,常见导航有如下样式:

  1. w3school导航
    这里写图片描述
  2. 网易首页导航
    这里写图片描述

以上两种分别可以用ul和div来制作,直接上代码:

test.html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<link rel="stylesheet" type="text/css" href="headline.css" />
<link rel="stylesheet" type="text/css" href="div.css" />
<title>Test Page</title>
<!-- <style type="text/css">
    h1 {color:blue}
    p {color:green}
    body {background-color:lightgrey}
</style> -->
</head>
<body>
    <div class="container">
        <div class="headline">
            <ul>
                <li><a href="http://www.baidu.com" target="_blank">Baidu</a></li>
                <li><a href="http://www.taobao.com" target="_blank">Taobao</a></li>
                <li><a href="http://www.163.com" target="_blank">163</a></li>
                <li><a href="http://www.yeah.net" target="_blank">Yeah</a></li>
                <li><a href="http://www.blog.csdn.net" target="_blank">Blog</a></li>
                <li><a href="http://www.google.com" target="_blank">Google</a></li>
                <li><a href="http://www.yahoo.com" target="_blank">Yahoo</a></li>
            </ul>
        </div>
        <div class="navi">
            <div class="navi-part">
                <div>
                    <strong><a href="http://www.baidu.com">新闻</a></strong>
                    <a href="http://www.baidu.com">军事</a>
                    <a href="http://www.baidu.com">评论</a>
                    <a href="http://www.baidu.com">图片</a><br/>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">体育</a></strong>
                    <a href="http://www.baidu.com">购彩</a>
                    <a href="http://www.baidu.com">NBA</a>
                    <a href="http://www.baidu.com">中超</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">娱乐</a></strong>
                    <a href="http://www.baidu.com">电影</a>
                    <a href="http://www.baidu.com">电视</a>
                    <a href="http://www.baidu.com">音乐</a>
                </div>
            </div>
            <div class="navi-part">
                <div>
                    <strong><a href="http://www.baidu.com">财经</a></strong>
                    <a href="http://www.baidu.com">股票</a>
                    <a href="http://www.baidu.com">基金</a>
                    <a href="http://www.baidu.com">商业</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">视频</a></strong>
                    <a href="http://www.baidu.com">资讯</a>
                    <a href="http://www.baidu.com">综艺</a>
                    <a href="http://www.baidu.com">公开课</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">女人</a></strong>
                    <a href="http://www.baidu.com">时尚</a>
                    <a href="http://www.baidu.com">美容</a>
                    <a href="http://www.baidu.com">情感</a>
                </div>
            </div>
            <div class="navi-part">
                <div>
                    <strong><a href="http://www.baidu.com">科技</a></strong>
                    <a href="http://www.baidu.com">酒香</a>
                    <a href="http://www.baidu.com">智能硬件</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">手机</a></strong>
                    <a href="http://www.baidu.com">海淘</a>
                    <a href="http://www.baidu.com">手机库</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">数码</a></strong>
                    <a href="http://www.baidu.com">家电</a>
                    <a href="http://www.baidu.com">电脑</a>
                </div>
            </div>
            <div class="navi-part">
                <div>
                    <strong><a href="http://www.baidu.com">汽车</a></strong>
                    <a href="http://www.baidu.com">购车</a>
                    <a href="http://www.baidu.com">选车</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">旅游</a></strong>
                    <a href="http://www.baidu.com">车险</a>
                    <a href="http://www.baidu.com">健康</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">房产</a></strong>
                    <a href="http://www.baidu.com">家居</a>
                    <a href="http://www.baidu.com">二手房</a>
                </div>
            </div>
            <div class="navi-part">
                <div>
                    <strong><a href="http://www.baidu.com">博客</a></strong>
                    <a href="http://www.baidu.com">海外</a>
                    <a href="http://www.baidu.com">小说</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">游戏</a></strong>
                    <a href="http://www.baidu.com">彩票</a>
                    <a href="http://www.baidu.com">探索</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">论坛</a></strong>
                    <a href="http://www.baidu.com">摄影</a>
                    <a href="http://www.baidu.com">佛学</a>
                </div>
            </div>
            <div class="navi-part">
                <div>
                    <strong><a href="http://www.baidu.com">教育</a></strong>
                    <a href="http://www.baidu.com">本地</a>
                    <a href="http://www.baidu.com">云课堂</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">亲子</a></strong>
                    <a href="http://www.baidu.com">君子</a>
                    <a href="http://www.baidu.com">艺术</a>
                </div>
                <div>
                    <strong><a href="http://www.baidu.com">哒哒</a></strong>
                    <a href="http://www.baidu.com">公益</a>
                    <a href="http://www.baidu.com">交友</a>
                </div>
            </div>
        </div>
        <div class="clear"></div>
        <!-- <div class="logo">
            <a href="http://blog.csdn.net/foreverling" target="_blank">
                <img src="http://avatar.csdn.net/2/D/2/1_u011331383.jpg" alt="logo" />
            </a>
        </div> -->
        <pre><code></code></pre>
    </div>
</body>
</html>

headline.css:

@CHARSET "UTF-8";

ul {
    list-style-type: none;
    float: top; 
    margin: 0;
    padding: 0;
}

li {
    float: left; /* 用于将多个放在同一行 */
}

ul a:link, ul a:visited {
    display: block;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #bebebe;
    width: 120px;
    text-align: center;
    padding: 4px;
    text-decoration: none;
    text-transform: upperCase;
}

ul a:hover, ul a:active {
    background-color: red;
}

div.css:

@CHARSET "UTF-8";

body {
    padding: 0;
    margin: 5px;
}

.container {
    width: 960px; 
    margin: 0 auto;
}

.headline {
    padding-bottom: 15px;
}

.navi {
    padding: 0;
    margin-top: 15px;
    overflow: auto;
}

.navi-part {
    overflow:auto;
    float: left; /* 用于将多个div放在同一行 */
    margin: 5px;
}

a {
    text-decoration: none;
    color: black;
}

a:hover {
    color: red;
}

.logo {
    padding-left: 0;
    width: 100px;
    height: 100px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.clear {
    clear: both;
}

width: 960px; margin: 0 auto;用于将页面居中,float: left; , 用于将多个div放在同一行 。

最后的结果如下:
导航1:
这里写图片描述

导航2:
这里写图片描述

目录
相关文章
|
5月前
|
前端开发
css div覆盖样式(一个div想覆盖掉另一个div在他上面进行显示)
css div覆盖样式(一个div想覆盖掉另一个div在他上面进行显示)
51 0
|
2月前
|
前端开发
导航新风尚:CSS梯形设计,让网站菜单不再单调!
导航新风尚:CSS梯形设计,让网站菜单不再单调!
|
7天前
|
前端开发 容器
css布局-弹性布局学习笔记
这篇文章是关于CSS弹性布局的学习笔记,详细介绍了flex容器和元素的相关属性,包括flex-direction、flex-wrap、flex-flow、justify-content、align-items、align-content以及order、flex-grow、flex-shrink、flex-basis、flex和align-self等,解释了这些属性在弹性盒子布局中的作用和用法。
|
24天前
|
Web App开发 前端开发 JavaScript
HTML/CSS/JS学习笔记 Day3(HTML--网页标签 下)
HTML/CSS/JS学习笔记 Day3(HTML--网页标签 下)
|
6天前
|
JavaScript 前端开发
网页前端课程设计-【模仿】香港中文大学官网,轮播图及div+css布局,js的dom操作
这篇文章介绍了如何模仿香港中文大学官网进行网页前端课程设计,包括使用div+css布局、js的DOM操作以及实现轮播图等技术细节。
|
2月前
|
前端开发
导航栏也时尚:CSS缩放动画,让导航链接在鼠标经过时绽放!
导航栏也时尚:CSS缩放动画,让导航链接在鼠标经过时绽放!
|
2月前
|
前端开发
一键复制:期末大作业常用的CSS动画导航效果!
一键复制:期末大作业常用的CSS动画导航效果!
|
2月前
|
前端开发
官网导航更智能:CSS动画下划线,让每一次点击都充满期待!
官网导航更智能:CSS动画下划线,让每一次点击都充满期待!
|
3月前
|
前端开发
css 巧用 ::after 和 ::before 实现竖排分类导航
css 巧用 ::after 和 ::before 实现竖排分类导航
38 1
|
3月前
|
前端开发
css 实用技巧 —— div在div中水平垂直居中(两种方法)
css 实用技巧 —— div在div中水平垂直居中(两种方法)
45 3