Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Simple position not as expected
Old 04-09-2009, 05:49 AM Simple position not as expected
Novice Talker

Posts: 11
Name: Bernard Sunderland
Trades: 0
Could someone please explain to me why, in the sample which follows, the top border of the <P> box is not adjacent to the top border of the <DIV> box, as is the case for the left border?

<HTML>
<HEAD>
<STYLE type="text/css">
div {
position: absolute;
top: 0px;
left: 0px;
width: 200px;
height: 200px;
border: thin solid #000000;
}
p {
position: absolute;
top: 0px;
left: 0px;
width: 100px;
height: 100px;
border: thin dashed #ff0000;
}

</STYLE>
</HEAD>

<BODY>
<DIV>
<P></P>
</DIV>

</BODY>
</HTML>
BernardS is offline
Reply With Quote
View Public Profile Visit BernardS's homepage!
 
 
Register now for full access!
Old 04-09-2009, 10:26 AM Re: Simple position not as expected
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
if you add
* {
margin:0;
padding:0;
}
it will reset those to start on even ground.

Here is an article about a popular CSS reset technique:
http://meyerweb.com/eric/thoughts/20...eset-reloaded/
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 04-09-2009, 10:41 AM Re: Simple position not as expected
LadynRed's Avatar
Defies a Status

Posts: 10,016
Location: Tennessee
Trades: 0
CSS reset is good, but using the * for everything can cause problems, I would suggest a modification of Eric's reset to clear margins and paddin

Why are you absolutely positioning a PARAGRAPH ??? Why would you take text completely out of the document flow ?? When you do that, it is completely 'divorced' from everything else in the document.

For that matter, the absolute on the div likely isn't necessary either. Better to use the normal document flow and then use floats to put things where you want them. Use positioning only when absolutely necessary.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 04-09-2009, 11:13 AM Re: Simple position not as expected
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Oops, thanks for mentioning LadynRed, I probably should have noted that * for everything was not was I was suggesting being used for the actual site. I was just trying to show how resetting would help in this example.
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 04-09-2009, 12:42 PM Re: Simple position not as expected
Novice Talker

Posts: 11
Name: Bernard Sunderland
Trades: 0
Ok, if I scrub the position and let them remain in normal flow, the resultant appearance is the same.
If I add to the para 'margin: 0px;' then it does indeed shift to the top edge of the DIV. So it appears that the para has a top margin by default. Is this correct? It seems very strange.
BernardS is offline
Reply With Quote
View Public Profile Visit BernardS's homepage!
 
Old 04-09-2009, 12:55 PM Re: Simple position not as expected
LadynRed's Avatar
Defies a Status

Posts: 10,016
Location: Tennessee
Trades: 0
It's not strange. I believe that ALL elements have default margins and padding applied, which is why it's good practice to zero it out from the very start. This is what I use as a typical reset:

Quote:
body, p, hr, img, address, h1, h2, h3, h4, a, ul, ol, li, form, #container, #wrapper, #header, #addressBlock, #nav, #sidebar, #content{
margin: 0;
padding: 0;
}
Those are the most common html elements I use, as well as the most common IDs that I use. I may add things to that reset as I build my structure. As I build in my CSS, I add back in the margins and padding that *I* want for the design.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Last edited by LadynRed; 04-09-2009 at 03:35 PM..
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 04-09-2009, 03:31 PM Re: Simple position not as expected
Novice Talker

Posts: 11
Name: Bernard Sunderland
Trades: 0
That's the complete answer, thank you.
It is easy to fall foul of these little complications for a long time before realising that they exist.
BernardS is offline
Reply With Quote
View Public Profile Visit BernardS's homepage!
 
Reply     « Reply to Simple position not as expected
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26655 seconds with 12 queries