版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、<div id="warp"> <div id="column1">这里是第一列</div> <div id="column2">这里是第二列</div> <div class="clear"></div></div>CSS:#wrap width:100%; height:auto;#column1 float:left; width:40%;#column2 float:right; w
2、idth:60%;.clear clear:both; position : static | absolute | fixed | relative取值:static : 默认值。无特殊定位,对象遵循HTML定位规则 absolute : 将对象从文档流中拖出,使用 left , right , top , bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。如果不存在这样的父对象,则依据 body 对象。而其层叠通过 z-index 属性定义 fixed : 未支持。对象定位遵从绝对(absolute)方式。但是要遵守一些规范 relative : 对象不可层叠,但将
3、依据 left , right , top , bottom 等属性在正常文档流中偏移位置它来实现一行两列的例子xhtml:<div id="warp"> <div id="column1">这里是第一列</div> <div id="column2">这里是第二列</div></div>CSS:#wrap position:relative;/*相对定位*/width:770px;#column1 position:absolute; top
4、:0; left:0; width:300px;#column2position:absolute; top:0; right:0; width:470px;他们的区别在哪?显然,float是相对定位的,会随着浏览器的大小和分辨率的变化而改变,而position就不行了,所以一般情况下还是float布局!2.CSS常用布局实例一列单行一列body margin: 0px; padding: 0px; text-align: center; #content margin-left:auto; margin-right:a
5、uto; 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;
6、160; text-align: center; #content-top margin-left:auto; margin-right:auto; width: 400px;#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: aut
7、o; margin-left: auto;overflow: auto; #bodycenter #dv1 float: left;width: 280px;#bodycenter #dv2 float: right;width: 410px;两行两列#header width: 700px; margin-right: auto;margin-left: auto; overflow: auto;#bodycenter width: 700px; margin-right: auto; margin-left: auto; overflow:
8、auto; #bodycenter #dv1 float: left; width: 280px;#bodycenter #dv2 float: right;width: 410px;三行两列#header width: 700px;margin-right: auto; margin-left: auto; #bodycenter width: 700px; margin-right: auto; margin-left: auto; #bodycenter #dv1 float: left;width: 280px;
9、#bodycenter #dv2 float: right; width: 410px;#footer width: 700px; margin-right: auto; margin-left: auto; overflow: auto; 三列单行三列绝对定位#left position: absolute; top: 0px; left: 0px; width: 120px; #middle margin: 20px 190px 20px 190px; #right po
10、sition: absolute;top: 0px; right: 0px; width: 120px;float定位xhtml:<div id="warp"> <div id="column"> <div id="column1">这里是第一列</div> <div id="column2">这里是第二列</div> <div class="clear">&l
11、t;/div> </div> <div id="column3">这里是第三列</div> <div class="clear"></div></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;
12、width:40%;.clear clear:both; float定位二xhtml: <div id="center" class="column"> <h1>This is the main content.</h1> </div> <div id="left" class="column"> <h2>This is the left sidebar.</h2> &
13、lt;/div> <div id="right" class="column"> <h2>This is the right sidebar.</h2> </div>CSS:body margin: 0;padding-left: 200px;padding-right: 190px;min-width: 240px;.column position: relative;float: left;#center width: 100%;#left width: 180px
14、; right: 240px;margin-left: -100%;#right width: 130px;margin-right: -100%;两行三列xhtml:<div id="header">这里是顶行</div><div id="warp"> <div id="column"> <div id="column1">这里是第一列</div> <div id="column2"&g
15、t;这里是第二列</div> <div class="clear"></div> </div> <div id="column3">这里是第三列</div> <div class="clear"></div></div>CSS:#headerwidth:100%; height:auto;#wrap width:100%; height:auto;#column float:left; w
16、idth:60%;#column1 float:left; width:30%;#column2 float:right; width:30%;#column3 float:right; width:40%;.clear clear:both; 三行三列xhtml:<div id="header">这里是顶行</div><div id="warp"> <div id="column"> <div id="column1">这里是第一列&
17、lt;/div> <div id="column2">这里是第二列</div> <div class="clear"></div> </div> <div id="column3">这里是第三列</div> <div class="clear"></div></div><div id="footer">这里是底
18、部一行</div>CSS:#headerwidth:100%; height:auto;#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; #footerwidth:100%; height:auto;PS:这里列出的是常用的例子,而非研究之用,对一每个盒子,我都没有设置margin,pad
19、ding,boeder等属性,是因为我个人觉得,含有宽度定位的时候,最好不好用到他们,除非必不得已,因为如果不是这样的话,解决浏览器兼容问题,会让你头疼,而且产生一系列CSS代码,我觉得这样的效率和效果都不好!3.CSS布局高级技巧margin和padding总是有可能要用到,而产生的问题如何解决呢?由于浏览器解释容器宽度的方法不同:IE 6.0 Firefox Opera等是真实宽度=width+padding+border+marginIE5.X真实宽度=width-padding-border-margin很明显,第一种下很完美的布局在第二种情况下后果是很凄惨的!解决的方法是 hack&
20、#160;div.content width:400px; /这个是错误的width,所有浏览器都读到了voice-family: """" /IE5.X/win忽略了""""后的内容voice-family:inherit;width:300px; /包括IE6/win在内的部分浏览器读到这句,新的数值(300px)覆盖掉了旧的 html>body .content /html>body是CSS2的写法width:300px; /支持CSS2该写法的浏览器(非IE5)有幸读到了这一句 div.content width:300px !important; /这个是正确的width,大部分支持!important标记的浏览器使用这里的数值width(空格)/*/:400px; /IE6/win
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 防雷接地专项施工方案
- 华泰保险如何挑选市场调研员?内行人必知
- 中医诊所考勤制度
- 事业单位b类考勤制度
- 学校前台考勤制度
- 公司考勤制度奖惩范本
- 金融投资分析师面试全攻略
- 企业人力资源管理面试技巧与策略
- 2027年秋季学期建队日新队员入队仪式活动方案
- 00后员工考勤制度
- 2024~2025学年北京市大兴区八年级下学期期中考试数学试卷
- 脊柱创伤术后康复课件
- 肿瘤生存者管理专家共识
- 设备故障抢修管理办法
- 化工厂安全培训课件
- 工程力学(第五版)课件 绪论
- 收单外包管理办法
- 3月3日5、6号机组故障跳闸报告
- 单招化学试题及答案
- 广西钦州市八年级上学期英语12月考试卷
- 甘肃兰州事业单位教师岗招聘考试综合基础知识真题(附答案)
评论
0/150
提交评论