positioning of float elements without spacing

Asked

Viewed 291 times

1

I have long been trying to solve this problem. whenever I create a site using div’s that are float I have the problem of leaving a blank space after the 1st div in the line break as in the example here:

http://jsfiddle.net/qxbxntvc/

wanted to know how I do so that there is no white space between the red div and the rose?

  • Would changing the position of the elements not help? http://jsfiddle.net/qxbxntvc/3/ Or using clear Both na div azul: http://jsfiddle.net/qxbxntvc/2/

3 answers

2

I can not work with a grid system where the sum of all width exceeds 100%, in the case of your example the total of div gives 200%.

In this case I would use nested div

div.column
{
    width:50%;
    float:left
}
#a{height:50px;background:red}
#b{height:20px;background:green}
#c{height:60px;background:blue}
#d{height:40px;background:pink}
<div class="column">
    <div id="a">
        
    </div>
    <div id="c">
        
    </div>
</div>
<div class="column">
    <div id="b">
        
    </div>
    <div id="d">
        
    </div>
<div>

  • the sum does not exceed 100% because when you define a DIV as a float within a defined space, HTML understands that when the div is larger it must reposition it to the next block. For example, see how the Responsive Content technique works on websites...

-1

The question is in the size of the div.

Pay attention that the blue div has 60px; And the rose starts soon after the same with a smaller number. In other words the problem there is the size of them.

To solve this problem you would have to do so:

#c{height:60px;background:blue; float: right;}
  • your solution does not solve the problem... I know that the blue div has 60px, the issue is that even if the existing div on the left is larger, the following would have to adjust on the right, this is what I want as with the site Pinterest

  • 2

    @Leandroluk only that in Pinterest he uses a guy called masonry there is a logic there, it is not only with the float that solves the positioning.

  • I don’t agree with the negative as it solved. @Leandroluk take a look at the flex display shape. http://www.w3schools.com/cssref/css3_pr_flex-flow.asp and a few examples http://www.w3schools.com/cssref/playit.asp?filename=playcss_flex-flow

  • @Edmo, as his blocks have a proposed screen size, then he will always have the same number of columns, in this way it is possible to achieve the same result of Pinterest using only Divs.

  • @Tobymosque good! If it’s always the same number, you’re absolutely right.

-2


I had this problem and I managed to solve it like this:

body {
  width: 1048px;
  height: auto;
  background: center, no-repeat;
  background-size: cover;
  background-color: #8E24AA;
}


/*COLUNA 1 E TEXTO*/

.column1 {
  width: 500px;
  height: 350px;
  background: #F3E5F5;
  float: left;
}


/*COLUNA E TEXTO 2*/

.column2 {
  width: 500px;
  height: 350px;
  background: #E1BEE7;
  float: right;
}


/*CONTEINER COM AS COLUNAS*/

.content {
  content: "column";
  display: table;
  clear: both;
}
<div class="content">
  <div class="column1 column">
    <h1>TESTING TESTING</h1>
  </div>
  <div class="column2 column">
    <h2>TESTING TESTING</h2>
  </div>
</div>

Browser other questions tagged

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