简体   繁体   English

下划线:使用CSS选择的首字母

[英]Underline :first-letter of a select with CSS

I know <select> 's are notoriously a pain to work with, but I'm building a form with accesskey's and to inform the user of said keys I'm underlining the first letter of the form items. 我知道<select>的使用非常麻烦,但是我正在用accesskey构建一个表单,并将上述密钥告知用户,我强调了表单项的第一个字母。

This is easy with placeholder's, 使用占位符很容易,

::-webkit-input-placeholder:first-letter{text-decoration:underline}

and naturally easy with paragraphs, 而且自然很容易使用段落

.field>p:first-letter{text-decoration:underline}

however, I cannot for the life of me figure out how to approach <select> 's. 但是,我一生无法弄清楚如何处理<select>

I've attempted a few things, I'll list them below. 我尝试了一些事情,在下面列出。

  /* attempt 1 */
  select:first-letter{}

  /* attempt 2 */
  select option:nth-child(1):first-letter{}

  /* attempt 3 */
  option[value="0"]:first-letter{}

  /* attempt 4 */
  select:before,
  option[value="0"]:before{
    content:'';
    position:absolute;
    left:0;
    bottom:3px;
    width:5px;
    height:1px;
    border-bottom:1px solid black;
  }

  /* attempt 5 */
  <option><u>N</u>ame</option>

  /* attempt 6 - kinda works, looks wonky */
  <option>&#x035F;Name</option>

The only way I've been able to accomplish it, is positioning a random <div> with a border exactly where it's needed. 我能够完成此操作的唯一方法是将随机<div>精确地定位在需要的位置并带有边框。 Which seems a little excessive and dirty to me. 对我来说,这似乎有些多余和肮脏。

I know I can use Selectize , Select2 , Chosen or any number of other plugins... Which I may end up doing anyways, but the OP stands. 我知道我可以使用SelectizeSelect2Chosen或任何其他数量的插件...无论如何我最终都可以这样做,但是OP 仍然可以使用。

Any Ideas? 有任何想法吗?

I could have mistaken the question, but 我可能会误解这个问题,但是

select option:first-letter 
{
  text-decoration:underline;
}

works fine for me... 对我来说很好...

http://jsfiddle.net/mce1tL7e/2/ http://jsfiddle.net/mce1tL7e/2/

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

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