简体   繁体   English

将Asterisk添加到a的末尾

[英]Add Asterisk to the end of a <label>

Is it possible to add an asterisk to the end of the textstring within <label> ? 是否可以在<label>中的文本字符串末尾添加星号?

This is what I have, but the asterisk (of course) is displayed behind the whole label: 这就是我所拥有的,但星号(当然)显示在整个标签后面:

<label class="xy-form-label-required" for="zipcode">
   Zip Code
   <span class="xy-form-labelinfo">
       Allowed characters a-z A-z 0-9 ,.-
       Could also be an information about the field...
   </span>
</label>

My CSS Code: 我的CSS代码:

form.xy-form .xy-form-label-required:after {
    color: grey;
    content: ' *';
}

This is the result: 这是结果:

Zip Code 邮政编码
Allowed characters az Az 0-9 ,.- 允许的字符az Az 0-9,.-
* *

This is what I want to achive without changing the html markup. 这是我想要在不改变html标记的情况下实现的。

Zip Code * 邮编 *
Allowed characters az Az 0-9 ,.- 允许的字符az Az 0-9,.-

you can simply add the following CSS code instead 您只需添加以下CSS代码即可

.xy-form-label-required > span.xy-form-labelinfo:before{
  color: grey;
  content: " *";
}

Typo apart, you want the asterisk before the info label: Typo除外,你想要信息标签的星号:

.xy-form-label-required .xy-form-labelinfo:before{
    color: grey;
    content: ' *';
}

I had to change the markup like so, it is not possible to achive what I want without a < selector (which is not available yet): 我不得不像这样更改标记,如果没有<选择器(现在还没有),就不可能得到我想要的东西:

<label class="xy-form-label" for="zipcode">
    <span class="mc-form-asterisk>Zip Code</span>
    <span class="xy-form-labelinfo">
        Allowed characters a-z A-z 0-9 ,.-
        Could also be an information about the field...
    </span>
</label>

My CSS Code: 我的CSS代码:

form.xy-form .xy-form-label .xy-form-asterisk:after,
form.xy-form .xy-form-label-required:after {
    display: inline-block;
    color: grey;
    content: '\a0*';
}

Still not that bad I think. 我觉得还是那么糟糕。 Nevertheless, thanks for your advice guys! 不过,谢谢你的建议!

You are adding asterix after element, not Text node. 您在元素之后添加了asterix,而不是Text节点。 To achieve effect that you want you would need to use javascript ie something like this: http://jsbin.com/udiroz/2/edit But I wouldn't go this way. 要实现你想要的效果,你需要使用javascript,例如: http//jsbin.com/udiroz/2/edit但我不会这样做

Don't know if this is possible in your case but I would recommend to change the markup to something like this: http://jsbin.com/udiroz/1/edit In my opinion label is not a good place for additional informations like what chars are allowed, or not, validation errors, etc. 不知道你的情况是否可行,但我建议将标记更改为: http//jsbin.com/udiroz/1/edit在我看来,标签不适合其他信息,如允许或不允许使用哪些字符,验证错误等。

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

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