国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

問題描述

參看語法規(guī)則完成練習(xí),我只能水平居中,無法垂直居中,是少設(shè)置了什么嗎?我想實(shí)現(xiàn)的是在位置高度的情況下實(shí)現(xiàn)居中,這樣可以用到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 一個(gè)高度,這樣可以垂直居中了

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

標(biāo)簽: CSS
相關(guān)文章:
主站蜘蛛池模板: 嘉定区| 云安县| 会宁县| 香港 | 秀山| 贵州省| 左贡县| 逊克县| 疏勒县| 霍山县| 长海县| 大化| 柘城县| 建水县| 福安市| 衡南县| 保靖县| 梁平县| 康马县| 盐津县| 洪雅县| 枣庄市| 邵武市| 广平县| 广汉市| 郯城县| 伽师县| 民县| 临沭县| 松潘县| 甘德县| 东平县| 西乡县| 建宁县| 衡山县| 吴江市| 泊头市| 道孚县| 黄浦区| 诏安县| 离岛区|