Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    div to height other than parent

    I'm just wondering if, short of javascript, anybody knows a way to get a div to break its parent div's height when the parent is set to 0. I set divs to 0 so I can position things without pushing down parts of a page structure. Then I set a div inside. This works fine, if the child div is set to a specific height. But what about when I want that div to be set to a percentage of page height or something.

    This is a simple representation of what I'm talking about. Any thoughts, or work arounds?

    Code:
    <div id="body" style="height:600px;">
       <div id="zerodiv" style="height:0px;">
          <div id="targetdiv" style="">
             This is the div I'm not sure how to get to break its parent height, without javascript or specific height.
          </div>
       </div>
       <div id="extracontent"> 
             This is the content I don't want pushed down by the zerodiv
       </div>
    </div>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    Get rid of all the height:0 as that is NOT the way to position things and as you can see it makes it impossible to size the content properly.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    I can see that now. Any suggestions how to have the div not affect the position of other blocks on the page, without using absolute?

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello turpentyne,
    If you want to stack div elements on top of each other maybe using z-index is what you need, that would stop an element from pushing the one below it out of the way. It would go over it instead, or under it depending on your stacking order.

    Have a quick look at this tutorial on z-index.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • Users who have thanked Excavator for this post:

    turpentyne (12-16-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •