Dar height and overflow-y in a div

Asked

Viewed 275 times

4

I’m trying to give height and overflow-y in a div to limit the size of the div and add a scroll.

Something like this:

inserir a descrição da imagem aqui

I’m uploading a list of data from the BD (I’m working on ASP MVC) to the div, and adding to height and the overflow-y in the same:

<div id="divListaEstabs" style="height: 60%; overflow-y: scroll;">
        <input type="checkbox" id="selectall">Seleccionar todos
        <br />
        @foreach (var item in ViewBag.estabelecimentos)
        {
            <input type="checkbox" value="@item.IdFilial" name="filialCopia"/>@item.Nome<br />
        }
</div>

Problem?

The scroll is added in the div, but it is not limited in height, increasing the page size (as shown in the image): inserir a descrição da imagem aqui

2 answers

4


You have the height(height) in %. Experiment in px:

<div id="divListaEstabs" style="height: 60px; overflow-y: scroll;">
        <input type="checkbox" id="selectall">Seleccionar todos
        <br />
        @foreach (var item in ViewBag.estabelecimentos)
        {
            <input type="checkbox" value="@item.IdFilial" name="filialCopia"/>@item.Nome<br />
        }
</div>
  • That was the mistake :)

1

Try to change from heigth to max-heigth, so you’ll have more flexibility and responsiveness in modal:

<div id="divListaEstabs" style="max-height: 10em; overflow-y: scroll;">
    <input type="checkbox" id="selectall">Seleccionar todos
    <br />
    @foreach (var item in ViewBag.estabelecimentos)
    {
        <input type="checkbox" value="@item.IdFilial" name="filialCopia"/>@item.Nome<br />
    }
</div>
  • i tried this. The error was right where pc_oc said: when using % to set the height stop giving, it has to be with px

  • I’d use another unit then as em, to maintain screen responsiveness.

  • That’s right, that’s right

Browser other questions tagged

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