CSS页面布局技巧
2012-06-12 17:53
351 查看
常见的几种定位方式
css的元素物理结构
All HTML elements can be considered as boxes.
Box Model
![](http://www.w3schools.com/css/box-model.gif)
Explanation of the different parts:
Margin - 边框透明没有背景色。
Border - A border that goes around the padding and content. The border is affected by the background color of the box
Padding - The padding is affected by the background color of the box
Content - The content of the box, where text and images appear
Width and Height of an Element
注意: 高宽只是对 content area有效. 如下:width:250px;
padding:10px;
border:5px solid gray;
margin:10px;
Let's do the math:
250px (width)
+ 20px (left and right padding)
+ 10px (left and right border)
+ 20px (left and right margin)
= 300px
下面就css一些布局常用的属性,还有一些相关的,涉及到的逐个讲解。
1.Positioning 定位
Static Positioning
HTML elements 的缺省值.通过 the normal flow of the page定位.不受 top, bottom, left, and right properties影响.
Fixed Positioning
1.fixed是特殊的absolute,即fixed总是以body为定位对象的,按照浏览器的窗口进行定位,即使拖动滚动条,他的位置也是不会改变的。
Relative Positioning
注意:移动后可能和其他元素重合, 但是元素本身的位置被保留in the normal flow.
根据top,right,bottom,left偏移。移动后可能与其他元素重合。
Absolute Positioning
1.当position属性设为absolute不是按照浏览器窗口来进行定位的。实际上,这是fixed属性的特点2.绝对定位相对它的第一个有定位的父类元素(除了static). 如果没发现, 以body为定位对象,即按浏览器的窗口进行定位,
3.当position设置为absolute后,元素溢出正常的文档流,就像它不属于 parent一样,它漂浮了起来,它原来位置肯可能其他元素占有。
2.Display
display:none
h1.hidden {display:none;}
visibility:hidden
h1.hidden {visibility:hidden;}注意:
visibility:hidden hides an element, but it will still take up the same
space as before. The element will be hidden, but still affect the layout.
display:Inline
li {display:inline;}
display:block
span {display:block;}
3. bottom,top,right,left Property
Definition and Usage
1.For absolutely positioned elements, the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its containing element.2.For relatively positioned elements, the bottom property sets the bottom edge of an element to a unit above/below its normal position.
注意: If "position:static", the bottom property has no effect.
参考文档:
1.http://www.w3schools.com/css/css_positioning.asp
相关文章推荐
- CSS技巧荟萃:了解CSS页面布局和加载流程
- CSS页面布局技巧(二)
- CSS页面布局技巧(三)
- CSS技巧荟萃:了解CSS页面布局和加载流程
- css后台页面布局技巧
- CSS页面布局技巧(一)
- CSS页面布局技巧(四)
- css布局小技巧---1:有一侧宽度固定,另一侧随浏览器及分辨率改变而改变的css页面布局
- CSS技巧荟萃:了解CSS页面布局和加载流程
- CSS技巧荟萃:了解CSS页面布局和加载流程
- CSS技巧荟萃:了解CSS页面布局和加载流程
- CSS技巧荟萃:了解CSS页面布局和加载流程
- CSS高级技巧:网页布局
- div+css布局中CSS图片大小自动按比例等比例缩小图片不变形解决技巧
- html+css正常但是复制到aspx页面出现布局混乱的问题
- div+css布局技巧博览
- CSS网页布局:网页页面结构化
- HTML与CSS布局技巧总结
- 使用CSS的float和clear属性完成页面布局
- CSS布局奇淫技巧之-高度自适应