300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > flex布局水平垂直居中

flex布局水平垂直居中

时间:2018-08-17 13:15:36

相关推荐

flex布局水平垂直居中

在flex布局中,子元素的属性代码写在父盒子里面,并且flex布局中任何元素都可以设置大小;居中的思路就是分清楚主轴justify-content和侧轴align-items,都设置为center即可,代码如下:

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>flex居中</title><style>div {display: flex;height: 600px;width: 600px;background-color: green;/* flex属性写在父盒子里面 *//* 主轴居中 */justify-content: center;/* 侧轴剧中 */align-items: center;}span {height: 200px;width: 200px;background-color: tomato;}</style></head><body><div><span></span></div></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。