Question how to increase input size according to div size using bootstrap

Asked

Viewed 2,176 times

2

I am having difficulty increasing the size of my inputs using the bootstrap classes, I would like to leave them according to the sizes of my div for example, in a Row with 12 columns I create the div with col-Md-12 and leave the input the size of this div, how to proceed? because the way I’m doing it isn’t working. Remembering that I would not like to use width with css, therefore it is not responsive, IE, when I decrease the size is fixed.

My View

@model Projeto.ERP.Model.Model.Genericos.PaisModel

@{
    ViewBag.Title = "Create";
    bool cadastradoComSucesso = ViewBag.cadastradoComSucesso;
    bool cadastroComErro = ViewBag.cadastroComErro;
}

<style>
    #Sigla2, #Sigla3 {
        text-transform: uppercase;
    }

    #painelAuditoria, #painelGeral {
        border-top: hidden;
        border-top-left-radius: unset;
        border-top-right-radius: unset;
    }

    .checkbox {
        margin-top: 25px !important;
        margin-bottom: 10px !important;
        margin-left: 14px;
    }

    label {
        font-weight: normal;
    }
</style>

@using (Html.BeginForm("Create", "Pais", FormMethod.Post, new { @id = "form" }))
{
    <div class="page-header">
        <h1>Cadastro de Paises</h1>
    </div>

    <div id="alerta">

    </div>

    <ul class="breadcrumb">
        <li class="active"> Editar </li>
        <li><a href="@Url.Action("Index", "Pais")"> Listar Paises </a></li>
    </ul>

    @Html.AntiForgeryToken()

    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <ul class="nav nav-tabs" id="tabelaPresentarion">
        <li role="presentation" id="tabGeral" class="active"><a href="#">Geral</a></li>
        <li role="presentation" id="tabAuditoria"><a href="#">Audiroria</a></li>
    </ul>

    <div class="panel panel-default" id="painelGeral">
        <div class="panel-body">
            <div class="form-horizontal">
                <div class="container">
                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-6">
                                <div class="checkbox" id="divCheckBox">
                                    @Html.LabelFor(model => model.Ativo, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.Ativo)
                                    @Html.ValidationMessageFor(model => model.Ativo, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-12">
                                @Html.LabelFor(model => model.Nome, htmlAttributes: new { @class = "control-label" })
                                @Html.EditorFor(model => model.Nome, new { htmlAttributes = new { @class = "form-control", placeholder = "" } })
                                @Html.ValidationMessageFor(model => model.Nome, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-6">
                                @Html.LabelFor(model => model.Sigla2, htmlAttributes: new { @class = "control-label" })
                                @Html.EditorFor(model => model.Sigla2, new { htmlAttributes = new { @class = "form-control", placeholder = "" } })
                                @Html.ValidationMessageFor(model => model.Sigla2, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-6">
                                @Html.LabelFor(model => model.Sigla3, htmlAttributes: new { @class = "control-label" })
                                @Html.EditorFor(model => model.Sigla3, new { htmlAttributes = new { @class = "form-control", placeholder = "" } })
                                @Html.ValidationMessageFor(model => model.Sigla3, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <input type="submit" id="btnSalvar" value="Salvar" class="btn btn-primary" />
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-default" id="painelAuditoria">
        <div class="panel-body">
            <div class="form-horizontal">
                <div class="container">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.DataCadastro, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.DataCadastro, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.DataCadastro, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.UsuarioCadastro, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.UsuarioCadastro, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.UsuarioCadastro, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.DataAlteracao, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.DataAlteracao, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.DataAlteracao, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.UsuarioAlteracao, htmlAttributes: new { @class = "control-label " })
                                    @Html.EditorFor(model => model.UsuarioAlteracao, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.UsuarioAlteracao, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Lista de Paises", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    @if (cadastradoComSucesso)
    {
        <script>
            var functionSuccess = function () {
                $('#alerta').html('<div class="alert alert-success" role="alert"> Registro cadastrado com sucesso.</div>')
                $('#alerta').fadeIn(9000);
            };

            functionSuccess();

            $('#alerta').fadeOut(5000);

            $('#btnSalvar').prop('disabled', true);
        </script>
    }
    else if (cadastroComErro)
    {
        <script>
            var functionWarrning = function () {
                $('#alerta').html('<div class="alert alert-danger" role="alert"> Erro ao salvar registro.</div>')
                $('#alerta').fadeIn(9000);
            };

            functionWarrning();

            $('#alerta').fadeOut(5000);
        </script>
    }
    <script>
            jQuery(document).ready(function () {



                var tabGeral = $('#tabGeral');
                var tabAuditoria = $('#tabAuditoria');

                var painelGeral = $('#painelGeral');
                var painelAuditoria = $('#painelAuditoria');

                tabGeral.click(function () {
                    painelGeral.show();
                    painelAuditoria.hide();

                    $('.nav.nav-tabs li').each(function () {
                        if ($(this).attr('class') == "active") {
                            $(this).removeClass('active');
                        }
                    });
                    $(this).addClass('active');
                });

                tabAuditoria.click(function () {
                    painelGeral.hide();
                    painelAuditoria.show();

                    $('.nav.nav-tabs li').each(function () {
                        if ($(this).attr('class') == "active") {
                            $(this).removeClass('active');
                        }
                    });
                    $(this).addClass('active');
                });

                tabGeral.click();
            });

    </script>
}

View result in Chrome

inserir a descrição da imagem aqui

  • You can use widththat gets responsive yes. Try width: 100%... if you exceed the width of the div (it can happen because of the input padding), decrease 1% until it is good.

  • I managed using the min-width property : 100% ! Mportant, for some reason only with didn’t work, how to proceed to close the question? self reply or edit the post ?

  • Elaborate a response with what you did and after 15 minutes mark it as right.

3 answers

0

Try to put the div with the class form-group inside the size definition of the "columns" and the class row to define each "line" of the form.

Would look like this:

<div class="form-horizontal">
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <div class="checkbox" id="divCheckBox">
                        @Html.LabelFor(model => model.Ativo, htmlAttributes: new { @class = "control-label" })
                        @Html.EditorFor(model => model.Ativo)
                        @Html.ValidationMessageFor(model => model.Ativo, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    @Html.LabelFor(model => model.Nome, htmlAttributes: new { @class = "control-label" })
                    @Html.EditorFor(model => model.Nome, new { htmlAttributes = new { @class = "form-control", placeholder = "" } })
                    @Html.ValidationMessageFor(model => model.Nome, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    @Html.LabelFor(model => model.Sigla2, htmlAttributes: new { @class = "control-label" })
                    @Html.EditorFor(model => model.Sigla2, new { htmlAttributes = new { @class = "form-control", placeholder = "" } })
                    @Html.ValidationMessageFor(model => model.Sigla2, "", new { @class = "text-danger" })
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    @Html.LabelFor(model => model.Sigla3, htmlAttributes: new { @class = "control-label" })
                    @Html.EditorFor(model => model.Sigla3, new { htmlAttributes = new { @class = "form-control", placeholder = "" } })
                    @Html.ValidationMessageFor(model => model.Sigla3, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
    </div>
</div>
  • It doesn’t work friend, it was the same way in the image I attached.

  • Post the "raw" HTML code generated by Razor to the question, to see if I can help you

  • See if it’s clearer friend. I edited

  • I made a mistake, please try again with my edited answer. If it doesn’t work unfortunately I won’t be able to help you

  • It hasn’t worked yet @Breno, but thanks for your help.

  • @Nicolabogar tries to post his entire code on a site like https://jsfiddle.net drop to try to help more

Show 1 more comment

0

I solved my problem after several attempts using the CSS property,
.form-control { min-width : 100% ! Important;}, so it gets the size of the parent div.

Code

@model Projeto.ERP.Model.Model.Genericos.PaisModel

@{
    ViewBag.Title = "Create";
    bool cadastradoComSucesso = ViewBag.cadastradoComSucesso;
    bool cadastroComErro = ViewBag.cadastroComErro;
}

<style>
    #Sigla2, #Sigla3 {
        text-transform: uppercase;
    }

    #painelAuditoria, #painelGeral {
        border-top: hidden;
        border-top-left-radius: unset;
        border-top-right-radius: unset;
    }

    .checkbox {

        margin-left: 14px;
    }

    .form-control {
        min-width : 100% !important;

    }

    label {
        font-weight: normal;
    }
</style>

@using (Html.BeginForm("Create", "Pais", FormMethod.Post, new { @id = "form" }))
{
    <div class="page-header">
        <h1>Cadastro de Paises</h1>
    </div>

    <div id="alerta">

    </div>

    <ul class="breadcrumb">
        <li class="active"> Editar </li>
        <li><a href="@Url.Action("Index", "Pais")"> Listar Paises </a></li>
    </ul>

    @Html.AntiForgeryToken()

    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <ul class="nav nav-tabs" id="tabelaPresentarion">
        <li role="presentation" id="tabGeral" class="active"><a href="#">Geral</a></li>
        <li role="presentation" id="tabAuditoria"><a href="#">Audiroria</a></li>
    </ul>

    <div class="panel panel-default" id="painelGeral">
        <div class="panel-body">
            <div class="">
                <div class="container">
                    <div class="row">
                        <div class="form-group">
                            <div class="checkbox" id="divCheckBox">
                                @Html.LabelFor(model => model.Ativo, htmlAttributes: new { @class = "control-label" })
                                @Html.EditorFor(model => model.Ativo)
                                @Html.ValidationMessageFor(model => model.Ativo, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-12">
                            @Html.LabelFor(model => model.Nome, htmlAttributes: new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.Nome, htmlAttributes: new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.Nome, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-6">
                            @Html.LabelFor(model => model.Sigla2, htmlAttributes: new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.Sigla2, htmlAttributes: new { @class = "form-control", placeholder = "" })
                            @Html.ValidationMessageFor(model => model.Sigla2, "", new { @class = "text-danger" })
                        </div>
                        <div class="form-group col-md-6">
                            @Html.LabelFor(model => model.Sigla3, htmlAttributes: new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.Sigla3, htmlAttributes: new { @class = "form-control", placeholder = "" })
                            @Html.ValidationMessageFor(model => model.Sigla3, "", new { @class = "text-danger" })
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <input type="submit" id="btnSalvar" value="Salvar" class="btn btn-primary" />
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-default" id="painelAuditoria">
        <div class="panel-body">
            <div class="form-horizontal">
                <div class="container">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.DataCadastro, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.DataCadastro, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.DataCadastro, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.UsuarioCadastro, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.UsuarioCadastro, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.UsuarioCadastro, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.DataAlteracao, htmlAttributes: new { @class = "control-label" })
                                    @Html.EditorFor(model => model.DataAlteracao, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.DataAlteracao, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-0 col-md-12">
                                    @Html.LabelFor(model => model.UsuarioAlteracao, htmlAttributes: new { @class = "control-label " })
                                    @Html.EditorFor(model => model.UsuarioAlteracao, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
                                    @Html.ValidationMessageFor(model => model.UsuarioAlteracao, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Lista de Paises", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    @if (cadastradoComSucesso)
    {
        <script>
            var functionSuccess = function () {
                $('#alerta').html('<div class="alert alert-success" role="alert"> Registro cadastrado com sucesso.</div>')
                $('#alerta').fadeIn(9000);
            };

            functionSuccess();

            $('#alerta').fadeOut(5000);

            $('#btnSalvar').prop('disabled', true);
        </script>
    }
    else if (cadastroComErro)
    {
        <script>
            var functionWarrning = function () {
                $('#alerta').html('<div class="alert alert-danger" role="alert"> Erro ao salvar registro.</div>')
                $('#alerta').fadeIn(9000);
            };

            functionWarrning();

            $('#alerta').fadeOut(5000);
        </script>
    }
    <script>
            jQuery(document).ready(function () {



                var tabGeral = $('#tabGeral');
                var tabAuditoria = $('#tabAuditoria');

                var painelGeral = $('#painelGeral');
                var painelAuditoria = $('#painelAuditoria');

                tabGeral.click(function () {
                    painelGeral.show();
                    painelAuditoria.hide();

                    $('.nav.nav-tabs li').each(function () {
                        if ($(this).attr('class') == "active") {
                            $(this).removeClass('active');
                        }
                    });
                    $(this).addClass('active');
                });

                tabAuditoria.click(function () {
                    painelGeral.hide();
                    painelAuditoria.show();

                    $('.nav.nav-tabs li').each(function () {
                        if ($(this).attr('class') == "active") {
                            $(this).removeClass('active');
                        }
                    });
                    $(this).addClass('active');
                });

                tabGeral.click();
            });

    </script>
}

inserir a descrição da imagem aqui

0


From what I can see, you’re using Asp.Net MVC and I had the same problem, so the solution is pretty simple.

When we create an Asp.Net MVC project a file is created in the Content folder called Site.css and then I commented to the lines below, with this I had all the control over the inputs

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.