【问题标题】:text-transform: Capitalize don,t work for <option> elements [duplicate]text-transform:大写 don,t 适用于 <option> 元素 [重复]
【发布时间】:2018-11-28 12:51:48
【问题描述】:

我想让选择框的每个首字母都大写,但我的代码只适用于小写和大写。如何使每个单词的首字母大写?大写是否适用于 crome 浏览器或我的代码有误?

我尝试了更多时间,但它仅适用于大写和小写,不适用于大写

这是我的 PHP 代码:

<select  name="hotel_name1" id="hotel_name1" class="select-drop">
    <option value disabled selected style="color:gray">Select Hotel</option>
    <?php
    while ($row=mysql_fetch_array($result)) {
    ?>
    <option value="<?php echo $row["postid"]; ?>"><?php echo $row["hotel_name"]; ?></option>
    <?php
    }
    ?>
</select>

CSS:

select {
  height: 1.4em;             /* show only one option when not focused */
}

option  {
  text-transform: lowercase; /* change to lowercase */
  padding-right: 2em;        /* the select's width is based on width of its longest non-transformed ... */
                             /* option.  padding ensures that option is completely visible */
  display: none;             /* hide all options by default (see below) */
}

option:first-letter {
  text-transform: uppercase; /* change first letter to uppercase */
}

option:checked, select:focus option { 
  display: block;            /* show selected option, or show all options when the select is focused */
}

【问题讨论】:

  • 似乎是什么问题 -> jsfiddle.net/yLehr95z?
  • 没有人应该再编写带有mysql_ 的代码了。请切换到mysqli_ 功能。通过 php 与 css 实现所需的调整会简单得多。

标签: php css


【解决方案1】:

你可以在 PHP 中直接输出格式化的单词:

string ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] )

这里的文档:http://php.net/manual/fr/function.ucwords.php

string ucfirst(string $str);

这里的文档:http://php.net/manual/en/function.ucfirst.php

对使用 CSS 执行此操作的类似问题的回应:

How to Capitalize first letter only using CSS in each case

【讨论】:

    【解决方案2】:
    option {
    text-transform: capitalize;
    }
    

    删除这一行

    option:first-letter {
      text-transform: uppercase; /* change first letter to uppercase */
    }
    

    【讨论】:

      【解决方案3】:

      已编辑:Seema => 使用选择并删除所有选项样式

      尝试 text-transform: 大写,并删除 display:none

      select {
       text-transform: capitalize; /* change to lowercase */
       padding-right: 2em;        /* the select's width is based on width of its longest 
       non-transformed ... */
                               /* option.  padding ensures that option is completely 
       visible */
      }
      

      并删除下面的样式

      option:first-letter {
        text-transform: uppercase; /* change first letter to uppercase */
      }
      

      【讨论】:

      • 如果输出代码,不要使用css,输出格式好的文本。加载和管理更容易、更少的 CSS 输出。工作 100%
      猜你喜欢
      • 2012-01-13
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-27
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      相关资源
      最近更新 更多