简体   繁体   中英

What is “CSS on-the-fly”?

What is CSS on-the-fly? Does JavaScript allow to modify CSS on-the-fly?

Changing an Elements CSS Attributes

The easiest way to modify CSS on the fly is probably with Jquery:

$('#elementID').css("height", "300px");

First parameter is the CSS attribute, second is the new value.

Try and steer away from over using this, as it wont degrade nicely probably for people without Javascript enabled.

Changing CSS Classes

Related info: How can I change the css class rules using jQuery?

This afaik is not possible on the fly, see above link.

Yes. It does allow you to modify the CSS on the fly.

You can also use .style to access css styles in javascript eg

document.getElementById("anElement").style.width = "300px";

Though I think this might only affect single elements

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM