Hongmu Notes
Home Language Notes In ul, how to divide 6 li into two columns?
Language Notes CSS

In ul, how to divide 6 li into two columns?

In ul, how to divide 6 li into two columns?

In HTML and CSS, there are various ways to implement this.<ul>6<li>The elements are displayed in two columns. Below are several common methods:

Method 1: Use CSS Flexbox

You can<ul>Set it as a Flex container, then configure it accordingly.flex-wrapAttribute:wrapAnd specify each<li>Use the width of an element (e.g., 50%) to create a two-column layout.

<ul class="flex-container">  
  <li>项目 1</li>  
  <li>项目 2</li>  
  <li>项目 3</li>  
  <li>项目 4</li>  
  <li>项目 5</li>  
  <li>项目 6</li>  
</ul>  
  
<style>  
.flex-container {  
  display: flex;  
  flex-wrap: wrap;  
  list-style-type: none;  
  padding: 0;  
}  
  
.flex-container li {  
  flex: 1 0 50%; /* 占据50%的宽度,不伸缩,基础大小为50% */  
  box-sizing: border-box; /* 防止padding和border影响布局 */  
  padding: 10px; /* 示例padding */  
}  
</style>

Method 2: Use CSS Grid

CSS Grid is another powerful layout tool that allows for a very straightforward implementation of a two-column layout.

<ul class="grid-container">  
  <li>项目 1</li>  
  <li>项目 2</li>  
  <li>项目 3</li>  
  <li>项目 4</li>  
  <li>项目 5</li>  
  <li>项目 6</li>  
</ul>  
  
<style>  
.grid-container {  
  display: grid;  
  grid-template-columns: repeat(2, 1fr); /* 创建两列,每列占据可用空间的一部分 */  
  list-style-type: none;  
  padding: 0;  
}  
  
.grid-container li {  
  padding: 10px; /* 示例padding */  
}  
</style>

Method 3: Use CSS Columns

CSSand so oncolumnsAttributes can also easily be used to implement a multi-column layout; however, it's important to note that this approach automatically distributes content across multiple columns rather than explicitly specifying the position of each element.

<ul class="column-container">  
  <li>项目 1</li>  
  <li>项目 2</li>  
  <li>项目 3</li>  
  <li>项目 4</li>  
  <li>项目 5</li>  
  <li>项目 6</li>  
</ul>  
  
<style>  
.column-container {  
  columns: 2; /* 分为两列 */  
  column-gap: 20px; /* 列之间的间隙 */  
  list-style-type: none;  
  padding: 0;  
}  
  
.column-container li {  
  break-inside: avoid; /* 防止列表项被分割到两列中 */  
  padding: 10px; /* 示例padding */  
}  
</style>

Each of the three methods mentioned above has its own advantages and disadvantages; you can choose the most suitable one based on your specific requirements and project context.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

css positioning

css positioning Language Notes CSS

Syntax: position: static | relative | absolute | fixed | center | page | sticky Default value: static Applies to: All elements except the display attribute defined as table-column-group | table-column Inheritance: No Animation: No...
👁 119
css vh and vw adaptive

css vh and vw adaptive Language Notes CSS

In the mobile terminal, REM is used to change the root HTML, and the mobile terminal adaptation is realized through a piece of JS. This article uses pure CSS viewport units to self-adapt. Although the current compatibility is not fully acceptable, it does not prevent you from recognizing the power of vw and vh. The implementation of responsive layout relies on media queries (Media Queries). Select the width size of mainstream devices as breakpoints to target...
👁 356

Recommended reading

Responsive, minimalist article and blog website template – 0008

Responsive, minimalist article and blog website template – 0008 Practical Collection Yiyou template

This EyouCMS responsive template is designed for minimalist article-based information and blog websites, featuring a clean and modern style focused on providing an optimal content reading experience. It is ideal for individual bloggers, content creators, or website administrators looking to build a blog platform to share articles, perspectives, and industry news. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (E...
👁 36
Responsive Precision Machinery and Mold Website Template 0626

Responsive Precision Machinery and Mold Website Template 0626 Practical Collection Yiyou template

An eyouCMS responsive website template designed specifically for precision machinery and mold manufacturing enterprises. Its professional and sophisticated design effectively showcases precision mold products, processing equipment, and technical expertise. This template helps mold manufacturing companies demonstrate their high-precision manufacturing capabilities online and attract clients from the electronics and automotive industries. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Installation Questions for eyouCMS...
👁 49
(PC+WAP) Activity Partitioning – Decoration & Interior Design Website – pbootCMS Template; Download Blue Low-Carbon Eco-Friendly Partitioning Website Source Code – 0588

(PC+WAP) Activity Partitioning – Decoration & Interior Design Website – pbootCMS Template; Download Blue Low-Carbon Eco-Friendly Partitioning Website Source Code – 0588 Practical Collection pbootcms Template

A blue modular partition system paired with a low-carbon, eco-friendly interior design PbootCMS website template, compatible with both PC and mobile devices. The fresh, sustainable design style effectively showcases the application of partition products in office and commercial spaces. This template helps interior design and renovation companies demonstrate their product expertise and secure more project contracts. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 50
Fishing Gear Wholesale Website Template 0009

Fishing Gear Wholesale Website Template 0009 Practical Collection Yiyou template

An eYouCMS website template designed specifically for the fishing tackle wholesale and fishing equipment industry. Its practical and professional design effectively showcases fishing gear products, accessories, and wholesale information, helping fishing equipment manufacturers or wholesalers establish an efficient online product display and sales platform. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS...
👁 40
Marketing generator electromechanical equipment website template 0627

Marketing generator electromechanical equipment website template 0627 Practical Collection Yiyou template

This set of eyoucms templates is suitable for marketing generators and electromechanical equipment companies. The design style is professional and industrial, and can display generator set products, electromechanical equipment and technical solutions. It helps electromechanical companies display their products online and attract industrial and power customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in Yiyou CMS installation Yiyou C...
👁 52
(Adaptive mobile version) PBootCMS website template for business registration agencies; Download source code for financial accounting websites – 0589

(Adaptive mobile version) PBootCMS website template for business registration agencies; Download source code for financial accounting websites – 0589 Practical Collection pbootcms Template

A PbootCMS website template designed for business registration and corporate setup services, compatible with both PC and WAP devices. Its professional and sophisticated design makes it ideal for accounting firms and business registration agencies to showcase their registration processes, financial and tax services, and successful case studies. It helps business service providers attract startup clients online. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5....
👁 50