请问如何设置 子div 在父div 水平居中

来源:7-1 定位案例

慕标3184021

2019-04-01 14:37:02

请问如何设置  子div 在父div 水平居中

写回答

1回答

好帮手慕查理

2019-04-01

您好,可以使用定位使子元素定位在父元素中:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
 body{
            margin:0px;
 padding:0px;
 }
        .out{
            width: 400px;
 height: 400px;
 background: orange;
 position: relative;
 }
        .order{
            width: 200px;
 height: 200px;
 background: pink;
 position: absolute;
 left: 100px;
 top: 100px;
 }
    </style>
</head>
<body>
    <div class="out">
        <div class="order">
        </div>
    </div>
</body>
</html>

祝学习愉快!

0

0 学习 · 4928 问题

查看课程