2016-04-01 12 views
0

私は非常に簡単なものを見落としていると思いますが、問題を見つけることができません。私はrequiredと呼ばれるCSSクラス名を持っており、ここでその上のスペックである第二divに今シンボルの位置が間違っています

<div class="form-group"> 
     @Html.LabelFor(model => model.Total, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10 required"> 
      @Html.EditorFor(model => model.Total, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.Total, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

.required:after{ 
    content: "*"; 
    font-weight: bold; 
    color: red; 
} 
私はこのようなコードを持ってビューを作成しますオン

レンダリング方法は次のとおりです。

Issue

テキストボックスの直後に赤いアスタリスクを表示させるにはどうすればよいですか? CSSで何が欠けていますか?

答えて

1

使用.required:before

.required:before{ 
    content: "*"; 
    font-weight: bold; 
    color: red; 
    float:left; 
} 
#input{ 
    float:left; 
} 
+0

私はちょうどそれを試してみましたが、それは、テキストボックスの後にアスタリスクを入れていません。それはアスタリスクを上に置き、実際にはテキストボックスを少し押し下げます –

+0

今すぐ確認してください。 –

+0

浮動小数点:左にアスタリスクがありますが、入力のIDはどこに置かれますか?私は '@Html.EditorFor(model => model.Total、new {htmlAttributes = new {@id =" input "、@class ="フォームコントロール "}})'を入れて、#input {float:left}私のCSSではそれは変わっていません –

0

私はそれを考え出しました。

CSS:

.required:after{ 
content: "*"; 
font-weight: bold; 
color: red; 
float:left; 
margin-left: 5px; 
} 

#input{ 
    float:left; 
} 

HTML:

<div class="form-group"> 
     @Html.LabelFor(model => model.Total, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10 required"> 
      @Html.EditorFor(model => model.Total, new { htmlAttributes = new { @id = "input", @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.Total, "", new { @class = "text-danger" }) 
     </div> 
</div> 
関連する問題