我正在尝试将我的 jquery css 转换为外部 css 文件,但遇到了一些问题:
1. 是否可以在外部css
文件中使用sceen.width
?如果没有,
2. 如果我在外部 css 文件中设置元素样式,然后使用 jquery 设置相同元素的样式,哪个元素会被覆盖?
例子:
查询:
$("#mainBody").css(
{
'margin-top':"5px",width: screen.width,
position:"absolute",top:"135px"
});
外部CSS:
#mainBody
{
background:#f0eded;
height:98px;
margin-top:5px;
}
- 有没有办法将外部
css
文件与jquery css
结合起来?谢谢
最佳答案
是的,您的 jQuery 样式将覆盖样式表中的样式。
所以,你可以这样组合
#mainBody{
background:#f0eded;
height:98px;
margin-top:5px;
width:100px; //ARBITRARY... for example only
}
和
$("#mainBody").css('width', screen.width);
关于jquery - css 中的屏幕宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7376706/