css中style="width:100px" 和width="100px"有什么不同

html-css011

css中style="width:100px" 和width="100px"有什么不同,第1张

本质上来讲两者没有区别,其作用都是定义元素的宽度为100px。但是区别在于:

1,style="width:100px"这种写法是可以应用在任何元素上的。

2,width="100px"这种写法有一定的局限性,其前提是此标签必须有默认width这个属性才行。

style表示样式,一般在页面上嵌套行内样式使用像<div style="" class="style"></div>或者<style>.style{color:red}</style>是在html页面上的写法。

0是背景图片的位置,表示顶部对齐,到顶部距离为0,center表示居中

css中背景样式分别如下:

background-color:#999999; //元素的背景色

background-image : url("path/bgFile.gif")//设置背景图像

background-repeat : repeat-x | repeat-y | repeat | no-repeat//设置重复方式

background-attachment : fixed | scroll//设置背景图片的固定方式

background-position : X轴坐标,Y轴坐标[top,bottom,center,left,right,20px,10%]

//设置背景的左上角位置,坐标可以是以百分比或固定单位

background  可以用这个属性把前面几个综合起来进行简写,

background 各个值的次序依次如下:

background-color | background-image  | background-repeat | background-attachment | background-position

例如:

.bg01{

background-color: #FFCC66

background-image: url("path/bgFile.gif")

background-repeat: no-repeat

background-attachment: fixed

background-position: left top

}

上面可以简写为:

.bg01{background:#FFCC66  url("path/bgFile.gif")  no-repeat  fixed  left  top}