最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to embed Javascript in CSS? - Stack Overflow

programmeradmin0浏览0评论

I have a CSS file, which contain the style information of my web. Some height & width is based on the screen size, so I can calculate the size using the Javascript, can I embedded the javascript in the CSS file to do so?

I have a CSS file, which contain the style information of my web. Some height & width is based on the screen size, so I can calculate the size using the Javascript, can I embedded the javascript in the CSS file to do so?

Share Improve this question edited Oct 25, 2009 at 11:35 Gabriel Hurley 40.1k14 gold badges63 silver badges89 bronze badges asked Oct 25, 2009 at 10:37 DNB5brimsDNB5brims 30.6k50 gold badges134 silver badges204 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

In IE, and only IE, you can use CSS expressions:

width: expression(blah + "px");

Then width bees whatever's inside the brackets.

This only works in IE, though - so don't use it. Use a JS function to assign the elements the style with element.style.width or similar.

For example:

<script type="text/javascript">
    document.getElementById('header').style.width = (100 * 2) + 'px';
</script>

I don't think so, but you can do the opposite, i.e. make the javascript create an inline css on the fly.

发布评论

评论列表(0)

  1. 暂无评论