手机
当前位置:查字典教程网 >网页设计 > Div+Css教程 >css中的四种定位方式示例介绍
css中的四种定位方式示例介绍
摘要:/*通配符选择器*/*{margin:0px;padding:0px;}/*div的选择器*/.div1{border:1pxsolidre...

/*通配符选择器*/

*{

margin:0px;

padding:0px;

}

/*div的选择器*/

.div1{

border:1px solid red;

background:silver;

width:60px;

height:30px;

float:left;

margin-left:5px;

}

.div2{

position:relative;

left:10px;

top:10px;

width:100px;

height:80px;

background:pink;

float:left;

margin-left:5px;

}

/*相对定位,他原来的空间任然保留*/

#spe{

position:relative;

top:40px;

left:20px;

}

/*绝对定位:元素框从文档流里完全删除

对该元素最近的那个脱离了标准流的元素定位*/

#spe2{

position:absolute;

top:40px;

left:20px;

}

/*固定定位,只想对于视图的左上角定位*/

#spe{

position:fixed;

top:40px;

left:20px;

}

/*静态定位是默认的static left、top此时没有效果

靠margin来移动位置*/

/*z-index用于设置对象(div)显示时候,层叠的属性,

z-index值越小,则越在下层显示*/

[html] view plaincopy在CODE上查看代码片派生到我的代码片

<html>

<head>

<link rel="stylesheet" type="text/css" href="position.css"/>

</head>

<body>

<div>内容1</div>

<div>内容3</div>

<div>内容4</div>

<div>

<div id="spe2">内容2</div>

</div>

</body>

</html>

1

【css中的四种定位方式示例介绍】相关文章:

CSS各种文字对齐方式代码

用css实现十字的布局示例代码

css强制文字不换行实现代码

css的margin缩写方式

css清除浮动方法和代码

控制css字间距和对齐方式所用属性介绍

css div绝对定位与固定定位实例

css的三种定位方式使用探讨

css中元素水平垂直居中4种方法介绍

练习层DIV的定位小实例

精品推荐
分类导航