Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
Ul li elements exceeding DIV height

I have a div with fixed height and it has Ul, li elements, so if the contents of the ul/li elements exceed the div height, it should align to the right side and not overflow outside the div. I have tried everything but not able to achieve it, below is my code:

div {
  max-height: 200px;
  background: red;
}
<div>
  <h3>ItemsA</h3>
  <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
  </ul>
  <h3>ItemsB</h3>
  <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
  </ul>
  <h3>ItemsC</h3>
  <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
  </ul>
</div>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

If you want place a row of li elements. You can give the div display: flex feature. If the height of the lis exceeds the height of the div, you can use overflow-y: auto. This puts the scroll bar to parent div

.parent {
  max-height: 200px;
  background: red;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
<div class="parent">
   <div>
    <h3>ItemsA</h3>
    <ul>
     <li>Item1</li>
     <li>Item2</li>
     <li>Item3</li>
     <li>Item4</li>
    </ul>
   </div>
   <div>
    <h3>ItemsB</h3>
    <ul>
     <li>Item1</li>
     <li>Item2</li>
     <li>Item3</li>
     <li>Item4</li>
    </ul>
   </div>
   <div>
    <h3>ItemsC</h3>
    <ul>
     <li>Item1</li>
     <li>Item2</li>
     <li>Item3</li>
     <li>Item4</li>
    </ul>
   </div>
   <div>
    <h3>ItemsD</h3>
    <ul>
     <li>Item1</li>
     <li>Item2</li>
     <li>Item3</li>
     <li>Item4</li>
    </ul>
   </div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

First of all I'd highly suggest wrapping each <ul> and its associated <h3> into a container, so you can control the layout much better. In whatever layout you're using, it would directly affect both the <ul> and the <h3>-elements individually. By wrapping the two associated elements into separate containers, the layout properties are affecting those containers only.

One way to solve this is using flex-wrap. By applying flex-direction: column, the flex-flow will try to put the elements in a single column, and if they can't, they will wrap into a new column.

/* Simple reset */
* {
  margin: 0;
  box-sizing: border-box;
}

.wrapper {
  max-height: 200px;
  background: red;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
}
<div class="wrapper">
  <div class="container">
    <h3>ItemsA</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
  <div class="container">
    <h3>ItemsB</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
  <div class="container">
    <h3>ItemsC</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
    <div class="container">
    <h3>ItemsD</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

.item-list {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  height: 100px;
  overflow-y: scroll;
  background: red;
}
<div class="item-list">
  <div>
    <h3>ItemsA</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
  <div>
    <h3>ItemsB</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
  <div>
    <h3>ItemsC</h3>
    <ul>
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </div>
 </div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda