<!DOCTYPE html><html><head> <meta charset="utf-8" /> <style> html, body { background: olive; position: relative; width: 100%; height: 100%; } /* 大小和颜色 */ .fa { width: 70%; height: 70%; background:navy; } .son { width: 50%; height: 50%; background: #999; } .center { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); } </style></head><body> <div class="fa center"> <div class="son center"> </div> </div></body></html>style中的第一个为什么必须html,body{},我只规定了body{},浏览器就不会显示子元素,只单单指定body为父元素不行吗?
添加回答
举报
0/150
提交
取消