Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add space at the top of every page

Status
Not open for further replies.

idtstudios2

Programmer
Aug 12, 2005
35
0
0
US
I need to be able to add a 30px space/margin at the top of everypage that includes a javascript snippet and I need it to work with atleast firefox, opera, and IE. Since this would have to "overide" any css the page has i'm at a complete lost on how to pull this off. Any suggestions? thanks
 
Try:
Code:
document.body.topMargin = 30;

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
didn't work. I'm off to bed but if anyone knows / comes up with a solution it would be very appreciated. Thanks for trying tsdragon.
 
Firefox requires units be provided, and I think Tracy meant "marginTop" instead of "topMargin":

Code:
document.getElementsByTagName('body')[0].style.marginTop = '30px';

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Nope, I meant topMargin, and it is not a style attribute, it's a property of the document body. Also, there are NO units allowed, the parameter is the number of pixels. I coded it exactly as it should be coded.

Here's the MSDN Reference.

Unfortunately, according to the ref there is "no public standard that applies to this property", which usually means an IE-only extension. I should have checked that, but it was late.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Thanks guys,

document.getElementsByTagName('body')[0].style.marginTop = '30px';

seemed to work for both FF and IE.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top