School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,148 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,705 people online right now. Registration is fast and FREE... Join Now!




positioning a fixed element to the right of centered parent

 

positioning a fixed element to the right of centered parent, I did this, but I don't understand how...

Chepoll

3 Nov, 2009 - 10:15 AM
Post #1

D.I.C Head
**

Joined: 27 Feb, 2009
Posts: 67



Thanked: 5 times
My Contributions
Hello people,

Here was what I'm trying to do:
Wrapper is centered.
I want to place rightBox, inside Wrapper, and at the right.

Here is how I did it
(below is not the code, just a design)
CODE

Wrapper
{
     _pos:relative
     _CENTERED horizontaly

     _width:700
}
rightBox
{
     _pos: fixed
     _CENTERED horizontally

     _width:150

     _left:550
     _right:0
}


So, how come this works?

User is offlineProfile CardPM
+Quote Post


calebj

RE: Positioning A Fixed Element To The Right Of Centered Parent

3 Nov, 2009 - 02:59 PM
Post #2

D.I.C Regular
Group Icon

Joined: 28 Feb, 2009
Posts: 335



Thanked: 19 times
Dream Kudos: 200
My Contributions
This works because you have the box fixed a certain distance from the left side of the container, it forces the box to stay 550 pixels from the left. You could also do this by just having a float right and declaring box widths and setting a margin of 0 or you could just set a margin of auto 0 for the container and then margin left like you are doing with no positioning.
User is offlineProfile CardPM
+Quote Post

Chepoll

RE: Positioning A Fixed Element To The Right Of Centered Parent

4 Nov, 2009 - 01:16 PM
Post #3

D.I.C Head
**

Joined: 27 Feb, 2009
Posts: 67



Thanked: 5 times
My Contributions
I don't still get the logic behind it.

Now, I tell it to center it.
It does so.
I tell it to leave 550px space to the left of this box.
I think what it does here is that, it considers this thing as a 550+150 px. wide box, and centers it.
I apparently got something wrong of things I said up to here, because, unless I say "right:0", it will not work; when I think it should.

I'm sorry that I'm causing trouble, guys. I'm a little thick-headed, so it takes quite some time for knowledge to difuse into my brain. But, once it does so, I will remember it for a loong.. time.
User is offlineProfile CardPM
+Quote Post

calebj

RE: Positioning A Fixed Element To The Right Of Centered Parent

4 Nov, 2009 - 02:19 PM
Post #4

D.I.C Regular
Group Icon

Joined: 28 Feb, 2009
Posts: 335



Thanked: 19 times
Dream Kudos: 200
My Contributions
Just to clarify, You are trying to make a sidebar inside of a container that sits to the right? What you could do is...

CODE

<div id="container">

<div id="content"></div>
<div id="sidebar"></div>

</div> /* This closes container*/


Notice how the content and sidebar are sitting inside of a container. The container has not yet been assigned a set width, we will be doing this with the following code. If the contents that are inside of the container div (div content and div sidebar) were to have widths that are to wide for the container to handle; they will drop down and forced to display under the other and not side by side.

When saying left is so many pixels it should be working for you. ie with the above code

CODE

#container {
margin: 0 auto;
width: 700px;
}
#content {
margin: 0 200px 0 0;
}
#sidebar {
width:200px;
float: right
}


This CSS code will leave you with 500px of room to work with. This is because you take the container value which is 700 subtract 200 and then you are left with 500 pixels. The sidebar floats to the right and has a declared width so the browser knows what to do with the rest of the page.
User is offlineProfile CardPM
+Quote Post

Chepoll

RE: Positioning A Fixed Element To The Right Of Centered Parent

5 Nov, 2009 - 04:40 AM
Post #5

D.I.C Head
**

Joined: 27 Feb, 2009
Posts: 67



Thanked: 5 times
My Contributions
I get it now.
Thanks.

And, yes, to sit a sidebar inside a wrapper/container was what I was trying to accomplish. I wanted the sidebar to be fixed, so that It would be easy to access, no matter where you have scrolled, inside the page.

Thanks, again.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:07PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month