美文网首页
CSS justify-content align-items

CSS justify-content align-items

作者: GaoEnron | 来源:发表于2020-01-01 12:25 被阅读0次

    通过 justify-content align-items 实现居中

    article {
        display: flex;
        border: solid 5px silver;
        border-color: #8A2BE2;
        width: 450px;
        height: 280px;
        background: red; /*  */
        flex-direction: row;
        justify-content: center;
            align-items: center;
    }
                
    

    代码:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" content="width=device-width, initial-scale=1.0">
            <title></title>
            <style type="text/css">
                * {
                    padding: 0px;
                    margin: 0px;
                }
                
                body {
                    padding-left: 0px;
                    padding-top: 15px;
                }
                
                article {
                    display: flex;
                    border: solid 5px silver;
                    border-color: #8A2BE2;
                    width: 450px;
                    height: 280px;
                    background: red; /*  */
                    flex-direction: row;
                    justify-content: center;
                    align-items: center;
                }
                
                article * {
                    width: 100px;
                    height: 100px;
                }
                
                .first {
                    background: #87CEEB;
                }
                
                .second {
                    background: #FFA07A;
                }
                
                .third {
                    background: lightpink;
                }
                .fourth {
                    background: lightgreen;
                }
            
            </style>
        </head>
        <body>
            <article>
                <div class="first">第一</div>
                <div class="second">第二</div>
                <div class="third">第三</div>
                <div class="fourth">第四</div>
            </article>
        </body>
    </html>
    
    

    相关文章

      网友评论

          本文标题:CSS justify-content align-items

          本文链接:https://www.haomeiwen.com/subject/zaipoctx.html