A
A
amidart2012-04-27 20:58:46
css
amidart, 2012-04-27 20:58:46

Why is the div being cut off?

It seems to me that the question is elementary, I just do not know some basics. Please explain the behaviour.
Here is the simplest html code:

  <div id="aa">
    <div id="bb">bb</div>
  </div>

with this style:
    #aa {background-color: #555; border: solid 2px red;}
    #bb {background-color: #ccc; height: 100px; width: 50%; margin: 50px;}


If the #aa block has a frame, then I see the following result (I expect this result):


If the frame is removed, then part of the block disappears somewhere (cut to the height of the nested block):


This happens in all browsers, so this standard.
The same effect will be if applied to #aaa property paddingor enter some text.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stdit, 2012-04-27
@Stdit

Block bb states that any block must be at least 50 pixels away from it. This does not apply to the parent block. For padding from the parent block boundaries, the parent must have padding jsfiddle.net/JyHCd/ or the parent block must limit the interaction of nested blocks beyond its borders (overflow jsfiddle.net/JyHCd/1/ ). In some specific cases, this option is also acceptable: jsfiddle.net/JyHCd/2/

N
Nesvet, 2012-04-27
@Nesvet

There is such a thing.
Use overflow: autofor outdoor unit.

N
nikel303, 2012-04-28
@nikel303

Also, as an option, you can add indents to the parent element, for example:

padding: 1px 0;

And for the inner element, make the alignment 1px smaller, for example:
margin: 49px 50px;

E
egorinsk, 2012-04-29
@egorinsk

This is how it should be - www.w3.org/TR/CSS21/box.html#collapsing-margins . Everything would be fine, but in Ie6-7, depending on the haslayout of the inner / outer blocks, this effect behaves completely differently, so you need to get rid of it. Replace margin with padding OR Add 1px top and bottom padding to the outer box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question