unknown gap before input-group-addon in default asp.net mvc 5 template

时间秒杀一切 提交于 2019-12-08 16:18:21

问题


how to reproduce :

  1. create new ASP.Net MVC project
  2. add a model
  3. add a controller with scaffolding views
  4. open the Create.cshtml in browser , then change any "form-group" using firebug or developer tools :

From :

<div class="form-group">
   <label class="control-label col-md-2" for="Name">Name</label>
   <div class="col-md-10">
      <input name="Name" class="form-control text-box single-line" id="Name" type="text" value="">
   </div>
  <span class="field-validation-valid text-danger" data-valmsg-replace="true" data-valmsg-for="Name"></span>
</div>

To :

<div class="form-group">
   <label class="control-label col-md-2" for="Title">Title2</label>
   <div class="col-md-10">
      <div class="input-group">
        <input name="Title" class="form-control text-box single-line" id="Title" type="text" value="">
        <span class="input-group-addon">@</span>
      </div>
   </div>
</div>

we just put "input" inside a "div" with "class='input-group'" and added an "input-group-addon"

the result is very weird , it looks like this : http://i.imgur.com/ylpYJKh.png

but the correct result is this : http://jsfiddle.net/6t3d9z8e/

is this a bug with ASP.Net MVC 5 default template or what ?


回答1:


It's interesting bug in interaction between bootstrap css and microsoft default styles.

See in your default css file "Site.css" and remove block after comment Set width on the form input elements since they're 100% wide by default, where setting max-width property on inputs.

And if you want to limit your input by size you should do this by bootstrap's col-md-... classes.




回答2:


By looking at your screenshots, it is very clear that MVC5 is overwriting the default bootstrap input properties.

Add the below CSS code to your style sheet. This will solve the problem.

.input-group .text-box { width: 100%; }


来源:https://stackoverflow.com/questions/26507294/unknown-gap-before-input-group-addon-in-default-asp-net-mvc-5-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!