gpt4 book ai didi

javascript - Javascript 上的正确 CSS 代码

转载 作者:行者123 更新时间:2023-11-28 06:45:18 26 4
gpt4 key购买 nike

我得到了这段代码,但它似乎不起作用:

var widthrel = 1366 - width;
var minusp = widthrel / 2;
var final = 10 - minusp;

document.styleSheets[0].addRule('.main-container:before','left:'+ parseInt(final) + 'px');
document.styleSheets[0].insertRule('.main-container:before {left:'+ parseInt(final) + 'px;}', 0);
document.styleSheets[0].addRule('.main-container:after','right:'+ parseInt(final) + 'px');
document.styleSheets[0].insertRule('.main-container:after {right:'+ parseInt(final) + 'px;}', 0);

你能帮我吗?

最佳答案

if(document.styleSheets[0].addRule) { //IE9, Chrome
document.styleSheets[0].addRule(".main-container:before","left: "+parseInt(final)+"px;")
document.styleSheets[0].addRule(".main-container:after","right: "+parseInt(final)+"px;")
} else if(document.styleSheets[0].insertRule) { /// Opera
document.styleSheets[0].insertRule(".main-container:before {left: "+parseInt(final)+"px;}",0)
document.styleSheets[0].insertRule(".main-container:after {right: "+parseInt(final)+"px;}",0)
}

关于javascript - Javascript 上的正确 CSS 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com