What is the best way to transfer list-items to a separate column when they exceed the height of the container?

I have a list that I would like to organize into two columns. The number of items in the list may vary, but it will not exceed 8.

My goal is to always have the first column display 4 elements. I attempted to use column-count: 2 but this did not work properly with an odd number of items because the first row needs to contain 4 elements.

.container {
  border: 1px solid red;
  width: 300px;
  height: 90px;
}
<div class="container">
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ul>
</div>

Answer №1

If you want to achieve this layout, you can utilize Flexbox in your CSS:

ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  width: 300px;
  height: 200px;
}
li {
  height: 25%;
}
<div class="container">
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
  </ul>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to extract data from an HTML table and store it in an array using JavaScript with the help of jQuery

Currently, I am faced with a challenge involving extracting values from an HTML table and storing them in a 2-dimensional array using JavaScript. jQuery seems like the ideal solution for this task. While I have managed to get the indices working properly, ...

Is it possible to select a checkbox using BeautifulSoup or Selenium?

Currently, I am getting familiar with Selenium and BeautifulSoup, but I'm facing a challenge with the following scenario: I have a collection of product codes: ['1242737-011', '4232345-015', '5673845-013'] My goal is t ...

Fixing Bootstrap's Timeline Component

I've created a Bootstrap timeline that works well on mobile and small screens, but encounters some issues on larger devices. You can view it at https://codepen.io/irshad437/pen/rLvxxa. Feel free to resize your window to test its functionality, which s ...

How can I change the padding that is being inherited from "@ .MuiAlert-icon"?

Is there a method to override the padding inherited from "@ .MuiAlert-icon"? The Chrome inspector indicates that the current padding is set to 7px. .MuiAlert-icon { display: flex; opacity: 0.9; padding: 7px 0; font-size: 22px; ...

Switch up the style and vibe using a drop-down menu option

I have successfully implemented the functionality for Ace to save and open files. The only thing left is to dynamically change its mode based on the selected value of a <select><option> element. Once this is achieved, I will have accomplished e ...

Utilize hashchange event to display specific div elements

I have several hidden divs on my webpage. Users can select jobs by clicking on links (such as "#job8"). I am attempting to use the hashchange function in my script to check the URL for a specific hash and then show the corresponding div. Below is an examp ...

Banner with video background (not taking up the entire page)

I'm currently working on a website project that involves using a YouTube video as the banner, but I'm facing some challenges in making it work correctly. So far, this is what I have: #video-background { position: absolute; right: 0; top:1 ...

Using CSS to automatically convert a table into one column layout with labels from the thead section

Is it possible to automatically create the labels for data when converting a multi-columns table into one column using CSS and taking the information from the thead section? This resource discusses how to convert a multi-column table into a single column ...

inline-table property

Is there an issue with IE 7 not supporting display:inline-table? While other browsers are compatible, what steps should be taken to find an alternate solution? ...

Can I Minify HTML using Node.js, Express, and EJS?

Currently, I am working with EJS in conjunction with Node and Express. However, I have noticed that the HTML generated by my views contains excessive whitespace. Is there a specific middleware or option available for use in production that can help compres ...

Using Javascript to generate a photo gallery from files named with dates

It's driving me insane, guys. I know there are limitations when using JavaScript, but the website I'm creating consists only of HTML files. I can incorporate PHP as a separate file that can be referred to, not included. The final extension must b ...

Is using the img-responsive class in Twitter Bootstrap 3 causing my container-fluid divs to resize?

Seeking some insights on a Bootstrap issue I'm experiencing. I've observed that the "container-fluid" divs with responsive images are slightly smaller than those containing only text. This inconsistency in sizing is affecting the overall look o ...

Storing a portion of JSON data within a function called in the HTML document

I've been working with Angular and need to save a portion of JSON data in a variable within a function that is called in an HTML file: <select id="postazione" onchange="postazioneSelezionata()"> <option value="" selected disabled >Cho ...

Customizing a div's hyperlinks using JavaScript

I want to use JavaScript to change the appearance of a specific element's links. The CSS code would be: #element a:link { color: #000; } I am aware that you can modify the style of the element itself, like so: elementObject.style.color = ' ...

Issue with Image Quality in Woocommerce/Wordpress Products

I'm experiencing an issue with either Wordpress or Woocommerce. Yesterday, I updated Woocommerce while installing a new theme. Unfortunately, I'm facing a problem now where I can't seem to improve the image quality on the product page. Jus ...

Updating user schema in Angular to include question_id in list of bookmarks

Schema: var UserSchema = new Schema({ ques_bookmarks: [{ type: String }], }) Controller: .controller('questionsController', function(questionsFactory, $routeParams, $scope) { var that = this; questionid = $routeParams.id; stats = fal ...

The functionality of the controls is not functioning properly when attempting to play a video after clicking on an image in HTML5

While working with two HTML5 videos, I encountered an issue with the play/pause functionality. Despite writing Javascript code to control this, clicking on one video's poster sometimes results in the other video playing instead. This inconsistency is ...

Modifying HTML Email to Achieve Consistent Rendering Across Various Email Platforms

While creating an HTML based email for our subscribers, I noticed that it renders differently in various email clients. The main issue arises in Outlook 2003 where the main picture is offset to the left and the grid boxes vary in height depending on the co ...

Issues with sending UTF-8 letters from HTML form inputs in PHP and Moodle

Having trouble with my form and email handler not transmitting UTF-8 characters from inputs. The email functionality is working fine and supports UTF-8 characters, but the data from the form inputs are not being encoded correctly. I'm at a loss as to ...

Utilizing Respond.js to Implement CSS3 Media Queries

Currently, I am attempting to implement Respond.js in order to utilize CSS3 Media Queries on older versions of Internet Explorer. You can find more information about Respond.js at here. Unfortunately, I seem to be encountering an "Access denied" message i ...