为什么我这样写不行,明明改的是top,但是content也跟着一起变了

来源:3-5 编程练习

慕工程331170

2020-03-11 20:24:29

<html>

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

        .content{

            width:800px;

            height:400px;

            background-color: skyblue;

            /*padding-top:100px;

            box-sizing:border-box;*/

        }

        .top{

            width:400px;

            height:200px;

            background-color: yellow;

            margin-left:200px;

            margin-top:100px;

        }

    </style>

</head>

<body>

    <div class="content">

        <div class="top"></div>

    </div>

</body>

</html>


写回答

1回答

guly

2020-03-12

你好,建议参考代码如下:

<html>

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

        .content{

            width:800px;

            height:400px;

            background-color: skyblue;
            position: relative;

            /*padding-top:100px;

            box-sizing:border-box;*/

        }

        .top{

            width:400px;

            height:200px;

            background-color: yellow;

            /*margin-left:200px;*/

            /*margin-top:100px;*/
            position: absolute;
            left: 200px;
            top: 100px;
        }


    </style>

</head>

<body>

<div class="content">

    <div class="top"></div>

</div>

</body>

</html>

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

0

0 学习 · 9666 问题

查看课程