css_display_block_inline_div_span_li_position_float

display 和 position的用法:

学习一点儿css,应该系统地看一遍的,否则,用到的时候就比较浪费时间了;

曾经总在div的布局上花费时间,今天才发现是因为display属性没有看明白。h1,p,div等元素默认是display:block的,所以,两个div 挨着就总换行; span,a等元素默认display:inline 的,所以,两个span挨着就不会自动换行; 现在,了解了 display属性后,就可以方便地控制他们是否换行了。

通过:

<style> div {display:inline}<style> 就可以让div也不换行了

通过:

<style> span{display:block}<style> 也可以让span换行了

参考资料:

http://www.w3schools.com/css/css_display_visibility.asp

http://www.w3schools.com/css/css_positioning.asp

http://www.w3schools.com/css/css_float.asp

http://www.zhangxinxu.com/wordpress/?p=1565

 

IN http://www.w3schools.com/css/css_align.asp

Crossbrowser Compatibility Issues

When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element. This is to avoid visual differences in different browsers.

There is a problem with IE8 and earlier, when using the position property. If a container element (in our case <div>) has a specified width, and the !DOCTYPE declaration is missing, IE8 and earlier versions will add a 17px margin on the right side. This seems to be space reserved for a scrollbar. Always set the !DOCTYPE declaration when using the position property:

留下评论

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据