简体   繁体   English

如何在所需的html输入label的右上角添加红点,就像星号一样?

[英]How to add red dot at top-right corner of required html input label just like asterisk?

I want to add dot in place of asterisk in html label of required input.It should be in top-right corner just like asterisk.我想在所需输入的 html label 中添加点代替星号。它应该像星号一样位于右上角。

For the required attribute in the input element to affect the label, the label must come after the input element.为了使输入元素中的必需属性影响 label,label 必须位于输入元素之后。

This snippet adds a small red circle at the end of the label by using a pseudo after element on the label when the input has the required attribute (using CSS attribute selector facility).当输入具有所需属性(使用 CSS 属性选择器工具)时,此代码段通过在 label 上使用伪后元素在 label 的末尾添加一个红色小圆圈。

 label { position: relative; } input[required]+label::after { content: ''; width: 10px; height: 10px; top: -5px; border-radius: 50%; position: relative; background: red; display: inline-block; }
 <input required><label>I am the label</label>

Note that if you want the layout to be different, eg the label before or on top of the input, then there will have to be further positioning undertaken.请注意,如果您希望布局不同,例如输入之前或之上的 label,则必须进行进一步定位。

you should use before or after as u needed.您应该根据需要在之前或之后使用。

label.required:before {
    content: ". ";
}

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

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