博客学堂
首页>>博客进阶>>css>> div+css学习笔记整理

div+css学习笔记整理

来源: 疯癫鼠 | 添加时间:2008-5-13 09:04:45 |   | 我要投稿 | 提问

一些比较常用属性:

font  字体
color 颜色
font-size  字体大小
text-align   文本位置
background 背景
margin  外补丁
padding 内补丁
border  边框
float  布局

下边是实例

CSS布局常用的方法:float:none|left|right

取值:

none:默认值。对象不飘浮
left:文本流向对象的右边
right:文本流向对象的左边
它是怎样工作的,看个一行两列的例子

xhtml代码:

<div id="wrap">
<div id="column1">这里是第一列</div>
<div id="column2">这里是第二列</div>
<div class="clear"></div> /*这是违背web标准意图的,只是想说明在它下面的元素需要清除浮动*/
</div>

CSS代码:

#wrap{width:100;height:auto;}
#column1{float:left;width:40;}
#column2{float:right;width:60;}
.clear{clear:both;}
position:static|absolute|fixed|relative

取值:

static:默认值。无特殊定位,对象遵循HTML定位规则
absolute:将对象从文档流中拖出,使用left,right,top,bottom等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。如果不存在这样的父对象,则依据body对象。而其层叠通过z-index属性定义
fixed:未支持。对象定位遵从绝对(absolute)方式。但是要遵守一些规范
relative:对象不可层叠,但将依据left,right,top,bottom等属性在正常文档流中偏移位置

它来实现一行两列的例子

xhtml代码:

<div id="wrap">
<div id="column1">这里是第一列</div>
<div id="column2">这里是第二列</div>
</div>

CSS代码:

#wrap{position:relative;/*相对定位*/width:770px;}
#column1{position:absolute;top:0;left:0;width:300px;}
#column2{position:absolute;top:0;right:0;width:470px;}

他们的区别在哪?

显然,float是相对定位的,会随着浏览器的大小和分辨率的变化而改变,而position就不行了,所以一般情况下还是float布局!

CSS常用布局实例

单行一列

body{margin:0px;padding:0px;text-align:center;}
#content{margin-left:auto;margin-right:auto;width:400px;}

两行一列

body{margin:0px;padding:0px;text-align:center;}
#content-top{margin-left:auto;margin-right:auto;width:400px;}
#content-end{margin-left:auto;margin-right:auto;width:400px;}  

三行一列

body{margin:0px;padding:0px;text-align:center;}
#content-top{margin-left:auto;margin-right:auto;width:400px;width:370px;}
#content-mid{margin-left:auto;margin-right:auto;width:400px;}
#content-end{margin-left:auto;margin-right:auto;width:400px;}

单行两列

#bodycenter{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
#bodycenter#dv1{float:left;width:280px;}
#bodycenter#dv2{float:right;width:420px;}

两行两列

#header{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
#bodycenter{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
#bodycenter#dv1{float:left;width:280px;}
#bodycenter#dv2{float:right;width:420px;}

三行两列

#header{width:700px;margin-right:auto;margin-left:auto;}
#bodycenter{width:700px;margin-right:auto;margin-left:auto;}
#bodycenter#dv1{float:left;width:280px;}
#bodycenter#dv2{float:right;width:420px;}
#footer{width:700px;margin-right:auto;margin-left:auto;overflow:auto;clear:both;}  

单行三列

绝对定位

#left{position:absolute;top:0px;left:0px;width:120px;}
#middle{margin:0px190px0px190px;}
#right{position:absolute;top:0px;right:0px;width:120px;} 

float定位

xhtml代码:

<div id="wrap">
<div id="column">
<div id="column1">这里是第一列</div>
<div id="column2">这里是第二列</div>
<div class="clear"></div>/*用法web标准不建议,但是记住下面元素需要清除浮动*/
</div>
<divid="column3">这里是第三列</div>
<divclass="clear"></div>/*用法web标准不建议,但是记住下面元素需要清除浮动*/
</div>

CSS代码:

#wrap{width:100;height:auto;}
#column{float:left;width:60;}
#column1{float:left;width:30;}
#column2{float:right;width:30;}
#column3{float:right;width:40;}
.clear{clear:both;}

float定位二

xhtml代码:

<div id="center"class="column">
<h1>Thisisthemaincontent.</h1>
</div>
<div id="left"class="column">
<h2>Thisistheleftsidebar.</h2>
</div>
<div id="right"class="column">
<h2>Thisistherightsidebar.</h2>
</div>

CSS代码:

body{
margin:0;
padding-left:200px;/*LCfullwidth*/
padding-right:190px;/*RCfullwidth CCpadding*/
min-width:200px;/*LCfullwidth CCpadding*/
}
.column{
position:relative;
float:left;
}
#center{
width:100;
}
#left{
width:200px;/*LCwidth*/
right:200px;/*LCfullwidth*/
margin-left:-100;
}
#right{
width:190px;/*RCwidth*/
margin-right:-100;
}

写一些比较简单的,这些应该多去实践才会真正的掌握

我写的这个

xhtml代码:

<div id="enter"><a href="http://www.blog286.com">清风徐来</a></div>
<div id="ziuotext">时光一逝永不回,往事只能回味.<br />忆童年时竹马青梅,两小无猜日夜相随.<br />春风又吹红了花蕊,你已经也添了新岁.<br />你就要变心像时光难倒回,我只有在梦里想依偎.</div>
<div id="copyright">Powered By <a href="/">Tsingfeng.com</a> _fcksavedurl=""/">Tsingfeng.com</a>" _fcksavedurl=""/">Tsingfeng.com</a>" _fcksavedurl=""/">Tsingfeng.com</a>" _fcksavedurl=""/">Tsingfeng.com</a>" _fcksavedurl=""/">Tsingfeng.com</a>" _fcksavedurl=""/">Tsingfeng.com</a>" _fcksavedurl=""/">Tsingfeng.com</a>" CopyRight 2005-2007 <a href="http://www.miibeian.gov.cn" target="_blank">苏ICP备000000号</a></div>

CSS代码:

body     {background-color:#FFFFFF;margin: 0px;text-align:center;line-height:150%;font-size:12px;color:#AA0000;font-family:"宋体"}
#enter{;font-size:20px;font-family:Impact;margin-top:100px;}
#enter a{font-size:36px;color:#AA0000; text-decoration:none}
#enter a:hover{color:#FFFFFF; background:#AA0000; padding:2px;}
#ziuotext{margin-top:30px;}
#copyright{margin-top:50px;}
a{color:#AA0000; text-decoration:none}
a:hover{color:#FFFFFF; background:#AA0000; padding:2px;}

主要用到的是 padding与 margin

一些常用的css 命名

页头:header

登录条:loginbar

标志:logo

侧栏:sidebar

广告:banner

导航:nav

子导航:subnav

菜单:menu

子菜单:submenu

搜索:search

滚动:scroll

页面主体:main

内容:content

标签页:tab

文章列表:list

提示信息:msg

小技巧:tips

栏目标题:title

加入:joinus

指南:guild

服务:service

热点:hot

新闻:news

下载:download

注册:regsiter

状态:status

按钮:btn

投票:vote

合作伙伴:partner

友情链接:friendlink

页脚:footer

版权:copyright

CSS ID 的命名

外 套:  wrap

主导航:  mainnav

子导航:  subnav

页 脚:  footer

整个页面: content

页 眉:  header

页 脚:  footer

商 标:  label

标 题:  title

主导航:  mainbav(globalnav)

顶导航:  topnav

边导航:  sidebar

左导航:  leftsidebar

右导航:  rightsidebar

旗 志:  logo

标 语:  banner

菜单内容1: menu1content

菜单容量: menucontainer

子菜单:  submenu

边导航图标:sidebarIcon

注释:   note

面包屑:  breadcrumb(即页面所处位置导航提示)

容器:   container

内容:   content

搜索:   search

登陆:   Login

功能区:  shop(如购物车,收银台)

当前的   current

在编辑样式表时可用的注释可这样写

<-- Footer -->

内容区

<-- End Footer -->

样式文件命名

主要的 master.css

布局,版面 layout.css

专栏 columns.css

文字 font.css

打印样式 print.css

主题 themes.css

网站常用中英文对照表

网站导航 Site Map

公司简介 Profile or Company Profile or Company

公司设备 Equipment Equipment

公司荣誉 Glories Glories

企业文化 Culture Culture

产品展示 Product Product

资质认证 Quality Certification

企业规模 Scale Scale

营销网络 Sales Network

组织机构 organization organization

合作加盟 Join In Cooperation

技术力量 Technology Technology

经理致辞 Manager`s oration

发展历程 Development History

工程案例 Engineering Projects

业务范围 Business Scope

分支机构 Branches

供求信息 Supply & Demand

经营理念 Operation Principle

产品销售 Sales Sales

联系我们 Contact Us Contact Us

信息发布 Information Information

返回首页 Homepage Homepage

产品定购 order order

分类浏览 Browse By Category

电子商务 E-business

公司实力 Strength Strength

版权所有 Copy Right

友情连结 Hot Link

应用领域 Application Fields

人力资源 Human Resource Hr

领导致辞 Leader`s oration

企业资质 Enterprise Qualification

行业新闻 Trade News

行业动态 Trends

客户留言 Customer Message

客户服务 Customer Service

新闻动态 News & Trends

公司名称 Company Name

销售热线 Sales Hot-Line

联系人 Contact Person

您的要求 Your Requirements

建设中 In Construction

证书 Certificate Certificate

地址 ADD Add

邮编 Postal Code Zipcode

电话 TEL Tel

传真 FAX Fax

产品名称 Product Name

产品说明 Description Description

价格 Price

品牌 Brand

规格 Specification

尺寸 Size

生产厂家 Manufacuturer Manufacturer

型号 Model

产品标号 Item No.

技术指标 Technique Data

产品描述 Description

产地 Production Place

销售信息 Sales Information

用途 Application

论坛 Forum

在线订购 On-line order

招商 Enterprise-establishing

招标 Bid Inviting

综述 General

业绩 Achievements

招聘 Join Us

求贤纳士 Join Us

大事 Great Event

动态 Trends

服务 Service

投资 Investment

行业 Industry

规划 Programming

环境 Environment

发送 Delivery

提交 Submit

重写 Reset

登录 Enter

注册 Login

社区 Community

业务介绍 Business Introduction

在线调查 Online Inquiry Inquiry

下载中心 Download

会员登陆 Member Entrance

意见反馈 Feedback

常见问题 FAQ

中心概况 General Profile

教育培训 Education & Training

游乐园 Amusement Park

在线交流 Online Communication

专题报道 Special Report

收藏和分享:
评论加载中…
网站地图 - 关于我们 - 版权声明 - 广告服务 - 联系我们 - 诚聘英才 - 帮助中心
Copyright © 2007-2008 www.blog286.com all Right Reserved
博客学堂 版权所有