老师 子div怎样之于父div完全居中,align里面好像没有

来源:7-8 编程练习

SomnusL

2020-03-07 01:09:48

。。。。。。

写回答

1回答

guly

2020-03-07

你好,建议使用绝对定位,参考代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        .father{
            width:500px;
            height: 500px;
            position:relative ;
            background-color: red;
        }
        .son{
            width: 200px;
            height: 200px;
            position: absolute;
            top:50%;
            left:50%;
            margin-top: -100px;
            margin-left:-100px;
            background-color: black;
        }
       
    </style>
</head>
<body>
<div class="father">
    <div class="son">1111</div>
</div>
</body>
</html>

如果解决您的问题请采纳,祝学习愉快!

0

0 学习 · 9666 问题

查看课程