HTML/CSS/JavaScript

CSS布局

2017-07-16  本文已影响3人  阿凡提说AI

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>
上一篇下一篇

猜你喜欢

热点阅读