CSS自定义属性Expression

1.给元素固有属性赋值
在图片缩放时用得最多
下面是定义container容器的宽度,若是<725就为本身的宽度,不然就等于725,至关于max-width:725px;。
<style type="text/css" media="screen">
#container { width: expression((documentElement.clientWidth > 725) ? "725px" : "auto" ); }
</style>
2.给元素自定义属性赋值   
有了CSS的自定义属性Expression,能够本身定义属性,本身在属性里写须要的代码,这样就能够结合CSS的特性与JS特效,实现对总体页面上相同元素的控制。是否是以为有点难以想象?咱们先拿新手们常常问的怎么消除页面上的连接虚线框为例。 

一般的作法是:
<a href="link1.htm" onfocus="this.blur()">link1</a>
<a href="link2.htm" onfocus="this.blur()">link2</a>
<a href="link3.htm" onfocus="this.blur()">link3</a>
粗看或许还体现不出采用expression的优点,但若是你的页面上有几十甚至上百个连接,这时的你难道还会机械式地Ctrl+C,Ctrl+V么,况且二者一比较,哪一个产生的冗余代码更多呢? css

采用expression的作法以下:
<a href="link1.htm">link1</a>
<a href="link2.htm">link2</a>
<a href="link3.htm">link3</a>

  说明:里面的star就是本身任意定义的属性,你能够随本身喜爱另外定义,接着包含在expression()里的语句就是JS脚本,在自定义属性与expression之间可别忘了还有一个引号,由于实质仍是CSS,因此放在style标签内,而非script内。OK,这样就很容易地用一句话实现了页面中的连接虚线框的消除。不过你先别得意,若是触发的特效是CSS的属性变化,那么出来的结果会跟你的本意有差异。例如你想随鼠标的移进移出而改变页面中的文本框颜色更改,你可能想固然的会认为应该写
<style type="text/css">
input {star : expression(onmouseover=this.style.backgroundColor="#FF0000";
onmouseout=this.style.backgroundColor="#FFFFFF")}
</style>
<input type="text">
<input type="text">
<input type="text">

  可结果倒是出现脚本出错,正确的写法应该把CSS样式的定义写进函数内,以下所示:
<style type="text/css">
input {star : expression(onmouseover=function()
 {this.style.backgroundColor="#FF0000"},
onmouseout=function(){this.style.backgroundColor="#FFFFFF"}) }
</style>
<input type="text">
<input type="text">
<input type="text"> express