-1

I need to expand parent div by child div, please look at this code:

HTML

<div class="wrapper">
    <header class="header"> </header>
    <div class="middle">
            <div class="container">
                    <main class="content">
                            <div id="child">
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            <p>1</p>
                            </div>
                    </main>
            </div>
            <aside class="left-sidebar"></aside>
    </div>
    <footer class="footer"></footer>
</div>

CSS

.wrapper {
    width: 500px;
    margin: 0 auto;
    min-height: 100%;
}
.header {
    height: 100px;
    background: blue;
}
.footer {
    height: 60px;
    width: 100%;
    bottom: 0;
    position: relative;
    background:yellow;
    clear:left;
}
.middle {
    width: 100%;
    min-height: 300px;
    position: relative;
}
.container {
    min-height: 300px;
    width: 100%;
    float: left;
}
.content {
    width: 800;
    min-height: 300px;
    left: 280;
    position: relative;
    background:red;
    padding:10px;
}
#child {
    position:relative; 
    top:100px;
    left:160px;
    min-height:500px;
    width: 200px;
    border: solid 1px white;
    background:green;
}
.left-sidebar {
    float: left;
    width: 100px;
    min-height: 500px;
    margin-left: -100%;
    position: relative;
    background:  black;
}

DEMO: JSFIDDLE

the problem is that main.content is not fully expanded by #child vertically on the value of "top:200" that is in #child relative positioning properties, how can I fix it? because it currently overlaps the footer.

swserg
  • 692
  • 1
  • 5
  • 18

2 Answers2

3

Actualy, when ou apply the "top" property with position: relative, it doesn't interfeer on the other elements of the page. so it will just overlap the parent div. Try using margin-top instead:

#child {
    margin-top: 200px;
    left:60;
    min-height:500;
    border: solid 1px white;
}
LcSalazar
  • 16,524
  • 3
  • 37
  • 69
  • unfortunately, this doesn't work either, please take a look at the fiddle http://jsfiddle.net/ac6s7/14/ – swserg Feb 19 '14 at 06:54
  • What exactly doesn't work with this answer? If I understand your problem correctly you want the main div to expand if the child gets larger. Well, if you use margin-top instead of top it'll do exactly this. See: http://jsfiddle.net/ac6s7/23/ – berentrom Feb 19 '14 at 07:55
  • Yes, just one correction on my original answer, I forgot about your left positioning. When you remove the "position:relative" property, the left will stop working. So you may either put the position relative back, or you can use "margin-left". – LcSalazar Feb 19 '14 at 12:31
  • @berentrom you are looking at the last revision, I did some test, please start with 14 revision: `jsfiddle.net/ac6s7/14` and you will see my original problem – swserg Feb 19 '14 at 15:23
  • I am not understand your problem at all then I guess. If I change .child { top: 100; } to .child { margin-top: 100px; } the parent expands with it. – berentrom Feb 19 '14 at 16:00
  • @berentrom is right. I also tried it in your 14th revision on jsfiddle, it works as expected. – LcSalazar Feb 19 '14 at 16:09
  • ok guys, setting `margin-top` instead of `top` for child and `overflow: auto;` for parent `.content` fixed 1st issue, so now only left-bar needs to be expanded to footer. – swserg Feb 19 '14 at 16:13
1

You need to clear:left; on the footer.

    .footer {
    clear:left;
}

http://jsfiddle.net/ac6s7/

Marcel
  • 375
  • 1
  • 8
  • thanks, I corrected the fiddle and now you can see the problem: http://jsfiddle.net/ac6s7/14/ #child is behind the footer, and left bar is not expanded to that footer. – swserg Feb 19 '14 at 06:50