CSS 中可以运算吗?? 比如 width:100%-10px;

lxy_lxy 2008-11-06 09:35:05
CSS 中可以运算吗?? 比如如下:

.div1
{
width:100%-10px;
height:50px;
color:#ffffff;
}

...全文
1650 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
F91KDASH 2010-08-12
  • 打赏
  • 举报
回复
.div1
{
width:expression((obj.width - 10) + "px");
height:50px;
color:#ffffff;
}

原來還可以這麼用,學習了。
csxrzeng 2009-02-18
  • 打赏
  • 举报
回复
还是不能啊~~~
ShowWin 2008-11-09
  • 打赏
  • 举报
回复
css 可以使用表达示。。但是不推荐。占资源太严重了。。
gengwanshanreally 2008-11-08
  • 打赏
  • 举报
回复
不报错就正确,呵呵!
greatverve 2008-11-08
  • 打赏
  • 举报
回复
width:expression((obj.width - 10) + "px");
学到一点,一会试试。
lxy_lxy 2008-11-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yoursWTR 的回复:]
可以在CSS里面用JS

.div1
{
width:expression((obj.width - 10) + "px");
height:50px;
color:#ffffff;
}
[/Quote]
这样也可以呀···可是 obj 指的是什么呢···??哪一个对象呢~~?
Silver_1987 2008-11-07
  • 打赏
  • 举报
回复
应该只能用JS来控制CSS里的东西吧
wfyfngu 2008-11-07
  • 打赏
  • 举报
回复
IE8开始不支持CSS中使用表达式。


What is a CSS expression ?

Also known as ‘Dynamic Properties’, this proprietary CSS extension was introduced in Internet Explorer 5. Long before JavaScript libraries such as jQuery or Dojo were conceived, it allowed web developers to dynamically bind script to the page through CSS selectors. As an example, the following CSS declaration updates the background color of certain page blocks depending on the time of day :

div.title { background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" ); }

Why end support for expressions ?

To comply with standards
Expressions are proprietary to Internet Explorer and as such not interoperable.
A common use-case for expressions was to fix IE bugs or to emulate those CSS 2.1 features not yet supported by the browser, for example, min-width and max-width. We have not only worked hard to fix these bugs in IE8 but our new layout engine supports the missing features natively.
To improve performance
Expressions evaluation has a high runtime cost; web performance experts like Steve Souders recommend avoiding them to improve front-end performance
To reduce the browser attack surface
Because they expose a script execution context, CSS expressions constitute a possible script injection attack vector.
Are expressions still available in IE7 and Quirks mode ?

Yes. For backward compatibility, CSS expressions are still executed in Quirks and IE7 Strict modes. But starting with IE8 Beta 2, they are ignored in IE8 Standards mode.

Pages on my web site depend on CSS expressions. How does this affect me ?

Thanks to IE8’s new layout engine, most expressions written to work around CSS 2.1 bugs and shortcomings should no longer be needed; we expect unsupported or incorrectly interpreted properties to work in a standard, interoperable way. For those expressions supporting more specific purposes, anything they do is inherently achievable using standard JavaScript, usually interoperably and at lower runtime costs. The specifics will of course depend on your application. Based on your feedback to this post, we may visit examples in future installments.

Ending support for expressions - a feature often used to fix the very issues we have worked hard to address in this release – helps make IE8 more standard, faster and more secure for our users.

Sylvain Galineau
Program Manager

Posted by ieblog | 78 Comments
Filed under: Developers, Security

toxxj 2008-11-06
  • 打赏
  • 举报
回复
这个真的没试过啊,第一次看到楼主这样,我也要去试一下了,呵呵
lutianling521 2008-11-06
  • 打赏
  • 举报
回复
up
oec2003 2008-11-06
  • 打赏
  • 举报
回复
呵呵 没这样用过
具体行不行 试试不就知道
takeshe 2008-11-06
  • 打赏
  • 举报
回复
可不可以`这种东西自己试一下不就出来了``
mingch516548094 2008-11-06
  • 打赏
  • 举报
回复
不可以。
yoursWTR 2008-11-06
  • 打赏
  • 举报
回复
firefox不支持
yoursWTR 2008-11-06
  • 打赏
  • 举报
回复
可以在CSS里面用JS

.div1
{
width:expression((obj.width - 10) + "px");
height:50px;
color:#ffffff;
}
koukoujiayi 2008-11-06
  • 打赏
  • 举报
回复
哦!楼主有创意,大概不行吧!
sharpblade 2008-11-06
  • 打赏
  • 举报
回复
没这样的语法

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧