1

Here is a simple html code from my ASP .NET MVC 5 project:

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <div class="form-group">
            @Html.TextBoxFor(model => model.Description, htmlAttributes: new { @class = "col-md-12", style = "Width:1000px" })
        </div>

        <div class="form-group">
            <div class="col-md-12">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>

}

I am trying to get a text box that is wide. However, no matter what I try for the width value, the text box width stays small.

I moved from EditorFor to TextBoxFor hoping I will have better control of width:-(.

Please help me understand what is it that I am missing? Regards.

4
  • 1
    You could also try replacing the style = "" with @style = "width:400px;" Commented Nov 23, 2014 at 21:44
  • Thank you. I tried that but it doesn't help. Commented Nov 24, 2014 at 1:22
  • maybe your style overwrite with other thing Commented Nov 24, 2014 at 7:11
  • the class "col-md-12" is only for divs, and you are using it on the textbox, maybe that's the problem or you have another style in a css file or in the view Commented Nov 24, 2014 at 17:30

2 Answers 2

3

This question has been out there for a while and I stumbled upon it while looking for an answer to the same problem.

It turns out the default VS template comes with a file called Site.css which includes the following style:

/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
    max-width: 280px;
}

So either change the max-width on this style or override the max-width with another style rule.

Sign up to request clarification or add additional context in comments.

1 Comment

+1. This one had me going insane. Nice catch. This is something you would definitely not expect. Thanks!
0

The thing is you are using Bootstrap. Try removing classes from the outer divs or even bootstrap completely.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.