Because when I write in the div she changes position?

Asked

Viewed 228 times

5

I write something in one of the <div> and it changes position. Because?

Here this happening: http://codepen.io/anon/pen/JHIjB

HTML:

<div class = "wrap1">
   <div>algo</div>
   <div></div>
   <div></div>
   <div></div>
</div>

CSS:

*{
  box-sizing: border-box;
}
body,html{
   height:100%;
   margin:0;
   padding:0;
}
.wrap1{
   min-height:100%; 
   background: #e1e1e1;
}
.wrap1 div{
   min-width: 45%;
   height:300px;
   min-height:50%;
   margin: 10px;
   display:inline-block;
   padding: 10px;
   border: 1px solid black;
   background: #b0bec5;
   position:relative;
}
  • why I don’t know, since I don’t handle CSS, but by adding a position:Bsolute interestingly worked here, look at this patch I made: http://codepen.io/anon/pen/AmaDd

  • Please put your code here. If codepen disappears the question will not make sense.

1 answer

3


Now that I understand your question I’ll explain to you:

First this happens because of the inline-block, it behaves according to the contents of the page. Try adding content outside the DIV and you will understand this. Example below:

display:inline-block;

<div class = "wrap1">
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
</div> 

According to inline-block is different from block, the block behaves by placing one above the other. The inline-block is very specific for this, adjust as all the content gives page, if not, in the same line.

In practice we use the inline-block value when we want to define a value for the width property. Under certain circumstances, some browsers ignore the property width for elements inline, then setting display: inline-block for such elements you will force the browser to recognize the value set for the property width.

  • 1

    The question is why this happens and not the way to solve.

  • You got it @Jorgeb.?

  • 1

    +1 for editing for new answer.

  • +1 for +1 :P!!

  • Hey Jorge will not put with certain answer?... I think it will not be very different other answers. : D

  • 2

    Mario asked the question, not @Jorgeb. Only Mario can mark the answer as accepted. He may be waiting to see if other answers appear, or he may not know how to mark the answer as accepted. Mario: if you are reading this, see http://meta.pt.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-reply/

  • Valeu @bfavaretto!

  • I marked it as accepted, so it seems to be a feature of inline-block when I fill all the boxes this problem should disappear, although I find it strange I already know it is something of that display. Thanks!

Show 3 more comments

Browser other questions tagged

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