CSS定位
来源:互联网 发布:日语红宝书软件下载 编辑:程序博客网 时间:2024/05/21 22:51
2013-01-09 14:30289人阅读评论(0)收藏举报
相对定位是按照元素自身所在的位置,使用边偏移属性重新定义元素的显示位置,使用相对定位的元素依然是文档中的元素,元素的显示位置和
元素所在文档中其他元素相互关联。
在确定相对定位元素位置的时候,首先要确定元素的原始位置,即元素在文档中的位置,然后根据偏移属性中定义的偏移值,确定元素的最终位置。
[html]view plaincopyprint?
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <title> New Document</title>
5 <meta name="Generator" content="EditPlus">
6 <meta name="Author" content="">
7 <meta name="Keywords" content="">
8 <meta name="Description" content="">
9 <style>
10 .div1 {
11 background: #333333;
12 width: 200px;
13 height: 100px;
14 }
15
16 .relative {
17 position: relative;
18 top: 50px;
19 left: 100px; 此属性设置,只是相对于他原先的位置,并不是以父元素的位置未起点
20 width: 400px;
21 height: 100px;
22 background: #666666;
23 }
24
25 </style>
26 </head>
27
28 <body>
29 <div class="div1"></div>
30 <div class="relative">这是相对定位到元素</div>
31 </body>
32 </html>
从上图可以看出,使用相对定位的元素按照自身所在的位置进行偏移。
在使用相对定位到时候,相对定位元素保留原来所占有的空间,同时自身按照边偏移属性中定义的属性值进行偏移(有可能覆盖其他元素),
与相对定位元素相邻的元素会将相对定位元素进行排列。
[html]view plaincopyprint?
33 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
34 <html>
35 <head>
36 <title> New Document</title>
37 <meta name="Generator" content="EditPlus">
38 <meta name="Author" content="">
39 <meta name="Keywords" content="">
40 <meta name="Description" content="">
41 <style>
42 .div1 {
43 background: #333333;
44 width: 200px;
45 height: 100px;
46 }
47
48 .relative {
49 position: relative;
50 top: 50px;
51 left: 100px;
52 width: 400px;
53 height: 100px;
54 background: #666666;
55 }
56
57 .div2 {
58 background: #999999;
59 width: 200px;
60 height: 100px;
61 }
62
63 </style>
64 </head>
65
66 <body>
67 <div class="div1"></div>
68 <div class="relative">这是相对定位到元素</div>
69 <div class="div2"></div>
70 </body>
71 </html>
从上图看出,与相对定位元素相邻的元素的显示方式,会保留相对元素原来占有的空间,使用相对定义的元素,由于其显示级别高于
普通元素,所以相对定位元素覆盖了普通页面元素。
- CSS定位
- CSS定位
- CSS定位
- CSS定位
- CSS定位
- CSS定位
- CSS定位
- css 定位
- css 定位
- css定位
- CSS 定位
- css定位
- css定位
- css 定位
- CSS 定位
- css定位
- css 定位
- css定位
- JavaScript学习总结(一)——JavaScript基础
- Python 学习入门(4)—— 连接MySQL
- Jquery判断input是否选择好了文件
- [教程] 浅谈Unity里面的模型优化 - 建模与材质的关联
- linux磁盘分区详解
- CSS定位
- C++中的using namespace std的作用
- Python 学习入门(5)—— 发送邮件
- shell 时间戳转换
- BSEG和BSIS、BSAS、BSID、BSAD、BSIK、BSAK 六个表的关系
- 华为笔试-字符串拆分和排序
- UVa - The 3n + 1 problem 题解
- 用UIImageVeiw来实现gif动态图
- java web初学,学习笔记