DIV+css布局入门.docx_第1页
DIV+css布局入门.docx_第2页
DIV+css布局入门.docx_第3页
DIV+css布局入门.docx_第4页
DIV+css布局入门.docx_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

DIV+CSS布局常用的行列布局规则1.CSS布局常用的方法:float : none | left | right取值:none : 默认值。对象不飘浮 left : 文本流向对象的右边 right : 文本流向对象的左边它是怎样工作的,看个一行两列的例子xhtml:这里是第一列这里是第二列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:这里是第一列这里是第二列CSS:#wrap position:relative;/*相对定位*/width:770px;#column1 position:absolute; top: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: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;#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: 410px;两行两列#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: 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;#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 position: absolute;top: 0px; right: 0px; width: 120px;float定位xhtml:这里是第一列这里是第二列这里是第三列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:This is the main content.This is the left sidebar.This is the right sidebar.CSS:body margin: 0;padding-left: 200px;padding-right: 190px;min-width: 240px;.column position: relative;float: left;#center width: 100%;#left width: 180px; right: 240px;margin-left: -100%;#right width: 130px;margin-right: -100%;两行三列xhtml:这里是顶行这里是第一列这里是第二列这里是第三列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; 三行三列xhtml:这里是顶行这里是第一列这里是第二列这里是第三列这里是底部一行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,padding,boeder等属性,是因为我个人觉得,含有宽度定位的时候,最好不好用到他们,除非必不得已,因为如果不是这样的话,解决浏览器兼容问题,会让你头疼,而且产生一系列CSS代码,我觉得这样的效率和效果都不好!3.CSS布局高级技巧margin和padding总是有可能要用到,而产生的问题如何解决呢?由于浏览器解释容器宽度的方法不同:IE 6.0 Firefox Opera等是真实宽度=width+padding+border+marginIE5.X真实宽度=width-padding-border-margin很明显,第一种下很完美的布局在第二种情况下后果是很凄惨的!解决的方法是 hackdiv.content width:400px; /这个是错误的width,所有浏览器都读到了voice-family: ; /IE5.X/win忽略了后的内容voice-family:inherit;width:300px; /包括IE6/win在内的部分浏览器读到这句,新的数值(300px)覆盖掉了旧的 htmlbody .content /htmlbody是CSS2的写法width:300px; /支持CSS2该写法的浏览器(非IE5)有幸读到了这一句div.content width:300px !important; /这个是正确的width,大部分支持!important标记的浏览器使用这里的数值width(空格)/*/:400px; /IE6/win不解析这句,所以IE6/win仍然认为width的值是300px;而IE5.X/win读到这句,新的数值(400px)覆盖掉了旧的,因为!important标记对他们不起作用 htmlbody .content /htmlbody是CSS2的写法width:300px; /支持CSS2该写法的浏览器有幸读到了这一句使用CSS层叠样式表设置行间距 教程 css 文本属性 使用CSS层叠样式表设置行间距 主题 在html中使用css层叠样式表如何设置行间距?我想让行之间有较大的间距,如何实现? 解释 属性: 线高度用法: line-height: 1cm; line-height: 40px; line-height: 40pt; line-height: 200%; 定义:这是用来设置行间距。 属性可以取以下的值。a)cm:行间距以厘米为单位来设置,例如:1cm或者2cm等.b)px:行间距以像素为单位来设置,例如:1px或者10px等.c)pt:行间距以点为单位来设置,例如:1pt或者10pt等.d)%:行间距以百分数为单位来设置,例如:200%或者500%等.如果是100%意思就是原来的行间距。示例1:测试线高度- 1号线 测试线高度- 2号线 结果:测试线高度- 1号线 测试线高度- 2号线示例2: 测试线高度测试线高度- 2号线 结果:测试线高度 测试线高度- 2号线 示例3: 测试线高度测试线高度- 2号线 结果:测试线高度 测试线高度- 2号线 示例4: 测试线高度测试线高度- 2号线 结果:测试线高度 测试线高度- 2号线如何设置div之间的水平间距:建议:尽可能的手写代码,可以有效的提高学习效率和深度。设定两个div的水平间距可能是最基本的操作了,但是对于初学div+css布局者来说也并不是那么容易,下面就简单介绍一下。先看一个代码实例: 蚂蚁部落 .parent width:200px; height:200px; border:1px solid green; overflow:hidden; .left width:100px; height:50px; border:1px solid blue; float:left .right width:80px; height:50px; border:1px solid red; float:right; 为了让两个div能够水平排列,使用了float属性,让两个div分别左浮动和右浮动。这时候两个div分别紧靠容器的左右两侧内壁,这样我们就可以调整容器的宽度来调整两个div的水平间距了,要注意的是:两个div的实际占用宽度一定不要忘记border。代码中两个div的间距是:200px-100px-1px-1px-80px-1px-1px=16px。下面再介绍一使用使用外边距设置两个div的水平间

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论