书签 分享 收藏 举报 版权申诉 / 32

类型CSS一.docx

  • 文档编号:23812595
  • 上传时间:2023-05-21
  • 格式:DOCX
  • 页数:32
  • 大小:199.76KB

/*这是违背web标准意图的,只是想说明在它下面的元素需要清除浮动*/

CSS代码:

ExampleSourceCode

#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代码:

ExampleSourceCode

这里是第一列

这里是第二列

CSS代码:

ExampleSourceCode[]

#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常用布局实例

单行一列

ExampleSourceCode

body{margin:

0px;padding:

0px;text-align:

center;}

#content{margin-left:

auto;margin-right:

auto;width:

400px;}

两行一列

ExampleSourceCode

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;}

三行一列

ExampleSourceCode

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;}

单行两列

ExampleSourceCode

#bodycenter{width:

700px;margin-right:

auto;margin-left:

auto;overflow:

auto;}

#bodycenter#dv1{float:

left;width:

280px;}

#bodycenter#dv2{float:

right;width:

420px;}

两行两列

ExampleSourceCode

#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;}

三行两列

ExampleSourceCode

#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;}

单行三列

绝对定位

ExampleSourceCode

#left{position:

absolute;top:

0px;left:

0px;width:

120px;}

#middle{margin:

0px190px0px190px;}

#right{position:

absolute;top:

0px;right:

0px;width:

120px;}

float定位一

xhtml代码:

ExampleSourceCode

这里是第一列

这里是第二列

/*用法web标准不建议,但是记住下面元素需要清除浮动*/

这里是第三列

/*用法web标准不建议,但是记住下面元素需要清除浮动*/

CSS代码:

ExampleSourceCode

#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代码:

ExampleSourceCode

Thisisthemaincontent.

Thisistheleftsidebar.

Thisistherightsidebar.

CSS代码:

ExampleSourceCode

body{

margin:

0;

padding-left:

200px;/*LCfullwidth*/

padding-right:

190px;/*RCfullwidthCCpadding*/

min-width:

200px;/*LCfullwidthCCpadding*/

}

.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;

}

 

DIV+CSS学习之margin缩进法

示例:

DIV页面布局(margin-left方法)顶部

中间左边

中间右边

底部

代码:

--

#top,#left,#right,#bottom

{

background:

#CCCCCC;

height:

120px;

}

#top,#index,#bottom/*页面上、中、下层宽度定义*/

{

clear:

both;

width:

778px;

margin:

4px;

margin-left:

auto;/*页面中上、中、下居中*/

margin-right:

auto;

}

#left{

float:

left;

width:

200px;

}

#right

{

margin-left:

200px;

}

-->

顶部

中间左边

中间右边

配套讲稿:

如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

特殊限制:

部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

关 键  词:
CSS
提示  冰豆网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:CSS一.docx
链接地址:https://www.bdocx.com/doc/23812595.html

copyright@ 2008-2022 冰点文档网站版权所有

经营许可证编号:鄂ICP备2022015515号-1