How do I embed Javascript in CSS?

I have a CSS file that contains styling information for my website. Some heights and widths are based on screen size, so I can calculate the size using Javascript, can I embed javascript in the CSS file to do this?

+2


source to share


2 answers


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

width: expression(blah + "px");

      

Then width

it becomes inside the parenthesis.



This only works in IE, so it doesn't use it . Use JS function to style your elements with element.style.width

or similar.

For example:

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

      

+7


source


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



+2


source







All Articles