简体   繁体   English

CSS类使HTML选择看起来像跨度

[英]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.

相关问题 如何使跨度看起来像img? - How to make span look like img? 使一个HTML表单看起来像其他 - Make one HTML form look like other 价值来自 <select> span CSS类的选项 - Value from <select> options to a span CSS class 如何使输入类型文本看起来像选择下拉列表? - How to make an input type text look like select dropdown? 如何使td标签看起来像HTML中的标签? - How to make td tag look like a tag in HTML? 如何仅使用 HTML 和 css 的选择标签在桌面浏览器中制作 ipad 之类的下拉列表,这可能吗? - How to make ipad like dropdownlist in desktop browsers using select tag of HTML and css only, is it possible? 如何将css类应用于jQueryMobile可折叠div中定义的范围。 我想在单击跨度时切换一个CSS类 - how to apply a css class to a span defined in jQueryMobile collapsible div . I would like to toggle a css class when it is clicked on span 如何修复CSS并使网站看起来像博客或杂志一样? - How to fix my CSS and make my site look blog- or magazine-like? 如何使用CSS或JQuery使整个网页看起来更小(就像chrome的缩小功能一样)? - how to make the whole webpage look smaller (just like zoom out function of chrome) using CSS or JQuery? 设置下拉选项列表的样式,使其看起来像带有背景图像的按钮。 HTML / CSS - Styling a drop down option list to look like a button with background image. HTML/CSS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM