gpt4 book ai didi

jQuery 包含 css

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:50 25 4
gpt4 key购买 nike

如何在里面添加css样式<body><head> , 像这样放置在 javascript 文件中:

<style type="text/css">
.popup-bg {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #eee;
}
</style>

唯一的方法是在 javascript 中编写 css,无法访问 html 或任何外部 css。

谢谢。

最佳答案

如果该类在您的结构/标记中用该类定义,则:

$(".popup-bg").css({ position: fixed, 
left: 0,
top: 0,
width: 100%,
height: 100%,
background: #eee
});

或将其添加到特定标签:

    $("body").css({ position: fixed,  
left: 0,
top: 0,
width: 100%,
height: 100%,
background: #eee
});

并注入(inject)它:

var style = document.createElement('style'); 

style.innerText = '.popup-bg{ position: fixed,
left: 0,
top: 0,
width: 100%,
height: 100%,
background: #eee
}';

document.head.appendChild(style);

关于jQuery 包含 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3039818/

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