DIV样式汇总
最近在学习JavaScript,在做到个要控制控件样式的例子时,突然有了把常用样式汇总一下的想法,于是乎就写了以下内容,以下是以div为例来汇总的,希望对大家有些帮助。
一、常用属性:
1、Height:设置DIV的高度。
2、Width:设置DIV的宽度。
例:
<div >
</div>
3、margin:用于设置DIV的外延边距,也就是到父容器的距离。
例:
<div >
<div >
</div>
</div>
说明:margin:后面跟有四个距离分别为到父容器的上-右-下-左边的距离;可以看例子中的白DIV到黑DIV的边距离效果。还可以分别设置这四个边的距离,用到的属性如下:
4、margin-left:到父容器左边框的距离。
5、margin-right:到父容器右边框的距离。
6、margin-top: 到父容器上边框的距离。
7、margin-bottom:到父容器下边框的距离。
例:
<div >
<div rtcscls-1-s_sn_19_rId_a6 rtcscls-1-s_r_20_rId_a6 rtcscls-1-s_sn_3_rId_a0 rtcscls-1-r_31" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_31%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33"> background- color:White;">
</div>
</div>
8、padding:用于设置DIV的内边距。
例:
<div >
<div ></div>
</div>
说明:padding的格式和margin的格式一样,可以对照学习。可以看黑DIV与白DIV的边距来体会此属性的效果。这是还需要注意的是padding设置的距离不包括在本身的width和height内(在IE7和FF中),比如一个DIV的width设置了100px,而padding-left设置了50px,那么这个DIV在页面上显示的将是150px宽。也可以用以下四个属性来分别设置DIV的内边距:
9、padding-left:左内边距。
10、padding-right: 右内边距。
11、padding-top; 上内边距。
12、padding-bottom: 下内边距。
例:
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">background-color:Black;">
<div >
</div>
</div>
13、position:设置DIV的定位方式。
例:
<div >
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">background-color:White;">
</div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
div border属性 </div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
</div>
</div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
</div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
</div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
</div>
</div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
</div>
<div rtcscls-2-s_sn_19_rId_a6 rtcscls-2-s_r_20_rId_a6 rtcscls-2-s_sn_3_rId_a0 rtcscls-2-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">width:100px;height:100px;">
</div>
说明:position的属性中有static、fixed、relative、absolute四个属性。常用relative和absolute。若指定为static时,DIV遵循HTML规则;若指定为relative时,可以用top、left、right、bottom来设置DIV在页面中的偏移,但是此时不可使用层;若指定为absolute时,可以用top、left、right、bottom对DIV进行绝对定位;若指定为fixed时,在IE7与FF中DIV的位置相对于屏屏固定不变,IE6中没有效果(期待高手指点原因);
14、left:设置对象相对于文档层次中最近一个定位对象的左边界的位置。
15、top:设置对象相对于文档层次中最近一个定位对象的上边界的位置。
16、right:设置对象相对于文档层次中最近一个定位对象的右边界的位置。
17、bottom:设置对象相对于文档层次中最近一个定位对象的下边界的位置。
18、z-index:设置DIV的层叠顺序。
例:
<div >
</div>
<div rtcscls-3-s_sn_19_rId_a6 rtcscls-3-s_r_20_rId_a6 rtcscls-3-s_sn_3_rId_a0 rtcscls-3-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">background-color:Blue;z-index:1;">
</div>
<div >
</div>
说明:上例效果中如果不设z-index属性蓝DIV应该在中间,而现在的效果蓝在最上面了。还要说明的是用z-index属性时,position必需要指定为absolute才行。
19、font:指定DIV中文本的样式,其后可跟文本的多个样式。
例:
<div >
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。
</div>
说明:font后可以跟文本样式的多个属性,如字体粗细、字体大小、何种字体等等。还
可以用以下几个属性分别加以设置:
20、font-family:设置要用的字体名称;
21、font-weight:指定文本的粗细,其值有bold bolder lighter等。
22、font-size:指定文本的大小。
23、font-style:指定文本样式,其值有italic normal oblique等。
24、color:指定文本颜。
25、text-align:指定文本水平对齐方式,其值有center(居中) left right justify。
26、text-decorator:用于文本的修饰。其值有none underline overline line-through和blink的组合。
(在IE中无闪烁效果,FF中有效果。期待高手指点,)
27、text-indent:设置文本的缩进。
28、text-transform:设置文本的字母大小写。其值有lowercase uppercase capitalize(首字母大写) none。
例:
<div rtcscls-4-s_sn_19_rId_a6 rtcscls-4-s_r_20_rId_a6 rtcscls-4-s_sn_3_rId_a0 rtcscls-4-r_2" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_2%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33"> text-transform:capitalize;color:Blue; font:bold italic 14px 宋体; background-color:Yellow">
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。
abcdefghijklmnopqRSTUVWXYZ
</div>
29、overflow:内容溢出控制,其值有scroll(始终显示滚动条)、visible(不显示滚动条,但超出部分可见)、
auto(内容超出时显示滚动条)、hidden(超出时隐藏内容)。
30、direction:内容的流向。其值有ltr(从左至右)、rtl(从右至左)。
31、line-height:指定文本的行高。
32、Word-spacing:字间距。
例:
<div rtcscls-5-s_sn_19_rId_a6 rtcscls-5-s_r_20_rId_a6 rtcscls-5-s_sn_3_rId_a0 rtcscls-5-r_51" src="wkrtcs.bdimg/rtcs/image?w=10.87&md5sum=7e0919a41b05ff44b3c3cee2d0fc9ec1&sign=aebfe6fa45&rtcs_flag=2&rtcs_ver=3.1&l=webapp&bucketNum=46&ipr=%7B%22c%22%3A%22word%2Fmedia%2Fimage3.gif%22%2C%22dataType%22%3A%22gif%22%2C%22h%22%3A%2216.33%22%2C%22r%22%3A%5B%22s_sn_19_rId_a6%22%2C%22s_r_20_rId_a6%22%2C%22s_sn_3_rId_a0%22%2C%22r_51%22%5D%2C%22t%22%3A%22img%22%2C%22w%22%3A%2210.87%22%7D" width="10.87" height="16.33">direction:rtl; overflow:auto;background-color:Yellow">
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。<br />
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。<br />
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。<b
r />
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。
</div>
明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。
</div>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论