文本转换:大写不要对<option>元素起作用

时间:2018-11-28 12:51:49

标签: php css

我想让选择框的每个首字母大写,但是我的代码仅适用于小写和大写。如何使每个单词的大写字母开头?大写字母是否可用于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 */
}

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

尝试文本转换:大写,并删除显示:无

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 */
}

答案 2 :(得分:0)

DateTime inFortyFiveDays = DateTime.Now.AddDays(45);
var toDoList = (from i in _context.ActPlan where 
                               i.Expected_Date > DateTime.Now &&
                               i.Expected_Date < inFortyFiveDays
                select i)

删除此行

option {
text-transform: capitalize;
}