how to create a layout using float

Asked

Viewed 256 times

0

I’m trying to create a page like the one in the picture, but without success. From what I’ve been seeing I need to use the float property.

inserir a descrição da imagem aqui

I’ve reached that point, but you’re not responsive either. inserir a descrição da imagem aqui

In the second photo I created, I can’t make the 4 images take the whole screen and the layout remain responsive.

  • First welcome, what have you tried to do?

  • 1

    Could you [Dit] the question and add your attempts as well as the result you got in each of them? Actually your question is almost a "do it for me," but I don’t think that’s what you want, is?

  • 1

    Young even without seeing your code I tell you that the best solution for this is not with Float, because float is to adjust the flow of content, elements and text. To make layouts these days preferably for Flex and Grid or both Together if you need to.

  • so I can’t float or Bootstrap

  • Can you do it... just don’t... I’ll make a simple example for you with Flex

  • I expressed myself badly, I don’t really know how to do with float or bootstrap....

  • I edited my answer, put option with Flex and Float, the Float model do not recommend and will give you more work to align the contents in the center...

Show 2 more comments

1 answer

4


Follow a flex model. Here’s a complete guide that can help you. https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Display the code in full screen to see the responsiveness and how they behave. On screens smaller than 768px they get the bigger box above and the smaller ones below. On large screens they are side by side.

inserir a descrição da imagem aqui

The values here are all in % so it’s very responsive, and the height of the container I left with 50vh, 50% of the height of body. But you can put a fixed value here in px if you want to leave the height always with a set size .container { height: 50vh; }

Follow the code referring to the image above:

OBS: I could have optimized the CSS more because some properties repeat a lot, but I prefer to leave it like this to facilitate understanding.

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
* {
    box-sizing: border-box;
    border: 1px solid #000;
}
.container {
    width: 100%;
    height: 50vh;
    display: flex;
    justify-content: center;
    align-items: center;
}
.left {
    width: 50%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.right {
    width: 50%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}
.box {
    width: 50%;
    height: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}
@media screen and (max-width:768px) {
.container {
    flex-direction: column;
}
}   
.left, .right {
    width: 100%;
}
}
<div class="container">
    <div class="left">esquerda</div>
    <div class="right">
        <div class="box">1</div>
        <div class="box">2</div>
        <div class="box">3</div>
        <div class="box">4</div>
    </div>
</div>


With Float

Same layout above, but using Float. Just for teaching purposes so you can see what I’d look like using Float. Although I don’t recommend it, and it gets more complicated to align the internal elements at the center.

Display the code below

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
* {
    box-sizing: border-box;
    border: 1px solid #000;
}
.container {
    width: 100%;
    height: 50vh;
}
.left {
    width: 50%;
    height: 100%;
    float: left;
}
.right {
    width: 50%;
    height: 100%;
    float: left;
}
.box {
    width: 50%;
    height: 50%;
    float: left;
}
    
@media screen and (max-width:768px) {
.left {
    width: 100%;
    height: 50%;
    float: left;
}
.right {
    width: 100%;
    height: 50%;
    float: left;
}
}
<div class="container">
    <div class="left">esquerda</div>
    <div class="right">
        <div class="box">1</div>
        <div class="box">2</div>
        <div class="box">3</div>
        <div class="box">4</div>
    </div>
</div>

  • more as I would, to make the break ... example that when you arrive at the breakpoint x the 4 images is redirected down

  • @Roneyberti Nice quiet, just create a @media screen and (max-width:768px) { seus ajustes } In the case of Flex vc puts flex-Direction as column and right and left now at 100% width, and in Com Float vc puts right and left now at 100% width, but now at 50% height. You can see in the code that I’ve already updated as the @media to make it easy for you

  • 1

    guy was that same, thank you very much ... I will study your codes to intender a little ... the day you give class calls me without fail.

  • @Roneyberti guy I’m also a student yet, I have no way to teach :D. But I’m glad it worked out! If my answer has helped you in any way consider marking it as Accept, in this icon below the arrows on the left side of my answer :) so the site does not get open questions pending without accepted answer. Abs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.