html 将flexbox强制转换为网格

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 将flexbox强制转换为网格相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Chapter 3: Forcing flexbox into a grid</title>
	<link rel="stylesheet" href="../assets/css/common.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto+Slab" rel="stylesheet">
    <style>
        .cards {
            margin: 0 -10px;
            padding: 0;
            list-style: none;
            display: flex;
            flex-wrap: wrap;
        }
        .cards li {
            width: calc(33.333333333% - 20px);
            background-color: #e5dbff;
            border: 1px solid #d0bfff;
            margin: 0 10px 20px 10px;
            padding: 10px;
            border-radius: 5px;
            flex: 0 0 auto;
        }
    </style>
</head>

<body id="ch1">
    <header class="example-header">
        <ul class="meta">
            <li class="book">The New CSS Layout</li>
            <li class="author">Rachel Andrew</li>
            <li class="chapter">Chapter 3</li>
            <li class="index"><a href="../">Index of examples</a></li>
        </ul>
        <div class="inner">
            <h1>Flex Items</h1>
        </div>
    </header>
    <div class="example">

        <ul class="cards">
            <li>
                <h2>Card 1</h2>
                <p>These cards have been laid out using flexbox. By setting <code>display: flex</code> on the parent, all direct children become flex items.</p>
            </li>
            <li>
                <h2>Card 2</h2>
                <p>These cards have been laid out using flexbox. By setting <code>display: flex</code> on the parent, all direct children become flex items.</p>
            </li>
            
             <li>
                <h2>Card 3</h2>
                <p>These cards have been laid out using flexbox. By setting <code>display: flex</code> on the parent, all direct children become flex items.</p>
            </li>
            <li>
                <h2>Card 4</h2>
                <p>These cards have been laid out using flexbox. By setting <code>display: flex</code> on the parent, all direct children become flex items.</p>
            </li>
            <li>
                <h2>Card 5</h2>
                <p>These cards have been laid out using flexbox. By setting <code>display: flex</code> on the parent, all direct children become flex items.</p>
            </li>
            
             
        </ul>
	 
    </div>
</body>
</html>

以上是关于html 将flexbox强制转换为网格的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Flexbox 将 4 个图像划分为 2x2 网格?

CSS多列布局Multi-column伸缩布局Flexbox网格布局Grid详解

html ITCSS Flexbox网格对象

带边距排水沟的 Flexbox 网格系统

如何使用 flexbox 制作灵活的 2x3 网格

使用 flexbox 具有相同高度元素的多线网格