Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: How to make a div block *not* take space in its parent container

If I have 2 div tags:

<div id="parentDiv">
   <div id="childDiv"><!-- other html --></div>
   <!-- parent div html -->
</div>

I want the content of <div id="childDiv"> to overlap the content <!-- parent div html -->.

Reason (in case this looks like bad code design to anyone): I need a hack workaround in google sites, I cannot add custom code on the sidebar nav, only in the main html space, I want to float a div that takes no space and relatively position it over the side bar to get around the forced limitation.

I can do everything except stop the childDiv from taking up space in it's bastardized main-page container.

like image 399
David Parks Avatar asked Mar 28 '12 14:03

David Parks


People also ask

How do I make DIVS not take up space?

You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).

How do I make a div take the width of its content?

Using inline-block property: Use display: inline-block property to set a div size according to its content.

How do I make div fit to parent div?

If you want the child divs to fit the parent size, you should put a margin at least of the size of the child borders on the child divs ( child. margin >= child. bordersize ).


2 Answers

You can give it a position absolute, and navigate it with margins.


    #childDiv {
      position: absolute;
      margin-top: -100px;
      margin-left: -100px;
    }

like image 188
S.Visser Avatar answered Sep 19 '22 07:09

S.Visser


How about a simple

#childDiv {height:0; overflow:visible;}

But you probably want it to have a background colour, hm? Hm.

like image 45
Mr Lister Avatar answered Sep 18 '22 07:09

Mr Lister