简体   繁体   English

HTML - <select>定制风格

[英]html - <select> custom style

i'm trying to customize the whole style of the component, and hide the selector image. 我正在尝试自定义组件的整个样式,并隐藏选择器图像。 All graphics style such border, shadows are setted in the previous table. 所有图形样式这样的边框,阴影都在上一个表中设置。 Now i want to remove all style from the selection menu such as the horrible icon to select an item 现在我想从选择菜单中删除所有样式,例如可怕的图标以选择项目 在此输入图像描述

My original code in jsf: 我在jsf中的原始代码:

<h:panelGrid class="dropDown">
  <h:selectOneMenu value="#{myBean.selected}"
  id="list" class="test" style="border-style:none; height:31px;">
    <f:selectItems value="#{myBean.list}" var="item"
    itemLabel="#{item.name}" itemValue="#{item.code}" />
    <f:ajax execute="@this" />
  </h:selectOneMenu>
</h:panelGrid>

This is my style for class .test 这是我的课堂风格.test

.test{
    background-color: white;
    clear: both;
    color: black !important;
    font-family: Helvetica !important;
    font-size: 16px !important;
    height: 30px;
    margin-bottom: 0;
    border-style: none;
}

My page rendered in html: 我的页面以html呈现:

<select id="list" name="item" class="test" size="1" style="border-style:none; height:31px;"onchange="jsf.util.chain(this,event,'disableBox()','mojarra.ab(this,event,\'valueChange\',\'@this\')')"> 

    <option value="1">al</option>
    ...
    <option value="22">re</option>
</select>

But when i open the webpage from a webview (Android) I still see the icon 但是当我从webview(Android)打开网页时,我仍然看到了图标 在此输入图像描述 . Is it impossible to remove if I'm on a simple Webview? 如果我在一个简单的Webview上,是不可能删除? Or what element should I use to remove it? 或者我应该使用什么元素来删除它? Or, it's another component I could use? 或者,它是我可以使用的另一个组件?

My idea is to hide the icon and allow a user to click on the single line, then the Android original component drop down list is opened. 我的想法是隐藏图标并允许用户单击单行,然后打开Android original component下拉列表。

I know that it's styled by the operating system.. any suggestion? 我知道它是由操作系统设计的..任何建议?

I think it's not usefull.. but I created a simple jsfiddle page where I can test css style modifications. 我认为它没有用..但我创建了一个简单的jsfiddle页面,我可以测试css样式的修改。 jsfiddle 的jsfiddle

The standard JSF html renderkit will render an h:selectOne as a simple html select tag with you f:selectItems becoming the child option tags. 标准的JSF html renderkit会将h:selectOne呈现为一个简单的html选择标记,其中f:selectItems成为子选项标记。

<select>
  <option value="a">a</option>
  <option value="b">b</option>
</select>

so your question is really is there a way to remove the icon from an html select tag. 所以你的问题是有没有办法从html选择标签中删除图标。 It really has nothing to do with JSF. 它与JSF无关。

Once you've figured out how to write the html and cssto get the effect you want, you can then write a custom renderer to reproduce that html. 一旦你弄清楚如何编写html和cssto获得你想要的效果,你就可以编写一个自定义渲染器来重现那个html。

Found a working solution with custom css: 找到一个自定义css的工作解决方案:

Since the component jsf is rendered as , we include all elements inside a , or in this case inside a 由于组件jsf被渲染为,我们将所有元素包含在a中,或者在这种情况下包含在a中

<h:panelGrid class="parent dropDown">
  <h:selectOneMenu value="#{myBean.selected}"
    id="list" class="test" style="border-style:none; height:31px;">
    <f:selectItems value="#{myBean.list}" var="item"
    itemLabel="#{item.name}" itemValue="#{item.code}" />
     <f:ajax execute="@this" />
   </h:selectOneMenu>
</h:panelGrid>

adding the class parent to the panelGrid and defining: 将class parent添加到panelGrid并定义:

  .parent{
        width:98%;
        overflow:hidden;
    }

    .parent select{
        width:100%;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border: none;
        background: none;    
    }

Our jsf component is rendered without the arrow and other components, like borders and shadows. 我们的jsf组件在没有箭头和其他组件(如边框和阴影)的情况下呈现。

自定义样式选择仅使用html和css而不是任何js / javascript

`http://jsfiddle.net/suyogN/39tx46L3/`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM