MVC newbie
MVC newbie

Reputation: 599

bootstrap icon float to most right

My icon always float to the most right.

See image below : See image below. It doesn't stick beside of the input.

My code is :

 <div class="form-horizontal">

  <div class="form-group">
        @Html.Label("date", htmlAttributes: new { @class = "control-label col-md-2" })

            <div class="form-group">
                <div class="col-md-10">


                    <div class="input-group date" id="datetimepicker1">
                        @Html.EditorFor(model => model.pdate, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model => model.pdate, "", new { @class = "text-danger" })
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>
    </div>

Upvotes: 0

Views: 1163

Answers (2)

Shivkumar kondi
Shivkumar kondi

Reputation: 6782

Don't know why are using nested form-group classes in your code

May be you added some css on input field so remove that.

Just remove this css from below answer and see the difference:

 #datepk{
  max-width: 200px;
}

.input-group-addon{
  width: 0%;
}
#datepk{
  max-width: 200px;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>

</style>
<body>

<div class="container">
  <div class='col-sm-6'>
  <div class="form-group">
    <div class='input-group date' id='datetimepicker1'>
      <input id="datepk"type='text' class="form-control" />
      <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
      </span>
    </div>
  </div>
</div>
  
</div>
  

  

</body>
</html>

Upvotes: 1

Mr. Perfectionist
Mr. Perfectionist

Reputation: 2746

You are using '.input-group-addon' class. In this class there is a property width: 1%; (from bootstrap.css)

And display property is table-cell;

So, your

<span class="input-group-addon">
      <span class="glyphicon glyphicon-calendar"></span>
</span>

is taking only 1% width of whole width. If you omit this property your problem will be solved I think.

Just override .input-group-addon width: 1%; property.

.input-group-addon
{
  width: 0%;
}

Or give whatever width you want to give him. :-)

Upvotes: 0

Related Questions