如何使用Javascript添加CSS?如何添加CSS规则(例如strong { color: red })使用Javascript?
3 回答

长风秋雁
TA贡献1757条经验 获得超7个赞
style
// Your CSS as textvar styles = ` .qwebirc-qui .ircwindow div { font-family: Georgia,Cambria,"Times New Roman",Times,serif; margin: 26px auto 0 auto; max-width: 650px; } .qwebirc-qui .lines { font-size: 18px; line-height: 1.58; letter-spacing: -.004em; } .qwebirc-qui .nicklist a { margin: 6px; } `var styleSheet = document.createElement("style")styleSheet.type = "text/css"styleSheet.innerText = styles document.head.appendChild(styleSheet)

小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
innerHTML
function insertCss( code ) { var style = document.createElement('style'); style.type = 'text/css'; if (style.styleSheet) { // IE style.styleSheet.cssText = code; } else { // Other browsers style.innerHTML = code; } document.getElementsByTagName("head")[0].appendChild( style );}
添加回答
举报
0/150
提交
取消