[英]css class to make html select look like span
I am trying to make select look like span based on some condition. 我试图根据某些条件使选择看起来像跨度。 i have following css class that works fine with input boxes but it doesnt work with dropdown. 我有以下css类,可以很好地与输入框一起使用,但不适用于下拉列表。 Any guidance how can i make the select look like span rather than replacing select with span? 任何指导我如何使选择看起来像跨度,而不是用范围替换选择?
jQuery function jQuery功能
function makeReadOnly(context) {
$('input, select', context).each(function() {
$(this).addClass('readOnlyInput');
});
}
CSS 的CSS
.readOnlyInput
{
border-width: 0;
background-color: Transparent;
text-align: right;
}
Trying to style SELECTs is a dead end. 尝试设置SELECT的样式是死胡同。 Replacing SELECTs upon pageload with lists that look and behave just like SELECTs? 在页面加载时将SELECT替换为外观和行为类似于SELECT的列表? Totally doable: http://filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/ 完全可行: http : //filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/
Always keep accessibility in mind, though. 不过,请始终牢记可访问性。
You should just replace the select
with a span
. 您应该只用一个span
替换select
。 That's the standard way of doing what you're trying to do, and I think you'll have a lot of difficulty making a select
look like anything other than a select
since it's a system control. 这是完成您要尝试的操作的标准方法,而且我认为由于select
是系统控件,因此使其很难像select
一样使select
看起来像其他任何东西。 select
elements don't even look the same on different browsers/operating systems, because as a web developer you don't have the ability to restyle it. select
元素在不同的浏览器/操作系统上甚至看起来都不一样,因为作为Web开发人员,您无法对其进行样式更改。
Even your standard restyled combo boxes and such, like the many jQuery plugins available out there, hide the original select
and replace it with a series of div
s and such. 甚至您的标准样式组合框等(如可用的许多jQuery插件)都隐藏了原始select
并用一系列div
等替代了它。
How about making it disabled
: 如何disabled
它:
function makeReadOnly(context) {
$('input, select', context).each(function() {
$(this).attr('disabled', 'disabled');
});
}
W3C Recommendation: W3C建议:
In contexts where user input is either undesirable or irrelevant, it is important to be able to disable a control or render it read-only. 在用户输入不合需要或不相关的情况下,重要的是能够禁用控件或使其变为只读状态。 For example, one may want to disable a form's submit button until the user has entered some required data. 例如,可能要禁用表单的“提交”按钮,直到用户输入了一些必需的数据。 Similarly, an author may want to include a piece of read-only text that must be submitted as a value along with the form. 同样,作者可能希望包括一段只读文本,该文本必须作为值与表单一起提交。 The following sections describe disabled and read-only controls. 以下各节描述了禁用和只读控件。
http://www.w3.org/TR/html4/interact/forms.html#h-17.12 http://www.w3.org/TR/html4/interact/forms.html#h-17.12
You can't. 你不能 There is no style available to remove the arrow that you see in the drop down. 没有可用的样式来删除您在下拉菜单中看到的箭头。
You are going to replace the drop down with a span if you want it to look like a span. 如果希望下拉菜单看起来像跨度,则将其替换为跨度。 All other are hacks are not going to be browser compatible or simply complicating it. 其他所有骇客都不会与浏览器兼容或使其简单化。
One such method to hide arrow How to remove the arrow from a select element in Firefox 一种隐藏箭头的方法如何从Firefox中的select元素中删除箭头
这不是可行的解决方案,但应将选择框的背景颜色设置为黑色,以使其看起来像span标签,因为您不能将箭头颜色更改为其他颜色。
background-color: black;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.