Changing jQuery UI Button size?
I've been using the jQuery UI button all over my page, however I haven't found a way around what seems to be a simple problem. I want some of my buttons to be smaller than the other, this should be as simple as setting the CSS of the button text to something like, font: .8em;
However jQuery UI takes your DOM element and wraps it:
<button class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all">
<span class="ui-button-text">Button Label</span>
</button>
So if I have a <button class="small-button">Small button!</button>
jQuery will place the text in a child span. Any font size given to the small-button
class will be ignored.
There's got to be a way around this without hacking at how jQuery makes its buttons. Any ideas?
Solution 1:
If it's styling ui-button-text
with font-size
directly, you can override it at a higher level by applying !important. Such as:
.small-button {
font-size: .8em !important;
}
EDIT: try setting a CSS style directly on .ui-button-text
to inherit:
.ui-button-text {
font-size: inherit !important;
}
This should also make the !important on the .small-button
irrelevant.
Solution 2:
This helped decrease the height of the button for me (Smoothness theme default is line-height of 1.4):
.ui-button .ui-button-text
{
line-height: 1.0;
}
Solution 3:
Here is what I use in my websites to setup the font-sizes so that my button sizes are the same as on the jQuery UI website. This works because it's exactly how the jQuery UI website does it!
/* percentage to px scale (very simple)
80% = 8px
100% = 10px
120% = 12px
140% = 14px
180% = 18px
240% = 24px
260% = 26px
*/
body
{
font-family: Arial, Helvetica, sans-serif;
font-size:10px;
}
By setting the font-size properties like that for the body element, setting the font-size for everything else becomes trivial as 100% = 10px.
Just watch out for the cascading effect when using percentages - a child element's 100% will be equal to the parent element's font-size.