我有一个元素的 id,css 是这样的:
#red {
background-color: #2ac0a3;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
position: relative;
bottom: 220px;
left: 365px;
}
我想向#red div 添加一个类来覆盖该位置,但它似乎不起作用。有什么想法吗?
JS:
$('#red').addClass('ya');
CSS
.ya{
position: relative;
left: 900px;
}
谢谢!
最佳答案
ID 的优先级高于类。要覆盖 ID 样式,您需要一个更具体的选择器:
.ya, #red.ya {
position: relative;
left: 900px;
}
关于javascript - 覆盖类定位的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21149877/