是否可以在选择框中居中文本? [英] Is it possible to center text in select box?

查看:138
本文介绍了是否可以在选择框中居中文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试这样: http://jsfiddle.net/ilyaD/KGcC3/

HTML:

<select name="state" class="ddList">
   <option value="">(please select a state)</option>
   <option class="lt" value="--">none</option>
   <option class="lt" value="AL">Alabama</option>
   <option class="lt" value="AK">Alaska</option>
   <option class="lt" value="AZ">Arizona</option>
   <option class="lt" value="AR">Arkansas</option>
   <option class="lt" value="CA">California</option>
   <option class="lt" value="CO">Colorado</option>
</select>

CSS:

select { width: 400px; text-align:center; }
select .lt { text-align:center; }

正如你所看到的,它不工作。

As you can see it doesn't work. Is there a CSS-only way to center text in the select-box?

推荐答案

恐怕这是不可能的

但是,使用jQuery插件,你可以在下拉菜单中设置样式:

However, using a jQuery plugin, you could style the dropdown:

http://filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/

此插件隐藏 select 元素,并创建 span 飞显示自定义下拉列表样式。我很有信心,你可以改变跨度等的样式,使中心对齐项目。

This plugin hides the select element, and creates span elements etc on the fly to display a custom drop down list style. I'm quite confident you'd be able to change the styles on the spans etc to center align the items.

这篇关于是否可以在选择框中居中文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆