Bender Bender - 1 year ago 75
CSS Question

Why button is overlapping with div?

I have a main wrapper div with a content div and a button. The button is supposed to go underneath the content div but for some reason it's overlapping with it.

The content div has css:

#groupMembers {
position: absolute;
height: 50%;
width: 90%;
left: 5%;
overflow: scroll;
display: inline-block;

and the button has:

button {
display: inline-block;
width: 70%;
left: 15%;

I thought since they're both inline-block that they wouldn't overlap, but for some reason they are. I made a JsFiddle to show:

Can anybody help me get the button to display beneath the content div?

Answer Source

Remove the (extensive) use of absolute positioning.... Change it to position: relative; if necessary. But on many elements even that is not necessary.

Move the button div up to under the <h4>add members</h4> in the HTML where you appear to want it.

Then adjust margins for #DIV_05 and the button.

Fiddle Update or Fiddle Update 2

(Note I merely performed a search to change absolute to relative in your CSS, then adjusted from there.)

By using absolute positioning so extensively you were forcing elements into unnatural positions. Then when it wasn't working out.. you are left wondering why. Let things fall where they naturally want to fall. Change the HTML for overall render order, don't force things with absolute positioning.

Use of absolute position is most commonly used to adjust z-index and make elements not alter positioning of other elements. (like a global float of sorts) It should not be the fall back for positioning everything in any layout.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download