2 replies [Last post]
sohrabx
Offline
newbie
Last seen: 16 years 17 weeks ago
Joined: 2003-08-19
Posts: 6
Points: 0

Hello, my question is related to the positionning of content in an HTML file that is linked to an external CSS file.

Now, I've been going over this and I've come to this conclusion, I want to know if this methedoloy is correct, common practice or "whow, no no, what are you doing"

let's say this is my html: (I'm leaving stuff out for the sake of being brief)

<html>
<head>
<link href="test.css" rel="stylesheet" type="text/css">
</head>

<body>
<div>
<p>
BLAH BLAH BLAH BLAH BLAH
BLAH BLAH BLAH BLAH BLAH
</p>
</div>
</body>
</html>

Now, let's say that my css file contains formatting rules for my <p>
p {
background-color: #00FF99;
border: 2px solid black;
padding: 5px;
}

Now, I've formatted my <p> however, it will just appear in my html docutment in it's default location.
If I want to position this: IS IT PROPER PRACTICE TO ---> use the <div> as the container for my <p> to which I will assign a #ID with absolute positioning? such as:

#main {
position:absolute;
left:65px;
top:45px;
width:263px;
height:176px;
z-index:1;
}

And then I apply the #main to the <div>: <div id="main">

and this way I keep positioning and formatting seperate.

Is this proper practice or not? I hoe I was clear enough here
Thank you very much for all of your help
-Sohrab

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 5 days 11 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

css positioning

Hi sohrabx,
It's fine to use a container div to position your paragraph.

The choice is usually made depending on other elements of the page.
If you have only on paragraph it may be simpler to position that without a container.
More likely you will have a few paragraphs so using a containing div will simplify positioning.

P and div are both block elements, p should not have any other block elements inside of it, where a div can contain other block elements.

Hope that helps

sohrabx
Offline
newbie
Last seen: 16 years 17 weeks ago
Joined: 2003-08-19
Posts: 6
Points: 0

Tony! Thank you very much! :)

Hi Tony, thank you so much, ya know it's funny, I've been rattling my brain over this for the longest time, and for some reason, I suppose due to my own fault, but I could not find anything on the web that directly addressed that question,

Than you very much for your post, it was most appreciated! Smile

-Sohrab