CSS布局

1.float

<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .one{
            background-color: red;
            width: 300px;
            height: 200px;
        }

        .two{
            background-color: yellow;
            width: 100px;
            float: left;
        }

        .three{
            background-color: blue;
            width: 100px;
            float: right;
        }
    </style>
</head>
<body>
    <div class="one">
        <div class="two">1111111111</div>
        <div class="three">22222222222</div>
        <div>22222222222</div>
        <div>22222222222</div>
        <div>22222222222</div>
    </div>
</body>
</html>

2.position

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        /*子绝父相*/
        .one{
            background-color: red;
            width: 300px;
            height: 400px;
            margin: 30px;
            position: relative;
        }

        .two{
            background-color: yellow;
            width: 50px;
            position: absolute;
            /*top: 20px;*/
            /*left: 20px;*/
            right: 100px;
            top: 100px;
        }
    </style>
</head>
<body>
   <div class="one">
     <div class="two">1234</div>
   </div>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容