浮动和 jQuery UI 按钮

发布于 2024-09-26 03:04:20 字数 1809 浏览 3 评论 0原文

我在一个项目中使用了 jQuery UI 按钮,它们工作得很好。

但是,在 IE7 中,图标没有按应有的方式浮动。我意识到 IE 还没有圆角支持,但这没关系。

好的浏览器某些浏览器可以很好地渲染

good example

IE sucks 版本 7 没有:

bad example

我从 HTML 中的一个按钮开始

<button type="submit"><span class="ui-icon ui-icon-mail-closed"></span>Send</button>

,然后循环遍历按钮,在每个按钮上使用一点点 jQuery

$('#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() });
});

,我只是在它们上调用 button(),但我决定这样做是为了确保我按照设计的方式使用该库。

我在图标上也有一些 CSS

button span.ui-icon {
    display: inline;
    float: left;
    margin-right: 0.1em;
}

上面的页面也可用。 (我希望缩短为 void HTTP Referrer)。

我做错了什么?

非常感谢!

更新

我尝试将图标制作为内联块元素,按照 梅德的回答

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;
}

然而,这会产生消隐按钮元素的不寻常效果!

IE7 with display: inline-block on icon

我该怎么办?

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

good example

IE sucks version 7 does not:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

街道布景 2024-10-03 03:04:20

无论如何,当你浮动一个元素时,它就变成了一个块框。 Display:inline 没用。
并且您应该始终设置浮动项目的宽度。

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.

无语# 2024-10-03 03:04:20

您需要显式定义水平浮动或 浮动下降的宽度。另一种方法是使用 inline-block

如果这不起作用,请告诉我。

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.

世态炎凉 2024-10-03 03:04:20
<button type="submit"><span class="ui-icon ui-icon-mail-closed"></span><span style="float:left;">Send</span></button>
<button type="submit"><span class="ui-icon ui-icon-mail-closed"></span><span style="float:left;">Send</span></button>
注定孤独终老 2024-10-03 03:04:20

你渲染的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>

你尝试过css吗,

button span.ui-button-text {
    display: inline;
    float: left;
}

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;
}
迷路的信 2024-10-03 03:04:20

尝试

button span.ui-icon {
    display: inline;
    float: left;
    margin-right: 2px;
}
button{width:75px;}

IE 需要一个按钮的宽度,我认为。

这是我的 jsfiddle 尝试

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文