Jquery 如何覆盖css属性?
我尝试使用jquery,但无法覆盖Jquery 如何覆盖css属性?,jquery,html,css,properties,Jquery,Html,Css,Properties,我尝试使用jquery,但无法覆盖.gridHeader类的width属性 我想确定(比如说100px)表中第一列的宽度 <html> <head> <style> html, body { font-family:Tahoma; font-size:11px; } .grid {
.gridHeader
类的width属性
我想确定(比如说100px)表中第一列的宽度
<html>
<head>
<style>
html, body {
font-family:Tahoma;
font-size:11px;
}
.grid {
border-left:1px solid #CCCCCC;
border-top:1px solid #CCCCCC;
}
.gridHeader {
background-color:#EFEFEF;
border-bottom:1px solid #CCCCCC;
font-weight:bold;
height:20px;
padding-left:3px;
text-align:left;
width:100%; /* problematic, that I cannot change*/
}
table.grid > tbody > tr > td {
border-bottom:1px solid #CCCCCC;
border-right:1px solid #CCCCCC;
padding:3px;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".gridHeader").css("width","");
});
</script>
</head>
<body>
<table width="100%">
<tr>
<td class="gridHeader" style="width:100px">Vikas
</td>
<td class="gridHeader">Vikas Patel Vikas Patel Vikas Patel
</td>
<td class="gridHeader">Vikas Patel Vikas Patel
</td>
</tr>
<tr>
<td>Vikas
</td>
<td>Vikas Patel Vikas Patel Vikas Patel
</td>
<td>Vikas Patel Vikas Patel
</td>
</tr>
</table>
</body>
</html>
html,正文{
字体系列:Tahoma;
字体大小:11px;
}
.电网{
左边框:1px实心#中交;
边框顶部:1px实心#中交;
}
.gridHeader{
背景色:#EFEF;
边框底部:1px实心#CCCC;
字体大小:粗体;
高度:20px;
左:3倍;
文本对齐:左对齐;
宽度:100%;/*有问题,我无法更改*/
}
表1.grid>tbody>tr>td{
边框底部:1px实心#CCCC;
右边框:1px实心#中交;
填充:3倍;
}
$(文档).ready(函数(){
$(“.gridHeader”).css(“宽度”,“宽度”);
});
维卡斯
Vikas Patel Vikas Patel Vikas Patel
Vikas Patel Vikas Patel
维卡斯
Vikas Patel Vikas Patel Vikas Patel
Vikas Patel Vikas Patel
您需要使用删除内联样式,然后使用css()
方法,如下所示:
$(".gridHeader").removeAttr('style').css("width","100px");
$(".gridHeader:first").removeAttr('style').css("width","100px");
style="width:100px !important;"
如果只想将宽度应用于第一列,可以使用如下过滤器选择器:
$(".gridHeader").removeAttr('style').css("width","100px");
$(".gridHeader:first").removeAttr('style').css("width","100px");
style="width:100px !important;"
对我来说行吗?除非我不明白你的“问题”
勾选:如果您想覆盖CSS内联,您可能会幸运地这样做:
$(".gridHeader").removeAttr('style').css("width","100px");
$(".gridHeader:first").removeAttr('style').css("width","100px");
style="width:100px !important;"
我猜你的问题不是第一栏,而是其他栏,尽管它们仍然100%适用
$(".gridHeader").css("width","");
…不起作用,因为你没有设定法律价值
试试这个:
$(".gridHeader").not(':first-child').css("width","auto");
这是因为我将“”设置为新宽度,如果我将其设置为“100px”,那么它可以工作,有趣吗?为什么?你在我的密码里试过了吗?在firebug中,我们似乎覆盖了它,但效果并不完全是我想要的,如果我设置了500px,请注意实际宽度。你的答案是正确的,但效果并不完全是我想要的,如果我为第一列设置了500px,请注意实际宽度。@Vikas:你可以使用
width
方法设置任何宽度,如图所示。旧帖子,但你保存了我的皮肤。