久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

css - 為何flex的align-items: center無法垂直居中?

瀏覽:165日期:2023-01-08 11:43:14

問題描述

參看語法規則完成練習,我只能水平居中,無法垂直居中,是少設置了什么嗎?我想實現的是在位置高度的情況下實現居中,這樣可以用到flex嗎?

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style>.box1{ width: 400px; height: 200px; background: #ccc; position: relative;}.leftCircle{ position: absolute; left: 0; top: 0; background: #fc0; width: 50px; height:50px; -webkit-border-radius:0 0 50px 0; -moz-border-radius:0 0 50px 0; border-radius:0 0 50px 0;}.rightCircle{ position: absolute; right: 0; bottom: 0; background: #fc0; width: 50px; height:50px; -webkit-border-radius:50px 0 0 0; -moz-border-radius:50px 0 0 0; border-radius:50px 0 0 0;}body{ display: flex; justify-content: center; align-items: center;} </style></head><body><p class='box1'> <p class='leftCircle'></p> <p class='rightCircle'></p></p></body></html>

問題解答

回答1:

給body 一個高度,這樣可以垂直居中了

html,body,.box1{ display: flex; justify-content: center; align-items: center; height:100%;}

標簽: CSS
相關文章:
主站蜘蛛池模板: 宜丰县| 阿拉善盟| 葫芦岛市| 土默特左旗| 永德县| 来宾市| 雷波县| 临沭县| 满洲里市| 湘潭县| 阿拉善右旗| 革吉县| 上高县| 依兰县| 平昌县| 通榆县| 华宁县| 麦盖提县| 南部县| 离岛区| 石林| 安国市| 三江| 广德县| 苗栗市| 龙胜| 得荣县| 沅江市| 金昌市| 偃师市| 通渭县| 鹤壁市| 阜城县| 天柱县| 上蔡县| 调兵山市| 涪陵区| 景德镇市| 红原县| 桦甸市| 江山市|