views:

122

answers:

6

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 browsers render it fine

good example

IE sucks

bad example

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!

IE7 with display: inline-block on icon

Whatever shall I do?

Many thanks, again!

A: 

You button lacks a width

Julien CROUZET
I don't want to explicitly give them widths.
alex
A: 

hi, try using

<button type="submit"><span class="ui-icon ui-icon-mail-closed"></span><span style="float:left;">Send</span></button>
Dhaval Tawar
A: 

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.

Julien CROUZET
`display: inline` is useful for avoiding the double margin bug in IE6. Why should I always set a width, when IE7 is the only browser having an issue?
alex
A: 

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;
}
Reigel
Thanks for your answer. I tried that, and then I tried it again just then with IE Developer Tools, and it didn't work :(
alex
+1  A: 

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.

meder
Thanks Meder. I might use `inline-block`. I'll try in the morning, I'm going to have a break now.
alex
Hey Meder, I tried giving the icon `display: inline` (or its equivalent) for IE7 and the buttons went blank! See my edit on OP - give me a pointer in the right direction and you will have an accepted answer sir!
alex
A: 

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

Chouchenos