為什么實(shí)現(xiàn)不了居中?求解
<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屬性:是為文本內(nèi)容設(shè)置對(duì)其方式
?????????????????*left:左對(duì)齊
?????????????????*center:居中對(duì)齊
?????????????????*right:右對(duì)齊
????????????????*/
????????????????/*text-align:?center;*/
????????????}
????????????#child{
????????????????width:?200px;
????????????????height:?200px;
????????????????background:green;
????????????????/*
?????????????????display屬性:
?????????????????*block:塊級(jí)元素
?????????????????*inline:內(nèi)聯(lián)元素(text-align屬性有效)
????????????????????*width和heigtht屬性是無(wú)效的
?????????????????*inline-block:行內(nèi)塊級(jí)元素(塊級(jí)+內(nèi)聯(lián))
????????????????????*width和height屬性是有效的
????????????????*/
????????????????display:?table;
????????????????margin:?0?auto;
????????????????/*text-align:?left;*/
????????????}
????????</style>
????</head>
????<body>
????????<!--定義父級(jí)元素-->
????????<div?id="parent">
????????????<!--定義子級(jí)元素-->
????????????<div?id="child"></div>
????????</div>
????</body>
</html>
為什么我的這段代碼實(shí)現(xiàn)不了第二種解決方案
2020-06-24
可以的啊,子元素只要是塊,設(shè)置margin:0 auto ;就是可以的