CSS注意事項有哪些

在使用CSS應該儘量避免使用哪些技術?下面yjbys小編爲大家整理使用CSS的注意事項,希望對大家學習CSS語言有幫助!

CSS注意事項有哪些

Internet Explorer Behaviors

它是什麼?Internet Explorer 5 引入了行爲 (behaviors)。behaviors 是一種通過使用 CSS 向 HTML 元素添加行爲的方法。

爲什麼要避免它?只有 Internet Explorer 支持 behavior 屬性。

用什麼代替?請使用 JavaScript 和 HTML DOM 取而代之。

  例子 1 - Mouseover Highlight

下面的. HTML 文件中有一個 <style> 元素,它爲 <h1> 元素定義了一個行爲:

<html>

<head>

<style type="text/css">

h1 { behavior: url() }

</style>

</head>

<body>

<h1>Mouse over me!!!</h1>

</body>

</html>

下面是 XML 文檔 "":

<attach for="element" event="onmouseover" handler="hig_lite" />

<attach for="element" event="onmouseout" handler="low_lite" />

<script type="text/javascript">

function hig_lite()

{

r='red';

}

function low_lite()

{

r='blue';

}

</script>

behavior 文件包含了針對元素的 JavaScript 和 事件句柄。

如果您使用 Internet Explorer,可以親自試一下(把鼠標放在例子中的文本上)。

  例子 2 - Typewriter Simulation

下面的 HTML 文件中有一個 <style> 元素,它爲 id 爲 "typing" 的元素定義了一個行爲:

<html>

<head>

<style type="text/css">

#typing

{

behavior:url(behave_);

font-family:'courier new';

}

</style>

</head>

<body>

<span id="typing" speed="100">IE5 introduced DHTML behaviors.

Behaviors are a way to add DHTML functionality to HTML elements

with the ease of CSS.<br /><br />How do behaviors work?<br />

By using XML we can link behaviors to any element in a web page

and manipulate that element.</p>

</span>

</body>

</html>

下面是 XML 文檔 "":

<attach for="window" event="onload" handler="beginTyping" />

<method name="type" />

<script type="text/javascript">

var i,text1,text2,textLength,t;

function beginTyping()

{

i=0;

text1=rText;

textLength=th;

rText="";

text2="";

t=nterval(+"()",speed);

}

function type()

{

text2=text2+tring(i,i+1);

rText=text2;

i=i+1;

if (i==textLength)

{

clearInterval(t);

}

}

</script>