为了账号安全,请及时绑定邮箱和手机立即绑定

为什么实现不了居中?求解

<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>


为什么我的这段代码实现不了第二种解决方案

正在回答

1 回答

可以的啊,子元素只要是块,设置margin:0 auto ;就是可以的

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么实现不了居中?求解

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信