Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ilias Loukakis
20,489 PointsPositioning Question
Hello there,
I'm just running on an issue I can't really understand.
I have a simple html structure:
<section> <div> that is a div example <p> this is a p example </p> </div> </section>
and I try to position these elements relatively, so on my css I have:
div { position: relative; top: 25%; left: 25%; }
p { position: relative; top: 25%; right: 25%; }
I thought that paragraph will be relative to div (as p is inside the div, div is the parent right?) but it seems that p is relative to the section...Any ideas?
Thanks in advance
6 Answers
Adam Moore
21,956 PointsRelative positioning is used to move the element a certain distance from its original position. For instance, if your "div" would normally be at the top left of the section, and you give it a 25% left and top relative positioning, then it will move 25% from the left and 25% from the top within its parent element. If you then place a paragraph element within that relatively positioned "div," then if you position the "p" element relatively 25% from the left and the top, then the "p" element will move from the left and top of its parent "div."
It sounds like this is what you had expected to happen, so if something else is occurring, there may be something else wrong in the code.
Scott Moore
4,050 PointsHello, take off the % sign If your using the position function.
Ilias Loukakis
20,489 PointsExactly Adam, I was expecting that but for some reason, the paragraph's parent element is the section and not the div that it is in, I can't really find the reason to be honest...
Adam Moore
21,956 PointsThe only thing that I can think of is that there would be some other part of the code that would be throwing off the alignment of those two divs. Is everything nested properly?
Ilias Loukakis
20,489 PointsIt seems that another value I gave destroyed the alignment :) now it works properly, thanks!
Adam Moore
21,956 PointsAwesome! :)
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsCan you repost your html showing the
section,div, andpusing code blocks? The html is stripped out when you paste it into the text box.https://teamtreehouse.com/forum/posting-code-to-the-forum