用js控制css基本樣式的方法
css code
.class1
html code
aaa(2)
aaa還可以用 document.stylesheets(i).href 可以知道當前頁面中引用的每個css的檔案!
另:css屬性與j**ascript編碼對照表
(一定要注意, 上次本人_何向陽,在使用js修改css的中margin-left屬性時,總報"left"未定義,後來,找了好多資料,才發現在js中,margin-left的寫法為:marginleft,恍然大悟,希望遇到相同問題的朋友,謹慎對待。)
css與js緊密配合,為我們的頁面增添了很多別緻的效果。為了達到某種特殊的效果我們需要用j**ascript動態的去更改某乙個標籤的css屬性。
比如:滑鼠經過乙個時我們讓加乙個邊框,**可能是這樣:j**ascript中style後面的屬性應該是什麼?
j**ascript css style屬性對照表
盒子標籤和屬性對照
css語法 (不區分大小寫) j**ascript語法 (區分大小寫)
border border
border-bottom borderbottom
border-bottom-color borderbottomcolor
border-bottom-style borderbottomstyle
border-bottom-width borderbottomwidth
border-color bordercolor
border-left borderleft
border-left-color borderleftcolor
border-left-style borderleftstyle
border-left-width borderleftwidth
border-right borderright
border-right-color borderrightcolor
border-right-style borderrightstyle
border-right-width borderrightwidth
border-style borderstyle
border-top bordertop
border-top-color bordertopcolor
border-top-style bordertopstyle
border-top-width bordertopwidth
border-width borderwidth
clear clear
float floatstyle
margin margin
margin-bottom marginbottom
margin-left marginleft
margin-right marginright
margin-top margintop
padding padding
padding-bottom paddingbottom
padding-left paddingleft
padding-right paddingright
padding-top paddingtop
顏色和背景標籤和屬性對照
css語法 (不區分大小寫) j**ascript語法 (區分大小寫)
background background
background-attachment backgroundattachment
background-color backgroundcolor
background-image backgroundimage
background-position backgroundposition
background-repeat backgroundrepeat
color color
樣式標籤和屬性對照
css語法 (不區分大小寫) j**ascript語法 (區分大小寫)
display display
list-style-type liststyletype
list-style-image liststyleimage
list-style-position liststyleposition
list-style liststyle
white-space whitespace
文字樣式標籤和屬性對照
css語法 (不區分大小寫) j**ascript語法 (區分大小寫)
font font
font-family fontfamily
font-size fontsize
font-style fontstyle
font-variant fontvariant
font-weight fontweight
文字標籤和屬性對照
css語法 (不區分大小寫) j**ascript語法 (區分大小寫)
letter-spacing letterspacing
line-break linebreak
line-height lineheight
text-align textalign
text-decoration textdecoration
text-indent textindent
text-justify textjustify
text-transform texttransform
vertical-align verticalalign
obj.style方法,這個方法只能js只能獲取寫在html標籤中的寫在style屬性中的值(style="..."),看一下**
xml/html**
js獲取css屬性值
上面這個例子對id為"css88"的div設定了2種煩事的樣式,包括style和外部樣式class。
從alert出來的資訊可以看到,document.getelementbyid("css88").style方法獲取不到class為ss的屬性和值。
那麼這麼樣才能獲取到class為ss的屬性和值呢?
ie中使用的是obj.currentstyle方法,而ff是用的是getcomputedstyle 方法。
網上乙個比較方法是:
xml/html**
sdf當然,如果您是引用外部的css檔案同樣適用。
另:可以將上面的方法簡化為
j**ascript**
function getdefaultstyle(obj,attribute){ // 返回最終樣式函式,相容ie和dom,設定引數:元素物件、樣式特性
return obj.currentstyle?obj.currentstyle[attribute]:document.defaultview.getcomputedstyle(obj,false)[attribute];
用css控制滑鼠樣式
用css控制滑鼠樣式的語法如下 文字或其它頁面元素 把 換成如下15個效果的一種 下面是對這15種效果的解釋。移動滑鼠到解釋上面,看看你的滑鼠起了什麼變化吧!hand是手型 pointer也是手型,這裡推薦使用這種,因為這可以在多種瀏覽器下使用。crosshair是十字型 text是移動到文字上的那...
用css控制滑鼠樣式語法
文字或其它頁面元素 把 換成如下15個效果的一種 下面是對這15種效果的解釋。移動滑鼠到解釋上面,看看你的滑鼠起了什麼變化吧!hand是手型 pointer也是手型,這裡推薦使用這種,因為這可以在多種瀏覽器下使用。crosshair是十字型 text是移動到文字上的那種效果 wait是等待的那種效果...
CSS和JS結合控制樣式
css控制樣式,毋庸置疑。但有時,僅靠css卻很難控制好,比如說,頁面在多種條件下進行不同的呈現 或者執行過程中,會發生變化,比如說,左側的選單欄收縮了,那麼右側的寬度就變大了。就拿這個元素的width height來說,頁面變了,預先設定的值就不合適 甚至乎,從一開始,你就不知道該預先設定什麼值,...