Float and jQuery UI button
I used jQuery UI buttons in a project, and they have been working fine.
But, in IE7, the icon doesn开发者_如何学运维't float as it should. I realise IE doesn't have rounded corners support yet, but that is OK.
Good browsersSome browsers render it fine
IE sucks version 7 does not:
I start with a button in the HTML
<button type="submit"><span class="ui-icon ui-icon-mail-closed"></span>Send</button>
I then loop through the buttons, using this little bit of jQuery on each
$('#content button').each(function() {
var icon = $(this).find('span.ui-icon');
var primaryIcon = icon.attr('class').replace(/ui-icon\s?/, '');
icon.remove();
$(this).button({ icons: {primary: primaryIcon }, label: $(this).text() });
});
I was just calling button()
on them, but I decided to do this to make sure I was using the library the way it was designed.
I had some CSS on the icon too
button span.ui-icon {
display: inline;
float: left;
margin-right: 0.1em;
}
The page from above is also available. (shortened to void HTTP referrer, I hope).
What am I doing wrong?
Thanks very much!
Update
I tried making the icon as an inline block element, as per Meder's answer.
button span.ui-icon {
display: inline;
float: left;
margin-right: 0.1em;
margin-top: -1px;
/* get rid of margin for inline element */
#margin: auto;
/* this should revert the element to inline as per declaration above */
#float: none;
/* hasLayout = true */
#zoom: 1;
}
This, however, has the unusual affect of blanking the button elements!
Whatever shall I do?
Anyway, when you float an element it becomes a block box. Display:inline is useless. And you should always set a width on floated items.
You need to explicitly define a width for horizontal floats or the float drops. The alternative is using inline-block.
If that doesn't work let me know.
<button type="submit"><span class="ui-icon ui-icon-mail-closed"></span><span style="float:left;">Send</span></button>
your rendered html,
<button type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button" aria-disabled="false">
<span class="ui-button-icon-primary ui-icon ui-icon-mail-closed"></span>
<span class="ui-button-text">Send</span>
</button>
have you tried css,
button span.ui-button-text {
display: inline;
float: left;
}
Try
button span.ui-icon {
display: inline;
float: left;
margin-right: 2px;
}
button{width:75px;}
IE need a width for the button I think.
Here's my jsfiddle try
精彩评论