css - 为什么我的页面布局会有问题?
PHP中文网
PHP中文网 2017-04-17 14:32:51
0
4
853

我想做一个如图的页面:

可是我的D部分总是到C的最下端,如图:

每个块我的css样式都设为:

{float: left;
display:block;}

若想达到图1的效果,只有把D部分添加位置设置:

{position:absolute;}

然后给D指定上部距离多少多少。
想知道有没有别的方法,不是使用absolute的?谢谢各位~

PHP中文网
PHP中文网

认证0级讲师

reply all(4)
迷茫

A B D is regarded as a whole package in one big block, and C is laid out left and right, A B is laid out left and right, and D is laid out in a normal flow. Your current problem is that A B C are all floats, covering a row. Of course D will Start floating again from the second line

PHPzhong

float, float. If there is very little space for a floating element on a row, the element will jump to the next row, and this process will continue until a row has enough space.

洪涛

//css 
.right {
    float:right;
}

.left {
    float:left
}

.row::after{
   content:'';
    clear:both;
}



<p class="row">
    <p class="left">
        <p class="row">
             <p class="left">A</p>
             <p class="right">B</p>
        </p>
        <p>
            D
        </p>
    </p>
    <p class="side right"></p>
</p>
小葫芦

As far as the current situation is concerned, you can float ABC, but you can use relative positioning of D to make it go up... In addition, I think ABC should be able to use inline-block

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template