6

I have a bootstrap form like this:

<div class="container">
    <form class="form-horizontal">
        <div class="form-group">
            <div class="col-xs-2 text-right">
                <label class="control-label">Name</label>
            </div>
            <div class="required col-xs-10" >
                <input class="form-control" type="text" />
            </div>
        </div>
    </form>
</div>

Now the name field is required so i want to display an asterisk right next to it. I tried this:

.required:after {
    content: " *";
}

But it is displayed under the input, not right next to it. How can i fix this? JSFiddle: http://jsfiddle.net/Dc5yw/

lunr
  • 5,159
  • 4
  • 31
  • 47

5 Answers5

9

Reduce the width of the input fields form-control and add float:left to this.

Check the fiddle

CSS changes

.required:after {
    content: "*";
    padding-left:1%;
}

.form-control{
    width:97%;
    float:left;
}
James
  • 4,540
  • 1
  • 18
  • 34
2

check this fiddle.this will solve ur problem.

http://jsfiddle.net/Dc5yw/1/

change this

<div class="required col-xs-10" >
<input class="form-control1" type="text" />
</div>
Abhijit Mali
  • 132
  • 2
  • 8
2
.required::after {
 content: "*";
 position:absolute;
 right:0px;
 top:10px;
}

check this JSFiddle

side note: :after is old syntax, now it is ::after

T J
  • 42,762
  • 13
  • 83
  • 138
0

DEMO

CSS

.col-xs-10 {
    position:relative;
}
.required:after {
    content:" *";
    position: absolute;
    top: 0;
    right: 5px;
}
Pravin W
  • 2,451
  • 1
  • 20
  • 26
-1

In your HTML

<div class="form-group required">
  <label class="col-md-4 control-label" for="textinput">Name<span style="color:red;">*</span></label>
    <div class="col-md-4">
      <input id="textinput" name="textinput" placeholder="Your name" class="form-control input-md" required="" type="text">
                                
    </div>
</div>
RASHED
  • 128
  • 8
  • This adds the required parameter while the user ask about displaying an asterisk next to an input field. Please always include an elaborate description of your code in your answer so it can be helpful – Bowdzone Apr 20 '15 at 12:26