Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Position a div layer relevant to an object

  1. #1
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Position a div layer relevant to an object

    Hi peeps,
    I have a query regarding positioning of a DIV on a page whic is never the same size.
    Right, let me explain.
    I want to place a div layer over a background image, Hypothetically lets say i have the page background set as country scene with a timy lake in the middle. Now i want to place a div layer with a duck postioned exactly over the pond.

    Now 99% of the time this is easy with the absolute or relative div position. but is it posible say to position it from say the corner of my background image rather than the viewers browser edges. Let me try to explain better, If my page has the country background and then i place a table for example that covers the whole page, say 100% wide by 100% high, can i in any way position my div layer relevant to the top left of the table? and not the browser?
    Hope i explained that clear, If i wasn't at work i would upload some code and the issue in full.
    If anyone understands what i am trying to do i would apreciate any advice.

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Understand that this link is for a CSS menu. but the effect is I believe similar to what you are after. The CSS used is in the source code.

    It might give you an idea about using top/left and transparency there.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default not sure about that one

    Just had a quick look at that and not sure that will do it. I need to be able to place a dic layer in a specific place WITHOUT using the left and top coordinates.Ie top:50px left:50pk.
    what would perfectly is if i could name the top cell in a table and then postion my div layer with co-ordinates from that named cell.
    I'll post my whole problem up with links etc later today, as it's it a bit hard to explain why i would need this without demo.
    cheers

  4. #4
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Talking

    I think the solusion the Professor suggested would answer your problem.

    Another thing I think, and forgive me if I'm wrong, you perhaps haven't understood that left and top values don't always relate to the window.

    If objects are absolutely positioned within a relatively positioned div for example, top:0; left:0; would position the objects in the top left of the containing div (not the top left of the window).

    Check out this example.

    HTML Code:
    <html>
    <head>
    <style type="text/css">
    
    body {
    	text-align: center;
    }
    
    #pond {
    	background: blue;
    	width: 300px;
    	height: 200px;
    	margin: 100px auto;
    	position: relative;
    }
    
    #duck {
    	background: yellow;
    	width: 50px;
    	height: 50px;
    	position: absolute;
    	top: 20px;
    	left: 80px;
    }
    
    </style>
    
    
    </head>
    <body>
    
    <div id="pond">
    	<div id="duck"></div>
    </div>
    
    
    </body>
    </html>
    I hope this helps.


  5. #5
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Dog, Thanks for the reply, plase forgive me, I am from the old school of programming HTMl in notepad and have only really started switching onto to CSS.
    I will have a play with your example this afternoon when i get home and if i can't work it will post the whole thing here.
    Cheers

  6. #6
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Hobsonschoice View Post
    Hi Dog, Thanks for the reply
    No problem man. I always like it when I find a thread I can actually help with.

    plase forgive me, I am from the old school of programming HTMl in notepad and have only really started switching onto to CSS.
    Cool! No reason you can't carry on in Notepad.

    Good luck and have fun!

  7. #7
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Here is the full problem

    Here ya go, this should explain the problem.
    I have a fixed background image which i would like to keep fixed so that i can scroll text over it.
    Now i have placed your yellow box to represent a cocnut so to speak against the tree,
    If i scroll the cocnut moves, i want the cocnut to keep its place.

    The finished product should work when posted into an ebay style template here.
    http://auctionsupplies.com/practice/ebay.shtml

    Here is your adjsuted code.

    <html>
    <head>
    <style type="text/css">

    body {
    background-attachment:fixed;
    margin-top:0;
    margin-bottom:0;
    margin-left:0;margin-right:0;
    background-image:url("http://www.anisites.com/crusoe/images/beach4.jpg");
    }

    #pond {
    background: ;
    width: 300px;
    height: 500px;
    margin: 10px auto;
    position: relative;
    }

    #duck {
    background: yellow;
    width: 10px;
    height: 10px;
    position: absolute;
    top: 300px;
    left: 900px;
    }

    </style>


    </head>
    <body>

    <div id="pond">
    <div id="duck"></div>
    </div>


    </body>
    </html>

  8. #8
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default blimey

    How can one man spell coconut so consistently wrong

  9. #9
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Try giving the duck/coconut a fixed position rather than an absolute position.

    This works for Firefox but not IE.

    I can't seem to find a solusion to use in IE as it doesn't seem to respond to fixed or static positioning.

    good luck!

  10. #10
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Have been skiving a bit

    Boss is away so had a play.

    Here is the challenge.

    <html>
    <head>
    <style type="text/css">

    body {
    background-attachment:fixed;
    margin-top:0;
    margin-bottom:0;
    margin-left:0;margin-right:0;
    background-image:url("http://www.anisites.com/crusoe/images/beach4.jpg");
    }

    }

    #nut {
    background: yellow;
    width: 10px;
    height: 10px;
    position: absolute;
    top: 300px;
    left: 900px;
    }

    </style>


    </head>
    <body>

    <div id="pond">
    <div id="nut"><img src="http://www.greentales.com/files/coconut.jpg" width=80 height=40></div>
    </div>

    <table width=400 border=2><h1>

    <tr><td>

    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>

    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>
    This is the challenge. The text should scroll over the fixed background,Whikle the coconut stays in place on the tree

    withoutscrolling. This must be done only with Css and there should be no openeing html tag or body tag as ebay strip them

    when loading.<p><p>


    </td></tr>
    </table>

    </body>
    </html>

Bookmarks

Posting Permissions

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