Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-18-2012, 09:34 PM   PM User | #1
freshdude
New Coder

 
Join Date: May 2011
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
freshdude is an unknown quantity at this point
CSS Positioning with Margins

I have my whole site set up to be centered with all elements (position:absolute within this one div:

#website {
position:relative;
margin:0 auto;
width:960px;

How do I add a <div> with a fixed position (stays in the same left and top position as you scroll down) that will be relative to the centered site?

I tried position:fixed; but it just ignores the margins and a left:60px; is always 60px from the left, no matter how wide the browser window.
freshdude is offline   Reply With Quote
Old 11-19-2012, 02:41 AM   PM User | #2
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
It sounds like you should be using position: absolute, which respects the containing block you put it in, but removes that box from the flow. I'm assuming here that you're wanting to place this box outside the main div (You would place it inside the main div in the code, but position it outside with styling). Using position: fixed is generally only relative to the viewport. I don't understand why you would be using position: absolute on all elements inside your centering div.
Custard7A is offline   Reply With Quote
Old 11-19-2012, 04:17 AM   PM User | #3
freshdude
New Coder

 
Join Date: May 2011
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
freshdude is an unknown quantity at this point
I used "position: absolute" for the elements in the centering <div> so that they would disappear as I scrolled down on the site.

I want a new <div> to be within the centering <div>, but I want it fixed at 60px from the top and 60px from the left of the 960px centering <div> the whole time I scroll down.

I found margin-left:60px works with position:fixed; but I wondered if there was a better way.
freshdude is offline   Reply With Quote
Old 11-19-2012, 01:14 PM   PM User | #4
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
If your elements in the centering div aren't scrolling away as one would expect from scrolling — when you are using the default positioning that is — then you must be doing something quite unusual to me.

If you have it working as you want with fixed positioning, then I would say it seems fine to do so. There may be a better way, but using position: absolute on all your centered elements doesn't seem like the best way to do that either.
Custard7A is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:46 AM.


Advertisement
Log in to turn off these ads.