Web全栈-盒子居中和内容居中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>盒子居中和内容居中</title>
    <style>
        .father{
            width: 800px;
            height: 500px;
            background-color: red;
            /*text-align: center;*/
            margin:0 auto;
        }
        .son{
            width: 100px;
            height: 100px;
            background-color: blue;
        }
    </style>
</head>
<body>

<!--
1.text-align:center;和margin:0 auto;区别
text-align: center;作用
设置盒子中存储的文字/图片水平居中

margin:0 auto;作用
让盒子自己水平居中
对块元素应用宽度属性width,并将左右的外边距都设置为auto,可使块级元素水平居中。
-->

<div class="father">
    我是文字<br/>
    <img src="images/girl.jpg" alt="">
    <!--<div class="son"></div>-->
</div>
</body>
</html>
posted @ 2019-10-15 17:22  yindanny  阅读(745)  评论(0编辑  收藏  举报