浮动和 jQuery UI 按钮
我在一个项目中使用了 jQuery UI 按钮,它们工作得很好。
但是,在 IE7 中,图标没有按应有的方式浮动。我意识到 IE 还没有圆角支持,但这没关系。
好的浏览器某些浏览器可以很好地渲染
IE sucks 版本 7 没有:
我从 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;
}
然而,这会产生消隐按钮元素的不寻常效果!
我该怎么办?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
无论如何,当你浮动一个元素时,它就变成了一个块框。 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.
您需要显式定义水平浮动或 浮动下降的宽度。另一种方法是使用 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.
你渲染的html,
你尝试过css吗,
your rendered html,
have you tried css,
尝试
IE 需要一个按钮的宽度,我认为。
这是我的 jsfiddle 尝试
Try
IE need a width for the button I think.
Here's my jsfiddle try