Attempting to disrupt the line for every trio of elements consecutively

I am facing an issue with my code. It's functional, but not completely.

ul {
  columns: 3;
  -webkit-columns: 3;
  -moz-columns: 3;
}
<ul>
  <li>Some text</li>
  <li>Some text</li>
  <li>Some text</li>
  <li>Some text</li>
  <li>Some text</li>
  <li>Some text</li>
  <li>Some text</li>
</ul>

The issue lies in the fact that when there is an extra element beyond multiples of 3, it does not create a new row for them. Instead, it tries to fit everything into 3 columns, causing some elements to look out of place.

I'm open to using divs, spans, or list items if they help resolve this problem. I can apply CSS to hide the bullets associated with the list items to achieve the desired layout.

Answer №1

The issue arises from the sequential population of columns, resulting in an unbalanced final column.

Converting the ul element into a flex container displays the li elements side by side. Using the flex-wrap property with wrap functionality allows elements to transition to a new line when exceeding container width.

Setting the flex-basis property to calc(100% / 3) ensures each li occupies one-third of the container's width.

Feel free to test this CSS code:

ul {
  display: flex;
  flex-wrap: wrap;
}

li {
  flex-basis: calc(100% / 3);
}

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

Modifying button appearance based on state change in AngularJS

I have a button with a grey color and I want to create two different states for it: one that is selected (blue) and another that is in an idle state (grey). Currently, I am working on Angularjs but I am fairly new to this platform. Could you kindly provid ...

An Inquiry into the Basics of CSS and jQuery

Just getting the hang of css and jQuery, I'm utilizing a CSS class named .content for various elements on my webpage like side navigation box, picture of the day box, statistics box, etc., all laid out using definition lists. Now, when I click on the ...

What method can be employed to eliminate choice selection lacking any value?

Currently, I am encountering difficulties in my attempt to remove or hide the first option value from a ransack code. Would you be able to assist me in addressing this concern? Here is the HTML CODE that I am working with: <select id="q_c_0_a_0_name" ...

Is it possible to form a union type using an interface?

My goal is to call the function getSvgPresentationAttribute using any valid CSS property name as cssStyleAttribute. However, I am encountering an issue with my current code where I receive the error message Type 'CSSStyleDeclaration' cannot be us ...

Ways to conceal a grid item in Material UI framework

My goal is to hide a specific grid item for a product and smoothly slide the others in its place. Currently, I am using the display:none property but it hides the item instantly. I have already filtered the products and now I want to animate the hiding of ...

Transforming an Associative Array into a Structured Table

I have a task of converting an Associative Array into an HTML Table. This is how the Array is structured: Array ( [] => Harvest_Project Object ( [_root:protected] => project [_tasks:protected] => Array ( ) ...

The embedment of wmv videos does not include the option for a fullscreen button

I am currently attempting to insert a wmv video into an HTML code. The file plays without any issues, however, I would like the website's users to have the option to view the video in fullscreen mode by clicking on a fullscreen button. Unfortunately, ...

Expanding the height of div elements while dynamically including content

Currently, my web application is designed to dynamically add content using ajax and then slide down. It typically includes two divs on either side with a height of 100% and a repeated image acting as a border. However, when new content is added, the bord ...

Aligning two floating elements vertically in respect to each other

Although the topic of vertically centering elements is common on various websites, I am new to HTML and still find it confusing even after doing some research. I attempted to create a basic header element for a website that includes an h1 title and a navi ...

Is it possible to automate the process of clicking the "next" or "previous" button on a webpage after a video has finished playing?

Is it possible to automate clicking the "next" or "previous" button on a specific website? The buttons are not labeled as such but instead show the cartoon name and episode number. For example, increasing episode numbers indicate the "next" episode while d ...

`We are experiencing alignment issues with the Bootstrap drop-down menu`

I'm struggling to understand why my menu isn't aligning properly on the sub dropdowns. They are appearing at the lower edge of their parent cell, making navigation quite difficult. You have to drop down diagonally just right to access the next me ...

Having difficulty accessing the selected input value from window.localstorage

<script> (function(window, document, undefined) { function saveFormData(event) { if(event.target.type=='checkbox' || event.target.type=='radio') { window.localStorage.setItem(event.target.id, event.target. ...

Troubleshoot: Problem with the name attribute in ASP.NET CheckBox control

When I use a checkbox with the attribute runat="server" in my ASP.NET web application, browsers encounter an issue: Uncaught Syntax error, unrecognized expression: [name=ctl00$ctl00$ContentPlaceHolder1$FormPlaceHolder$CrossFinancing] The ASP.NET code ...

html nested table with merged columns

I've come across this issue before, but I just can't seem to figure out how to implement a multi-layered colspan in an HTML table. The HTML table I'm working with is from w3schools, but I want to create a colspan of 2 for Data 2 and Data 5. ...

When utilizing table-cell, the padding will automatically increase within the <div>

After creating two tables using table,table-cell, I noticed that increasing padding on the first cell also results in an increase in padding on the second cell, and vice versa. How can this issue be resolved? .desc-one{ width: 100%; margin-bottom: 2 ...

Incorporating a new div element into a CSS layout with multiple

Could this be done? Imagine I have 15 divs, with 3 in each of the 5 columns of a multiple column CSS layout. I also have responsive code that adjusts the number of columns based on screen size. So, is there a way to insert a div between the 12th and 13th ...

I designed a dropdown menu with a searchable <mat-select> feature, where selecting an item is automatic when a space bar is pressed in the search box

Description : I have implemented a dropdown list using element that contains a list of items along with a search field. This allows users to easily search for specific items in the list instead of manually scrolling through a long dropdown menu. They can ...

CSS-powered tabs which necessitate the conventional display of radio buttons and labels inside each tab

Creating CSS-only tabs involves hiding the radio button and styling the tab label accordingly. .tabs input[type="radio"] { position: absolute; top: -9999px; left: -9999px; } .tabs label { display: block; min-height: 150px; padding: 4px 4px; ...

Utilizing Yeoman/Grunt for Generating CSS from SASS Files in a Specific Subdirectory

Reviewing My Current Folder Structure: https://i.sstatic.net/RuNqd.png All my sass files residing in the styles folder (like newStyles.sass) are getting compiled successfully. However, the sass files within the myUi directory (e.g., nuclearMed.sass) are ...

Expanding image size with CSS

Looking for assistance to fix the squished image in HTML & CSS. I used the CSS code provided by Figma to style the image in html, but it resulted in a different aspect ratio from the original picture, causing the image to appear squished. Any help is appr ...