CSS中,我們可以使用flex布局來實(shí)現(xiàn)一個(gè)元素左右鋪滿頁(yè)面的效果,下面是一個(gè)具體的示例:
<!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: space-between; align-items: center; height: 100vh; } .item { width: 50%; height: 100%; background-color: #f0f0f0; } </style> </head> <body> <div class="container"> <div class="item"></div> <div class="item"></div> </div> </body> </html>
在這個(gè)示例中,我們創(chuàng)建了一個(gè)名為container
的容器,其中包含了兩個(gè)item
元素,每個(gè)item
元素的寬度設(shè)置為50%,高度設(shè)置為100%,并且背景顏色為#f0f0f0,通過justify-content: space-between;
屬性,我們可以確保兩個(gè)item
元素之間有一定的間隔,從而實(shí)現(xiàn)左右鋪滿頁(yè)面的效果,通過align-items: center;
屬性,我們可以確保兩個(gè)item
元素在垂直方向上居中對(duì)齊,通過height: 100vh;
屬性,我們可以確保容器的高度占滿整個(gè)頁(yè)面。