我正在尝试将元素的背景设置为no-repeat
- 我尝试了以下方式,但它似乎什么都不做,我在哪里出错?它会在a
链接上显示图像,这很好。我正在使用text-indent
隐藏文本链接以将其从页面中删除(隐藏它),但隐藏它也会隐藏背景图像。有没有办法试图隐藏链接,只显示bg图像?下面是我到目前为止所做的 - 我只需要一些指导来克服这个问题 - 相对较新的jQuery。
<script type="text/javascript"> //Looking for every td a element and alerting it out on page (popup)
$('.AspNet-DataList td a').each(function (index) {
//alert(index + ': ' + $(this).text());
var submitEl = $(".AspNet-DataList td a")
//.parent('.AspNet-DataList td a')
.css('background', 'url(/assets/img/radarstep' + (index + 1) + 'dark.png)', 'backgroundRepeat:', 'no-repeat');
});
当我在firebug中查看td a
元素时,这就是来自jQuery css的内容。即使从这里将背景设置为no-repeat
也无法正常工作,并且在主css文件中我尝试添加高度和宽度 - 似乎不起作用。现在很困惑。
<a id="ctl07_HealthAndSafetyRadarForm_Wizard_SideBarContainer_SideBarList_SideBarButton_5" href="javascript:__doPostBack('ctl00$ctl07$HealthAndSafetyRadarForm_Wizard$SideBarContainer$SideBarList$ctl05$SideBarButton','')" style="background: url("/assets/img/radarstep6dark.png") no-repeat scroll 0 0 transparent;">Review</a>
//main.css
.AspNet-DataList td a {
/*text-indent: -9999em;*/
/*display:block; */
background-repeat: no-repeat;
height: 25px;
width: 25px;
}
答案 0 :(得分:21)
.css({'background-image' : 'url(/assets/img/radarstep' + (index + 1) + 'dark.png)',
'background-repeat': 'no-repeat'});
答案 1 :(得分:2)
为什么评论display: block;
css?您需要告诉浏览器您的链接必须显示为块。
另外我不确定你可以像你一样使用jQuery css
属性;你尝试过语法div.css( { propertie: value, propertie: value } );
吗?
答案 2 :(得分:0)
试试这个:
.css({
'background-image': 'url(/assets/img/radarstep' + (index + 1) + 'dark.png)',
'background-repeat' : 'no-repeat'
});
答案 3 :(得分:0)
input[type="submit"] {background:url(mybutton.png);background-repeat:no-repeat;height: 29px;width: 44px; }
试试这个对我有用