Why does included files margin effect main file?

liunx

Guest
I have the margins for my body of my main index.php set up so that the top margin is 10px.
I have made a footer html page that will be included in the index.php. I set the body style in this html file so that margins were all 0px.
When I include the footer html file in the index.php it sets the margins of the index.php to 0px all round.

Does anyone know how I can include files that have 0px margins that won't effect the page it is being included into?

Brad.The last CSS instruction is what takes precedence.

There are several ways to fix it. You can define the CSS for the BODY after the include, or give your BODY tag an ID and assign CSS to the ID, or put the footer in a DIV and assign margins to that.Could you give me an example of what you mean? Sorry...I'm still fairly new to CSS.Post a link so I can see what you already have.Sorry Gil, I'm actually working on it locally on my pc and haven't uploaded this page. I'm trying to learn the fundamentals.

Define a tag for the body or define the CSS for the BODY after the include...which of these two methods is the most preferred?

I'm gathering if i define a body tag i'd declare it as:

body#formatting {
...
}

Then I would have something like:

<body>
<body id="formatting">
</body>
</body>

Is that right?No, you wouldn't want to have 2 <body> tags. The <div> tag is what'd be used here. Also, when styling things with id's (Note: an id cannot be used on two elements on a page), you can leave out the tag's name. For example:

body {margin: 0;}
#foo {color:red;}
#bar {color: blue;}
...
<body>
<div id="foo">This text will be red in CSS enabled browsers.</div>
<div id="bar">This text will be blue in CSS enabled browsers.</div>
</body>

Of course, that example is insanely simplistic, but, oh well. As for learning CSS, have you tried W3 Schools (<!-- m --><a class="postlink" href="http://www.w3schools.com/">http://www.w3schools.com/</a><!-- m -->) or Elizabeth Castro's HTML for the WWW 5th edition? They're both very good sources, especially Castro's book; very in depth and clear.Originally posted by omega
As for learning CSS, have you tried W3 Schools (<!-- m --><a class="postlink" href="http://www.w3schools.com/">http://www.w3schools.com/</a><!-- m -->) or Elizabeth Castro's HTML for the WWW 5th edition? They're both very good sources, especially Castro's book; very in depth and clear.

ive read w3schools along w/ many others for css but havent seen Elizabeth Castro's. I have a pretty good understanding of CSS now (i think at least ;P) but would always like to read more, i will most likely learn at least something else from it :P thx :)
 
Back
Top