简体   繁体   English

输入字段中必填的星号

[英]Required asterisk inside input field

Is it possible to put a red asterisk to inside of an input field to the far right? 是否可以在最右边的输入字段内放置一个红色星号? I don't have room on my form to put an asterisk and if I do put them it will look strange. 我没有在表格上放置星号的空间,如果我放置它们,它将看起来很奇怪。 Here is my css for my inputs. 这是我输入的CSS。

input {
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 3px;
    margin-bottom: 10px;
    box-sizing: border-box;
    font-family: montserrat;
    color: #2C3E50;
    font-size: 13px;
}

Is there any way to accomplish this? 有什么办法可以做到这一点? Thanks. 谢谢。

Using Bootstrap there is a class called "input-group-addon" that would do what you're talking about. 使用Bootstrap,有一个叫做“ input-group-addon”的类可以完成您正在谈论的事情。 If you aren't using Bootstrap, maybe you could still borrow the css for that class if it looks like what you're envisionng for your project. 如果您不使用Bootstrap,那么如果看起来像您为项目所设想的那样,也许仍可以借用该类的CSS。 There's an example of it used here: http://getbootstrap.com/css/#forms 这里有一个使用它的示例: http : //getbootstrap.com/css/#forms

You cannot use a before or after for input control. 您不能在输入控制之前或之后使用。 So inorder to achieve the end result, you need to wrap the input control with a div (make it inline-block) and use css "after" to position the "*" 因此,为了获得最终结果,您需要使用div包装输入控件(使其成为行内块),并使用CSS“之后”将“ *”定位

 #wrapper { position: relative; display: inline-block; z-index: 1; } #wrapper input { padding-right: 14px; } #wrapper:after { content: "*"; position: absolute; right: 5px; top: +3px; color: red; z-index: 5; } 
 <div id="wrapper"> <input type="text" /> </div> 

If you use bootsrap3 along with Glyphicons, you can try this: 如果将bootsrap3和Glyphicons一起使用,则可以尝试以下操作:

 .requiredFieldWrapper::after { font-family: 'Glyphicons Halflings'; content: '*'; position: absolute; top:2px; bottom: 0; right: 17px; font-size: 10px; color: red; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <br> <br> <div class="col-xs-10 requiredFieldWrapper"> <input class="form-control" type="text" autocomplete="off" required> </div> 

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

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