有没有办法在 IE8 中居中选择/组合框选项元素?

发布于 2024-10-07 07:44:33 字数 736 浏览 0 评论 0原文

我在 IE8 中居中选择选项元素时遇到问题。基本上,这对我来说在其他浏览器中有效,但在 IE8 中无效。

到目前为止,我已经设法避免了任何特定于浏览器的黑客攻击,但从我所做的研究来看,这对于 IE8 来说似乎是不可能的。

这是说明问题的示例代码。

<html>
<head><style>select { text-align: center; }</style></head>
<body>Debugging Centering Issue
    <select>
        <option>Short option</option>
        <option>Very Long Option with lots of horizontal width</option>
    </select>
    </body>
</html>

将其加载到 FF 中,组合框居中。在 IE 中做同样的事情,它是左对齐的。

我尝试使用 jQuery 中心元素插件,但没有成功。

有办法做到这一点吗?

只是为了澄清,我正在讨论将选项(下拉项)集中在选择元素上,而不是选择元素本身。

I'm experience an issue with centering select option elements in IE8. Basically, this works for me in other browsers, but not in IE8.

Up to now I've managed to avoid any browser-specific hacks, but from the research I've done, it seems like this may not be possible with IE8.

Here's sample code to illustrate the problem.

<html>
<head><style>select { text-align: center; }</style></head>
<body>Debugging Centering Issue
    <select>
        <option>Short option</option>
        <option>Very Long Option with lots of horizontal width</option>
    </select>
    </body>
</html>

Load it up in FF and the combobox is centered. Do the same in IE and it's left-aligned.

I've tried using the jQuery Center Element Plugin, without any success.

Is there a way to do this?

Just to clarify, I'm talking about centering the options (drop-down items) on the select element, not the select element itself.

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

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

发布评论

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

评论(1

鹤仙姿 2024-10-14 07:44:33

默认情况下不可能。

检查:如何确保选择选项文本在 IE 中居中对齐?

如果它确实应该居中,我将使用 javascript 创建一个自定义选择。

如果您愿意,我可以使用 HTML 和 Jquery 为您编写一个示例。

Not possible by default.

Check: how to make sure select option text align in the center in IE?

If it really should be centered I would create a custom select with javascript.

I can code you an example with HTML and Jquery if you like.

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