简体   繁体   English

当标签具有固定宽度时,如何在标签开始前显示星号

[英]how to show asterisk sign before label start when label has fixed width

I want to show asterisk sign before my label indicating it is a mandatory field.我想在我的标签前显示星号,表明它是必填字段。 following is my css id code for label,以下是我的标签 css id 代码,

#label{
    float: left;
    height: 30px;
    padding-right: 4px;
    padding-top: 2px;
    position: relative;
    text-align: right;
    vertical-align: middle;
    width: 73px;
}

output of above is, * Label but I want it to be like, *Label Thanks上面的输出是,* 标签,但我希望它像,*标签谢谢

Use :before pseudo class使用 :before 伪类

     .label:before{
     content:"*" ;
     color:red   
     }

Or要么

    #req:before{
    content:"*" ;
    color:red    
    }
​

DEMO Updated演示更新

Simple approach is like this
<font color="red">*</font>UserName<input type="text" name="userID"/>

It will display the asterik.

Edit编辑

The font tag is not supported in HTML5. HTML5 不支持字体标签。 Use CSS instead.改用 CSS。

font link字体链接

Without seeing the HTML it is difficult for us to know what is going on.如果没有看到 HTML,我们很难知道发生了什么。 I suspect you will be able to solve your problem using the little-known white-space property, if the asterisk is in the same element as #label.如果星号与#label 位于同一元素中,我怀疑您将能够使用鲜为人知white-space属性来解决您的问题。 Try using white-space: pre .尝试使用white-space: pre

Here is some more info: http://www.w3schools.com/cssref/pr_text_white-space.asp以下是更多信息: http : //www.w3schools.com/cssref/pr_text_white-space.asp

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

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