CSS expression判斷表達(dá)式設(shè)置input樣式
發(fā)布時(shí)間:2009-06-14 23:52:35 作者:佚名
我要評(píng)論

用CSS的expression判斷表達(dá)式設(shè)置input樣式,簡(jiǎn)單,輕量級(jí)。缺點(diǎn)在于expression判斷表達(dá)式FireFox是不支持的。致命的是只能區(qū)分出一個(gè)(例如例子中就只能區(qū)分出text文本框),不要試圖設(shè)置多個(gè)…
代碼:
[code]
<!doctype html public "-//W3C//DTD XHTML
用CSS的expression判斷表達(dá)式設(shè)置input樣式,簡(jiǎn)單,輕量級(jí)。缺點(diǎn)在于expression判斷表達(dá)式FireFox是不支持的。致命的是只能區(qū)分出一個(gè)(例如例子中就只能區(qū)分出text文本框),不要試圖設(shè)置多個(gè)…
代碼:
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>www.52CSS.com</title>
<meta name="Author" content="JustinYoung"/>
<meta name="Keywords" content=""/>
<meta name="Description" content=""/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
input
{
background-color:expression(this.type=="text"?'#FFC':'');
}
</style>
</head>
<body>
<dl>
<dt>This is normal textbox:<dd><input type="text" name="">
<dt>This is normal button:<dd><input type="button" value="i'm button">
</dl>
</body>
</html>
另一種方法:
input{
zoom: expression(function(ele){(ele.className)?ele.className+=" "+ele.type:ele.className=ele.type; ele.style.zoom = "1";}(this));
}
1、將 input 的屬性取出來,賦給 className。
2、對(duì)于 expression,這里使用一個(gè)無關(guān)緊要的屬性(此處是zoom)來觸發(fā),處理完需要做的事情之后,再將此屬性覆蓋掉以解決 expression 不斷執(zhí)行的效率問題。
代碼:
<!--[if lt IE 7]>
<style type="text/css" media="screen">
input{
zoom: expression(function(ele){(ele.className)?ele.className+=" "+ele.type:ele.className=ele.type; ele.style.zoom = "1";}(this));
}
input.text{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
background: #F5F5F5;
}
input.password{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
color: #000; background: #F5F5F5;
width: 50px;
}
input.button{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #000; font-weight: bold; background: #F5F5F5;
}
input.reset{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #666; background: #F5F5F5;
}
</style>
<![endif]-->
<style type="text/css" media="all">
input[type="text"]{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
background: #F5F5F5;
}
input[type="password"]{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
color: #000; background: #F5F5F5;
width: 50px;
}
input[type="button"]{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #000; font-weight: bold; background: #F5F5F5;
}
input[type="reset"]{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #666; background: #F5F5F5;
}
</style>
</head>
<body>
<input type="text" name="xx" />
<input type="password" name="yy" />
<input type="checkbox" name="oo" />
<input type="radio" name="pp" />
<input type="button" name="qq" value="button" />
<input type="reset" name="oo" value="reset" />
</body>
</html>
代碼:
復(fù)制代碼
代碼如下:<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>www.52CSS.com</title>
<meta name="Author" content="JustinYoung"/>
<meta name="Keywords" content=""/>
<meta name="Description" content=""/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
input
{
background-color:expression(this.type=="text"?'#FFC':'');
}
</style>
</head>
<body>
<dl>
<dt>This is normal textbox:<dd><input type="text" name="">
<dt>This is normal button:<dd><input type="button" value="i'm button">
</dl>
</body>
</html>
另一種方法:
復(fù)制代碼
代碼如下:input{
zoom: expression(function(ele){(ele.className)?ele.className+=" "+ele.type:ele.className=ele.type; ele.style.zoom = "1";}(this));
}
1、將 input 的屬性取出來,賦給 className。
2、對(duì)于 expression,這里使用一個(gè)無關(guān)緊要的屬性(此處是zoom)來觸發(fā),處理完需要做的事情之后,再將此屬性覆蓋掉以解決 expression 不斷執(zhí)行的效率問題。
代碼:
復(fù)制代碼
代碼如下:<!--[if lt IE 7]>
<style type="text/css" media="screen">
input{
zoom: expression(function(ele){(ele.className)?ele.className+=" "+ele.type:ele.className=ele.type; ele.style.zoom = "1";}(this));
}
input.text{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
background: #F5F5F5;
}
input.password{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
color: #000; background: #F5F5F5;
width: 50px;
}
input.button{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #000; font-weight: bold; background: #F5F5F5;
}
input.reset{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #666; background: #F5F5F5;
}
</style>
<![endif]-->
<style type="text/css" media="all">
input[type="text"]{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
background: #F5F5F5;
}
input[type="password"]{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
color: #000; background: #F5F5F5;
width: 50px;
}
input[type="button"]{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #000; font-weight: bold; background: #F5F5F5;
}
input[type="reset"]{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #666; background: #F5F5F5;
}
</style>
</head>
<body>
<input type="text" name="xx" />
<input type="password" name="yy" />
<input type="checkbox" name="oo" />
<input type="radio" name="pp" />
<input type="button" name="qq" value="button" />
<input type="reset" name="oo" value="reset" />
</body>
</html>
相關(guān)文章
- CSS中寫expression可能會(huì)在Chrome中有問題.2010-01-27
優(yōu)化瀏覽器渲染 避免CSS expressions
CSS表達(dá)式會(huì)降低瀏覽器的渲染性能;用其他方案替換它們將會(huì)改善IE瀏覽器的渲染性能。2010-03-09CSS中使用expression完美設(shè)置頁面最小寬度(兼容ie)
CSS中使用expression有ie才能識(shí)別,其把CSS屬性和Javascript表達(dá)式關(guān)聯(lián)起來,效果相當(dāng)于min-width,即實(shí)現(xiàn)了兼容ie,示例如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫2013-07-31css expression使用概述及其優(yōu)缺點(diǎn)介紹
css expression(css表達(dá)式)又稱Dynamic properties(動(dòng)態(tài)屬性)是早期微軟DHTML的產(chǎn)物,微軟從IE8 beta2標(biāo)準(zhǔn)模式開始,取消對(duì)css expression的支持,感興趣的朋友可以了解下2013-11-04CSS行為expression輕松實(shí)現(xiàn)IE6無抖動(dòng)固定定位
IE6不支持固定定位(position:fixed)是眾所周知的事情,想在IE6做出固定定位的效果就只能用JS,用js會(huì)出現(xiàn)“跳動(dòng)”的效果,下面為大家介紹下CSS中的行為expression2014-03-03CSS表達(dá)式(expression)解決IE6 position:fixed無效問題
IE6 position:fixed無效在做兼容時(shí),很是頭疼,本例通過一條Internet Explorer的CSS表達(dá)式(expression)來完美的實(shí)現(xiàn)ie6下position:fixed效果,有需要的朋友可以參考下2014-07-28- 這篇文章主要介紹了CSS中使用expression表達(dá)式,需要的朋友可以參考下2014-12-22