PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 18, 2022

[FIXED] How to vertically align elements with horizontal overflow

 November 18, 2022     css, vertical-alignment     No comments   

Issue

I want to be able to create a div with a set size (in this example 100x100).

Then i want to be able to add x number of elements inside the div, in this example we can say 10 buttons with the size of 10x10 and align them vertically.

This means all buttons should be in a single column.

Then if i resize and make the new size 80x80 i should have 2 columns, the first with the first 8 buttons and then a new columns with the last 2 buttons.

I have tried with

flex-wrap: wrap;
display: flex;
flex-direction: column;
align-content: flex-start;

It aligns vertically but then when i resize the buttons keeps going over the bottom.

How can i align all elements so they are aligned vertically but if the height are not enought it should overflow into a new column. So no set number of columns since it could be x number of columns depending on the size.

Is this possible using css?


Solution

I think it only works when you give the container a maximum height. Is this what you need?

.container {
  flex-wrap: wrap;
  display: flex;
  flex-direction: column;
  align-content: flex-start;
  max-height: 100px;
}

.button {
  width: 100px;
  height: 10px;
  border: solid thin black;
}
<div class="container">
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
  <div class="button"></div>
</div>



Answered By - Gerard
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing