i was wondering if anybody knew of a tutorial or guide on how the child/parent work i开发者_运维知识库n css in terms of positioning ?. I'm trying to position a div element 50 px away from another element of the same kind but i can't get it to work.
//Thx in advance.
The official docs are pretty good:
First you'll have to learn the basics of the box model:
http://www.w3.org/TR/CSS2/box.html
Then you can see what are the possibilities for visual formatting:
http://www.w3.org/TR/CSS2/visuren.html
To use CSS for layout, you should be familiar with the box model.
A List Apart is also a good read on this subject.
As for your particular situation, please be more specific.
CSS Mastery by Andy Budd is a pretty good book I recommend everyone to check out. You should grab it if you want more than a casual understanding, Otherwise, if you google "CSS tutorial" you'll get a million hits.
A great new book called the CSS Detective is awesome. One sentence explanations with code examples of all the general problems with positioning, floats etc and then, there are four/five case studies with all the code for you to look and figure what's wrong all before the explanations.
Now, as to your issue, are you using positioning at all or just floats? Though floats were not intended for layout, they've become a huge tool for just that but there are caveats just as there are for other.
A child will inherit its parents properties unless overridden.
Sounds like if you're using floats, you would float the item left/right and stick a margin-left or right of 50px. If absolute positioned, then just check the onscreen coordinates and use left: and top: with px as to where to put it.
Obviously, you have to have a parent or container with position:relative which wraps the element you position absolutely as that is the item the element/child will get positioned against.
Relative establishes a positioning concept/target. But, it's 'relative' to its own position within the document flow.
精彩评论