我在某处读到 CSS 表达式已被弃用,甚至不应该使用。我从未听说过它们,因此决定看一看。我找到了一个代码示例,它使 float 元素保持在屏幕上的同一位置,即使您滚动也是如此。
<html>
<style>
#fixed {
position:absolute;
left:10px;
top:expression(body.scrollTop + 50 + "px");
background:white;
border:1px solid red;}
</style>
<body>
<p id="fixed">Here is some text, which is fixed.</p>
<p>
[many times: "stuff <br/>"]
</p>
</body>
</html>
这让我想起了那些在页面底部有“分享栏”和东西的网站。
所以...
- 他们是这样做的吗?
- 在这种情况下可以使用表达式吗?
- 如果没有,我应该使用什么?
- 表达式还有其他有趣/有用的东西吗?
最佳答案
CSS 表达式曾经在旧的 IE 中工作,但现在已被 completely abandoned in IE8:
Dynamic properties (also called "CSS expressions") are no longer supported in Internet Explorer 8 and later, in IE8 Standards mode and higher. This decision was made for standards compliance, browser performance, and security reasons, as detailed in the IE blog entry titled Ending Expressions. Dynamic properties are still available in Internet Explorer 8 in either IE7 mode or IE5 mode.
因此可以说不再值得学习它们了。
If not, what should I use?
根据用例,JavaScript 或 media queries .
正如@Yet Another Geek 所说,您上面的示例可以使用position: fixed
来实现。 IE6 不支持 - CSS 表达式可能是为了解决这个问题而创建的。
关于html - CSS 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191679/