Results 1 to 8 of 8

Thread: How to place a div over another div using css??

  1. #1
    Shark3y3s is offline x10Hosting Member
    Join Date
    Apr 2008
    Posts
    1

    How to place a div over another div using css??

    Hi,

    I've have a site coded with divs seperating each section of the webpage, my question is, is there a way i can float another div anywhere above the divs i already have on the page??? here's the following code for my new div i'm trying to float (overlap) the other divs...

    div#comments {
    position: absolute;
    left: 10px;
    top: 700px;
    width: 700px;
    height: 100px;
    z-index: 10;
    border: 1px solid;
    }

    it works fine for IE 7 and Firefox, but for IE6 it don't work and i don't see nothing for the div... Is there anyway i can fix this...

  2. #2
    MasterMax1313's Avatar
    MasterMax1313 is offline x10Hosting Member
    Join Date
    Oct 2007
    Posts
    84

    Re: How to place a div over another div using css??

    try adding

    visibility: visible;

    (sorry, but i don't have ie6, so i can't test this)
    If you found this helpful, don't be afraid to add to my rep
    ____________________________

    There are only 10 types of people in this world...

    Those who understand binary,
    And those who don't

  3. #3
    preetham is offline x10Hosting Member
    Join Date
    Mar 2008
    Posts
    16

    Re: How to place a div over another div using css??

    the border attribute passed is in correct.
    try this (added one more attribute to the css - float)
    div#comments {
    float:left;
    position: absolute;
    left: 10px;
    top: 700px;
    width: 700px;
    height: 100px;
    z-index: 1000;
    border: 1px solid #666666;
    }

  4. #4
    lordskid is offline x10Hosting Member
    Join Date
    Mar 2008
    Posts
    41

    Re: How to place a div over another div using css??

    try this :
    div#comments {
    position: absolute;
    left: 10px;
    top: 700px;
    width: 700px;
    height: 100px;
    z-index: 9;
    border: 1px solid;
    }

    div#hoverabovecomments {
    position: absolute;
    left: 10px;
    top: 700px;
    width: 700px;
    height: 100px;
    z-index: 10;
    border: 1px solid;
    background:transparent;
    }
    I'm not so sure if the z-index of the top div should be greater than the bottom one. make sure none of the two divs you want to overlap has the float:left or float:right attribute set.
    Edit:
    Quote Originally Posted by preetham View Post
    the border attribute passed is in correct.
    try this (added one more attribute to the css - float)
    div#comments {
    float:left;
    position: absolute;
    left: 10px;
    top: 700px;
    width: 700px;
    height: 100px;
    z-index: 1000;
    border: 1px solid #666666;
    }
    man if you float objects it will pile to the left or to the right and be as solid as can be... the border attribute is just fine.
    Last edited by lordskid; 05-15-2008 at 02:42 AM. Reason: Automerged Doublepost

  5. #5
    sybregunne is offline x10Hosting Member
    Join Date
    Feb 2008
    Posts
    54

    Re: How to place a div over another div using css??

    I don't know if this is what you need...

    try this and work from this.
    <head>
    <style>
    div#behind {
    position:absolute;
    top:20px;
    left:20px;
    width:100px;
    height:100px;
    }

    div#infront {
    position:absolute;
    top:25px;
    left:25px;
    width:90px;
    height:90px;
    }
    </style>
    </head>
    <body>
    <div id="behind">
    <p>I am behind another div</p>
    </div>
    <div id="infront">
    <p>I am in front of another div</p>
    </div>


    </body>

  6. #6
    preetham is offline x10Hosting Member
    Join Date
    Mar 2008
    Posts
    16

    Re: How to place a div over another div using css??

    Quote Originally Posted by lordskid View Post
    try this :


    I'm not so sure if the z-index of the top div should be greater than the bottom one. make sure none of the two divs you want to overlap has the float:left or float:right attribute set.
    Edit:


    man if you float objects it will pile to the left or to the right and be as solid as can be... the border attribute is just fine.
    If there are multiple divs in layout and the 'comments' div is somewhere in the middle then, applying float will make sure that the other div's beneath or over will not be effected with the position of the current div(as the requirement was to show the div over others with out effecting the layout). Position of the floating div can be set by changing the 'left' and 'top' attributes in css.

    #comments{
    float:left;
    position:absolute;
    top:50px;
    left:200px;
    width:500px;
    height:200px;
    border:1px solid #dddddd;
    background-color:#efefef;
    z-index:1000;
    }

    If you have used z-index for the previous div's(other than the floating div) then u need to specify z-index with greatest value of those which you have used for other div's.
    Last edited by preetham; 05-15-2008 at 09:05 PM.

  7. #7
    sybregunne is offline x10Hosting Member
    Join Date
    Feb 2008
    Posts
    54

    Re: How to place a div over another div using css??

    but by floating a div to the left doesn't that mean that the div will go to the left side of the browser regardless of its absolute position...

    I am not sure as I am just a hobbyist but I always try to use one type of positioning as much as possible.

    Then sometimes using a dtd will change the way an html code responds to a css...
    Edit:
    unless of course your floating div is inside another block element meaning it will float to the left most portion of your block element e.g. another div.

    Correct me if I am wrong... please...
    Last edited by sybregunne; 05-31-2008 at 02:41 AM. Reason: Automerged Doublepost

  8. #8
    xeross is offline x10Hosting Member
    Join Date
    Sep 2007
    Posts
    26

    Re: How to place a div over another div using css??

    Try making the Z-Index of the one that should be in front higher then the one in the back

Similar Threads

  1. Looking for affiliates (ads to place on my site)
    By gamerdude in forum Classifieds
    Replies: 1
    Last Post: 05-12-2008, 04:00 PM
  2. Cheapest place to buy domains?
    By Jacob in forum Scripts, 3rd Party Apps, and Programming
    Replies: 21
    Last Post: 04-15-2006, 10:21 AM
  3. Place ADS in Invision Power Board 2
    By michaelp in forum Tutorials
    Replies: 22
    Last Post: 09-04-2005, 09:40 AM

Posting Permissions

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