為什么實現不了居中?求解
<html?lang="en">
????<head>
????????<meta?charset="UTF-8">
????????<meta?name="viewport"?content="width-device-width,initial-scale=1.0">
????????<meta?http-equiv="X-UA-Compatible"?content="ie=edge">
????????<title>水平居中布局的第一種解決方案</title>
????????<style>
????????????#parent{
????????????????width:?100%;
????????????????height:?200px;
????????????????background:?blue;
????????????????/*
?????????????????text-align屬性:是為文本內容設置對其方式
?????????????????*left:左對齊
?????????????????*center:居中對齊
?????????????????*right:右對齊
????????????????*/
????????????????/*text-align:?center;*/
????????????}
????????????#child{
????????????????width:?200px;
????????????????height:?200px;
????????????????background:green;
????????????????/*
?????????????????display屬性:
?????????????????*block:塊級元素
?????????????????*inline:內聯元素(text-align屬性有效)
????????????????????*width和heigtht屬性是無效的
?????????????????*inline-block:行內塊級元素(塊級+內聯)
????????????????????*width和height屬性是有效的
????????????????*/
????????????????display:?table;
????????????????margin:?0?auto;
????????????????/*text-align:?left;*/
????????????}
????????</style>
????</head>
????<body>
????????<!--定義父級元素-->
????????<div?id="parent">
????????????<!--定義子級元素-->
????????????<div?id="child"></div>
????????</div>
????</body>
</html>
為什么我的這段代碼實現不了第二種解決方案
2020-06-24
可以的啊,子元素只要是塊,設置margin:0 auto ;就是可以的