div+css实例布局(一)

导航是前端开发中避免不了的一个区域,今天就来写写导航栏。

导航栏(一)

<div id='menu'>
	<a href="#">链接</a>|
	<a href="#">链接</a>|
	<a href="#">链接</a>|
	<a href="#">链接</a>|
	<a href="#">链接</a>
</div>
*{margin:0;padding:0}
#menu{
		min-width:400px;
		height:2rem;
		background:#06f;
		text-align:center;
		line-height:2rem;
		font-size:1rem;
	}
#menu a{
		padding:0 1rem;
		color:#000;
		text-decoration:none;
		font-weight:bold
		}
#menu a:hover{color:#FFC0CB}

导航栏(二)

<ul id="menu"> 
	   <li><a href="#">首页</a></li> 
	   <li><a href="#">首页</a></li> 
	   <li><a href="#">首页</a></li> 
	   <li><a href="#">首页</a></li> 
	   <li><a href="#">首页</a></li> 
	   <li><a href="#">首页</a></li> 
</ul> 
*{margin:0;padding:0}
body{min-width:500px;}
li{list-style:none} 
body{text-align:center} 
a{text-decoration:none}  
a:hover{color:#BA2636} 
#menu{ width:100%; height:3.75rem; background:#00A2CA;} 
#menu li{display:inline; height:3.75rem} 
#menu li a{display:inline-block; padding:0 1.25rem; height:3.75rem; line-height:3.75rem; 
color:#FFF;font-weight:bold;font-size:1rem} 
#menu li a:hover{background:#0095BB} 

移动端底部滑动导航栏(三)

测试时候需要调成移动端

<div id="nav">
        <footer id="footer">
            <div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div><div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div><div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div><div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div><div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div><div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div><div class="flex">
               <div class="top" ></div>
               <div class="bottom" >首页</div>
            </div>
        </footer>
    </div>
*{ margin: 0;padding: 0;}
        #nav{
            width: 100%;
            height: 4rem;
            position: fixed;
            bottom: 0;
            margin: 0 0 0.625rem 0;
        }
        #footer
        {
            width: 100%;
            white-space: nowrap;
            overflow-x: auto;
            cursor: pointer;
        }
        /*将容器分为上下2部分*/
        #footer .flex
        {
            width: 5rem;
            height: 4rem;
            display: inline-block;
            border: 1px solid #808080;
        }
        .top{
            width: 100%;
            height: 3rem;
            background: url("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4075723771,1234971875&fm=27&gp=0.jpg")   center center no-repeat;
            background-size: 100% 100%;
        }
 	.bottom{
            width: 100%;
            height: 1rem;
            line-height: 1rem;
            text-align: center;
        }

响应式导航栏

<header>
        <nav class="nav">
            <input type="checkbox" id="toggle" class="toggle"/>
            <label for="toggle">
                <span class="menu-icon">
                    <svg viewBox="0 0 18 15" width="18px" height="15px">
                        <path fill="white" d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.031C17.335,0,18,0.665,18,1.484L18,1.484z"/>
                        <path fill="white" d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484 h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z"/>
                        <path fill="white" d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z"/>
                   </svg>
              </span>
            </label>
            <ul class="list">
                <li><a href="#">菜单一</a></li>
                <li><a href="#">菜单二</a></li>
                <li><a href="#">菜单三</a></li>
                <li><a href="#">菜单四</a></li>
                <li><a href="#">菜单五</a></li>
            </div>
        </nav>
    </header>
*{margin:0;padding:0}
.nav{background:#abc;height:3rem;display:block}
.list{z-index:0;display:block;}
li{list-style:none;float:left;margin-left:2rem;}
a{text-decoration:none;color:#fff;line-height:3rem;}
a:hover{color:#FFC0CB}
input:checked~.list{
                position:absolute;
		padding:0 0.3rem 0.3rem 0.3rem;
		display:block;
		background: #abc;
		z-index:0;
		margin-top:3rem;
		}
input:checked~.list li{clear:both;background: #abc;}
label{display:none}
.toggle{display:none}
@media screen and (max-width:500px) {
	.toggle{display:none}
	label{display:block;z-index:4}
	.list{display:none;margin-left:0;}
	li{margin-left:0;}
	.meun-icon{display: block;float: left; }
	.menu-icon>svg path{fill: white; }
    label[for="toggle"] {
          	display: block;
          	float:left;
          	z-index:2;
          	cursor:ponter;
          	line-height:3rem;
          	margin-left:1rem
          	    }
			}

 

  • 47
    点赞
  • 268
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你正在学习 CSS 布局吗?是不是还不能完全掌握纯 CSS 布局?通常有两种情况阻碍你的学习: 第一种可能是你还没有理解 CSS 处理页面的原理。在你考虑你的页面整体表现效果前,你应当先考虑内容的语义和结构, 然后再针对语义、结构添加 CSS。这篇文章将告诉你应该怎样把 HTML 结构化。 另一种原因是你对那些非常熟悉的表现层属性(例如:cellpadding,、hspace、align="left"等等)束手无策,不知道该 转换成对应的什么 CSS 语句。当你解决了第一种问题,知道了如何结构化你的 HTML,我再给出一个列表,详细列出原来的表 现属性用什么 CSS 来代替。 结构化 HTML 我们在刚学习网页制作时,总是先考虑怎么设计,考虑那些图片、字体、颜色、以及布局方案。然后我们用 Photoshop 或者 Fireworks 画出来、切割成小图。最后再通过编辑 HTML 将所有设计还原表现在页面上。 如果你希望你的 HTML 页面用 CSS 布局(是 CSS-friendly 的),你需要回头重来,先不考虑“外观”,要先思考你的页面 内容的语义和结构。 外观并不是最重要的。一个结构良好的 HTML 页面可以以任何外观表现出来,CSS Zen Garden 是一个典型的例子。CSS Zen Garden 帮助我们最终认识到 CSS 的强大力量。 HTML 不仅仅只在电脑屏幕上阅读。你用 photoshop 精心设计的画面可能不能显示在 PDA、移动电话和屏幕阅读机上。但 是一个结构良好的 HTML 页面可以通过 CSS 的不同定义,显示在任何地方,任何网络设备上。 开始思考 首先要学习什么是"结构",一些作家也称之为"语义"。这个术语的意思是你需要分析你的内容块,以及每块内容服务的 目的,然后再根据这些内容目的建立起相应的 HTML 结构。
XHTML 40个例子显示的内容一样,通过CSS实现不一样的布局效果, 是学习div + css排版的绝佳教程.body标签内的内容如下: Header 1) Content here. column long long column very long fill fill fill long text text column text silly very make long very fill silly make make long make text fill very long text column silly silly very column long very column filler fill long make filler long silly very long silly silly silly long filler make column filler make silly long long fill very. very make make fill silly long long filler column long make silly silly column filler fill fill very filler text fill filler column make fill make text very make make very fill fill long make very filler column very long very filler silly very make filler silly make make column column fill long make long text very make long fill column make text very silly column filler silly text fill text filler filler filler make make make make text filler fill column filler make silly make text text fill make very filler column very column text long column make silly long text filler silly very very very long filler fill very fill silly very make make filler text filler text make silly text text long fill fill make text fill long text very silly long long filler filler fill silly long make column make silly long column long make very 2) Navigation here. long long fill filler very fill column column silly filler very filler fill fill filler text fill very silly fill text filler silly silly filler fill very make fill column text column very very column fill fill very silly column silly silly fill fill long filler 3) More stuff here. very text make long silly make text very very text make long filler very make column make silly column fill silly column long make silly filler column filler silly long long column fill silly column very Here it goes the footer
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值