html - CSS 表达式

标签 html css css-expressions

我在某处读到 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>

这让我想起了那些在页面底部有“分享栏”和东西的网站。

所以...

  1. 他们是这样做的吗?
  2. 在这种情况下可以使用表达式吗?
  3. 如果没有,我应该使用什么?
  4. 表达式还有其他有趣/有用的东西吗?

最佳答案

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/

相关文章:

css - IE6 css hack 及其标准 css 等效项?

css - 多个 css 表达式 IE

html - 避免 CSS 表达式

html - 网站更新延迟(保存时不更新)

html - 如何结合 Noto Sans CJK SC 和 Noto Sans CJK TC

html - 使用伪元素定位特定的 div

javascript - 如何将 child 的div高度扩展到 parent 的高度

javascript - 如何从 CSS(不是 jquery 或 javascript)向元素添加 CSS 类?

c# - 如何从另一个 .aspx 页面更新一个 .aspx 页面的 div?

html - 不循环提取内部元素