1

I have to use a custom icon in a button in jquery mobile.I have the icon with me and it is coming in the button.But the problem I am facing is,the default circle is appearing around my icon.I need to remove this border circle and just show the icon as it is.How to fix this issue?

This is the html I have:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width; initial-scale=1.0" />
        <link rel="stylesheet"  href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
        <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
           </head>
    <body>
        <div data-role="page" id="home">
            <div data-role="header" data-theme="b">
                <h1>Test</h1>
            </div>
            <div data-role="content" data-theme="b">
                <input type="button" data-inline="true" data-theme="b" data-icon="save-icon" data-iconpos="left" value="Save Data"></a>
            </div>
            <div data-role="footer" data-position="fixed" data-id="pFooter">
               <h1>Test</h1>
            </div>    
        </div>
   </body>
</html>

and the following CSS:

.ui-icon-save-icon{
    background:  url(save_icon.png) 50% 50% no-repeat; background-size: 19px 21px;
}

You can see it here - http://jsfiddle.net/yPRpt/

Please note that the icon is missing,but you can see the circle in the example.

7 Answers 7

4

The only way that I have found so far to do this is to set the 'data-icon' attribute on the element to 'custom' and then style it in the CSS using a transparent background image

ie in the markup:

<a id="hlFind" data-role="button" data-icon="custom">Find</a>

in the css:

#hlFind .ui-icon-custom {
    background:url("images/icon_phone_green.png") no-repeat scroll 0 0 transparent;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, thanks for the good idea. They key thing there is "transparent". I had an image that was 14x14 so added "background-size: 14px 14px". I was able to remove "scroll" and changed "0 0" to "2px 2px".
2

The only way you're going to be able to remove the semi-transparent circle that jQuery Mobile's theming adds to buttons is to identify and override the relevant CSS and / or Javascript responsible.

Alternatively, why not modify your custom icon to work with what jQM does?

Comments

1

I don't think you can remove the circle.

The documentation:

The jQuery Mobile framework...automatically adds a semi-transparent black circle

http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/buttons/buttons-icons.html

You might be able to create a non-transparent icon with the background as large as the circle and the same color as the button, but I am not sure this would work. (untested)

Comments

1

override the below code in jquery mobile css file

.ui-icon-searchfield:after {
    background:                         #666 /*{global-icon-color}*/;
    background:                         rgba(0,0,0,.4) /*{global-icon-disc}*/;
    background-image: url(images/icons-18-white.png) /*{global-icon-set}*/;
    background-repeat: no-repeat;
    -moz-border-radius:                 9px;
    -webkit-border-radius:              9px;
    border-radius:                      9px;
}

this part is causing the default black transparent image and the rounded cut offs

Comments

1

This post is well referenced on google. If anyone still looking for a simple solution, I just found one:

<p data-role="button"><img align="left" width="35px" src="something.jpg"/>Button name<p>

Hope this will help

2 Comments

Welcome on stackoverflow. Can you please put it in the example in the jsfiddle? Thanks!
This creates a button with an image perfectly, but the problem is that the text is not vertically aligned anymore. Probably needs a CSS change also.
0

override this css

.ui-btn-corner-all {

}

Comments

0

None of the solutions worked for me...

Just put your css code

.ui-icon-save-icon{
    background:  url(save_icon.png) 50% 50% no-repeat; background-size: 19px 21px;
}

and add a :after css event to set default circle size to 0, and the default circle will disappear! :)

.ui-icon-save-icon:after {
    width: 0px;
    height: 0px;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.