English 中文(简体)
Can I set a Custom Icon for a jQueryUI Button
原标题:

Is it possible to create a jQueryUI Button with a custom icon, ie: an icon that is not part of the sprite icons that are provided with jQueryUI???

I am using the ButtonSet functionality for a group of 3 checkboxes but need a more stylised icon than what is provided out of the box...

最佳回答

Worked it out with a CSS hack.

Setup the button as per normal and give the primary icon the "Error" class defined below

.Error
{
    background-image: url( Images/Icons/16/Error.png ) !important;
}

The !important overrides the ui-icon definition for background-image.

问题回答

I took this approach for one of my buttons and I discovered some interesting things:

  1. I didn t need to use the "!important" override
  2. I needed to set background-position for my button (otherwise I think the background was being displayed well outside the button)
  3. It looks like you can also put anything you like in the jQueryUI primary icon name - it just needs something as a placeholder.

For my uses I ended up with:

Javascript:

jQuery(function() {
    jQuery( #share-button ).button({
        icons: { primary: "icons/share" }
    });

});

CSS:

#share-button > span.ui-icon {
    background-image: url(icons/share.png);
    background-position:0px 3px;}

HTML:

<button id= share-button >Share</button>




相关问题
C#和Lotus Notes附录一

我正在使用C#,并需要附上一张空白(shortcut/link)档案和电子邮件给一个彩票账户。 问题是一对一幅通用形象的不实之词,没有像......那样显示双fold。

Load the Default Icon For the Shell

The default icon in Vista is listed under: HKEY_CLASSES_ROOT Unknown DefaultIcon As: %SystemRoot%System32shell32.dll,0 I want to load a 48x48 version of that Icon in C++. I have tried: ...

How to access Google/Gmail/Gchat/Reader user icons

I m building a Google Reader client and wonder if it s possible to access a user s profile image (aka avatar) directly. When I navigate to the images in Reader itself, I find that they point to URLs ...

How to tell Windows Explorer to refresh its icons?

Once my installer finishes installing new versions of my application s exe, I d like to tell Explorer to use the new exe s icons for its shortcuts. However, I cannot figure out how to do this. From ...

Outlook 2003 - Add an icon column to a View?

I want to add a custom column to the Inbox which is a Yes/No column. I want an icon to show in the Yes case. How can I do this? Everything I ve looked up is either about adding a column through the ...

热门标签