Blocks side by side above and below

Asked

Viewed 500 times

0

Hello, I’ve been postponing this doubt and leaving aside [...] I look for a simple solution to leave blocks of tables side by side. In this example the blocks start at the bottom edge up with alignment of the block containing 'height' larger. I want you to start from top to bottom, and when there is a block with 'height' larger does not unravel, being aligned to side or bottom in a space of 3px.

<style>
    body{
        background:black;
    }
</style>

<h2>Titulo</h2>
<ul class="galeria">
    <li><div style="position:relative;width:100px; height:100px; background:yellow;"</div></li>
    <li><div style="position:relative;width:100px; height:320px; background:yellow;"</div></li>
    <li><div style="position:relative;width:100px; height:100px; background:yellow;"</div></li>
    <li><div style="position:relative;width:100px; height:100px; background:yellow;"</div></li>
    <li><div style="position:relative;width:100px; height:100px; background:yellow;"</div></li>
</ul>


<style>
.galeria {
    padding-right: 1em;
    text-align: center;
}

.galeria li {
    padding-left: 0.1em;
    padding-right: 0.1em;
    box-sizing: border-box;
    display: inline-block;
    width: 20%;
}
</style>

• A hint already serves ;)

1 answer

0

The element <li> the way you graduated with display:inline-block can receive the property vertical-align, then just put vertical-align:top that it will align to the top and not the base of the higher brother. To keep the space between the top element and the bottom line you can use a padding-top as in the code below.

inserir a descrição da imagem aqui

body {
    background: black;
}

.galeria {
    padding-right: 1em;
    text-align: center;
}

.galeria li {
    padding-left: 0.1em;
    padding-right: 0.1em;
    box-sizing: border-box;
    display: inline-block;
    width: 20%;
    vertical-align: top;
padding-top: 10px;
}

  • Got it! I’m ashamed of my stupid questions. Thanks for the example in response, when the blocks leave the sequence of a passing line to another is uneven. I tried other shapes using float and clear but could not. Is there any gimmick I can share? When I say uneven I mean not next to each other in a say 3px space.

  • @Jonathan has simpler ways to treat this with display:flex that is what I point out, or in your case just put a padding-top as I said in the items that will stand on the second bottom line after the first 4. If you have any questions on how to make this example with flex just open another question asking for help with this. If this answer solved the problem consider marking it as accepted in this icon beside the answer arrows ✔

Browser other questions tagged

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