Move div down

Asked

Viewed 6,089 times

2

I have 4 Ivs on my page, next to each other, as I can do, so that the last div is aligned left on the bottom line ?

inserir a descrição da imagem aqui

My Code:

     <!-- DIV 1 -->
     <div style="float: left; width: 100px; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">1</div>

     <!-- DIV 2 -->
     <div style="float: left; width: 100px; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">2</div>

     <!-- DIV 3 -->
     <div style="float: left; width: 100px; height: 100px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">3</div>

     <!-- DIV 4 -->
     <div style="float: left; width: 100px; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; clear: Left; border-color: #FFFFFF;">4</div>

     <!-- DIV 5 -->
     <div style="float: left; width: 100px; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">5</div>

As it was after inserting the clear:left.

inserir a descrição da imagem aqui

Problem 2 - After using ( clear:left ).

Another problem arose, I need to fit the div’s as per the image below, I want to do this using only CSS and without using the margin top, I need to do this using some pure CSS solution. The numbers within the DIV’s refer to the sequence in which the DIV’s are displayed by PHP coming from Mysql.

inserir a descrição da imagem aqui

Thank you

  • 1

    Is this what you’re looking for? -> https://jsfiddle.net/r7Lwtu6y/

  • Exactly, but I had a problem, as the div at the end is wider than the others, when she jumps in line, she’s not fitting in with the top one, there’s a space, what can I use ? I updated my topic.

  • Thanks for the tip.

1 answer

2


Good in css and html the elements relate, for this specific solution you can do as below, however it may be necessary to adapt, without the whole code I have no way to go beyond...

<div style="float: left; width: 100; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">1</div>
 <div style="float: left; width: 100; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">2</div>
 <div style="float: left;width: 100; height: 70px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">3</div>

  <!-- Fazer essa div abaixo se alinha a esquerda na linha de baixo -->     

 <div style="position:absolute; margin-top:55px; width: 100; height: 50px; background-color: #CCCCCC; border-style: solid; border-size: 1; border-color: #FFFFFF;">4</div>

Let’s try another way:

div
{
    float:left;  
    height:50px;
    width:100px;
    border: 1px solid #000000;
}
#id4
{
    clear:left;
}
#id3
{
   height:102px;
   margin-top:-52px;
}
<div>1</div>
<div>2</div>
<div  id="id4">4</div>
<div>5</div>
<div id="id3">3</div>

Or one more option where I define a width to the content and thus use the float:right, but it’s like I say every case is a case:

#content
{
    width: 306px;
    height: auto;
}
div
{
    float:left;  
    height:50px;
    width:100px;
    border: 1px solid #000000;
}
#id3
{
    float:right;
    height:102px;
}
<div id="content">
    <div>1</div>
    <div>2</div>
    <div id="id3">3</div>
    <div>4</div>
    <div>5</div>
</div>

  • I tested this code, but it didn’t work very well, for automated records coming from the database, would it be possible to do without using mar-gin-top ? something more automatic ?

  • Guy gets hard to say, without having the explicit problem, what I mean is :At first it was just play the div down (solve with the clear), ah but the last div is bigger,, and so it goes... With this shallow information you’ve passed on, there’s no going beyond that... And to tell the truth, the data of the bank in my view should not influence, because the front-end is the display of information, no matter what the information (roughly)... Then it would be important to edit and put more information, how your page intends to work...

  • Ready Magichat, already changed the topic and explains in detail what I wish. Thank you

  • Note that your code has 4 Divs and the visual example has 5...

  • Ready Magic Hat, I changed the code;

  • See if it gets better...

  • So, I noticed that the DIV 3 you played at the end, after the DIV 5, this will not work for me as the DIV’s are inserted in the page in the sequence.

  • Look now... heheh

  • wow, now it’s too much Oko the code, can you explain the logic ? I loved it.

  • Next, how I assign a width for the caontainer with the exact size of the Divs, when any exceeds the size it goes to the bottom block, and played the div3 right with the right float, if there was no container to delimit the width would all be on the same line and the div3 would stand to the right of the window... Note that in the container I counted with the edges...

  • Nice that it worked out... good luck man...

  • Man, thank you so much Magic Hat.

Show 7 more comments

Browser other questions tagged

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