css - How to solve the problem of float elements falling
怪我咯
怪我咯 2017-05-16 13:36:42
0
7
1200

Want to achieve this effect

But the current code is written like this

    <p class="main">
     <p class="left"></p>
     <p class="center"></p>
     <p class="right"></p>
    </p>
.main{

    margin: 0 auto;
width: 100%;
height: 100%;
overflow: hidden;

}

.left{
    width: 5rem;
    height: 3rem;
    float: left;
    margin: 2rem;
    background-image: url("/templates/CeHua/images/new01.jpg");

}
.center{
    width: 5rem;
    height: 3rem;
    float: left;
    margin: 2rem;
    background-image: url("/templates/CeHua/images/new02.jpg");
}
.right{
    width: 5rem;
    height: 3rem;
    float: left;
    margin: 2rem;
    background-image: url("/templates/CeHua/images/new03.jpg");
    
}

How should I solve it

I read a lot of replies about the width problem. After I change the width, the background image of p is not fully displayed. Is there a way to scale the photo to reduce the width?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(7)
迷茫

Set the width of the first two smaller, probably because the width exceeds the maximum width of the parent element, causing line breaks to be displayed

巴扎黑

Three sub-elements width: 33.333%. Try changing their margin to padding and use percentage.

大家讲道理

Reason 1: The width of the content + margin exceeds the width of the parent element. It is recommended to try changing the width.
Reason 2: All float: left, this problem is prone to occur, usually the two left on the left and the right on the right
Hope it can Helpful for you

淡淡烟草味

In CSS calculations, it is often 1+1>2. There are many possible reasons (such as borders, newline spaces, etc.). A better way to deal with it is to appropriately reduce the width of the child nodes.

The problem of the background image being blocked. After modifying the p width, the size of the background image must also be set simultaneously (100%), otherwise it will be displayed according to the actual size of the image.

左手右手慢动作

This attribute background-size:100% 100%;

给我你的怀抱

The set width is greater than 100%, causing it to overflow to the next line

某草草

Control p width, background-size:contain, solved. If the aspect ratio of the image is the same as your p, the image should not be deformed.

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