用flex將內容居中

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        body{
            margin: 0px auto;
        }
        .app {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 100vw;
            height: 100vh;
            font-size: 8rem;
            background: hsl(240, 100%, 67%);
            color: hsl(0, 0%, 100%);
        }
    </style>
</head>

<body>
    <div class="app">
        <h3>Hey</h3>
    </div>
</body>

</html>

 

支持將任意的元素標籤<p>、<h2>、<img>居中顯示

flex-direction: column;

justify-content: center;

align-items: center;

//這三個樣式標籤自己體驗下就知道有什麼作用

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章