简体   繁体   English

如何将每个CSS的jQuery UI图标设置为背景图像?

[英]How to set jquery ui icon as background image per css?

How can I set a jquery ui icon as a background image per a css container? 如何将每个CSS容器的jQuery UI图标设置为背景图像?

Something like: 就像是:

.MyClass {
  background: url("ui-icon-plus");
}

// Existing div...want to add icon to left-align
<div class="MyClass">
   //Other stuff in there that expands and collapses
</div>

UPDATE 更新

How can I get the following text to appear to the right of the icon? 如何使以下文本显示在图标的右侧?

<div class="MyClass">Whatever</div> <!-- no workee--> 
<div class="MyClass"><span class="MC">Whatever</span></div> <!-- works --> 

 .MyClass {
      width: 16px; height: 16px; background-image: url("../../Content/themes/base/images/ui-icons_222222_256x240.png")/*{iconsContent}*/;
      background-position : -16px -128px; 
}
.MC {
   padding-left: 20px;   
}

You have to apply the corresponding CSS class: 您必须应用相应的CSS类:

<div class="ui-icon ui-icon-plus"></div>

Assuming that you have the correct jQuery UI .css file with those classes defined. 假设您具有定义了这些类的正确jQuery UI .css文件。 If you look at the jQuery .css file you'll see that it is using background-position to find the icon in the CSS sprite . 如果查看jQuery .css文件,您会发现它使用background-positionCSS sprite中查找图标。

Look at the styles of the icons on Themeroller for examples . 请查看Themeroller上图标的样式作为示例

I would use: 我会用:

<div class="ui-icon ui-icon-plus"></div>

But if you need the css in your own class for some reason: 但是,由于某种原因,如果您需要在自己的类中使用CSS:

.MyClass { width: 16px; height: 16px; background-image: url(images/ui-icons_333333_256x240.png); background-position: -16px -128px; }

To get the icon you can directly refer the sprite like for plus. 要获得该图标,您可以直接将精灵指向加号。

 .MyClass {
width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png)/*{iconsContent}*/;
background-position: -16px -128px; 

}

您需要调用图像的绝对位置,例如:

.MyClass { background: url("http://yourdomain.com/somefolder/ui-icon-plus.ext"); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM