By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

Body tag vs margin-right

P: n/a
Hi

I was using <BODY leftmargin=20 > which worked ok. but then I changed it to
<BODY style="margin-left:20px;" and this works fine as well.

In order to try and formalise things I decided to use a style sheet so I
linked it in and every other style i have set works fine. but my margin for
the entire page does not work.

... in my page now the body tag has no attributes apart from one.

<BODY vlink="blue" >

and in the linked style sheet/

BODY { margin-left:20px }
What am I doing wrong ?

--

Jan 21 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Terry Moon wrote:
I was using <BODY leftmargin=20 > which worked ok.
For some odd values of "worked". It is proprietary markup that is
supported by some browsers only, so you didn't test well. Besides, it
sets the margin in pixels, not relative to font size.
but then I changed it to
<BODY style="margin-left:20px;" and this works fine as well.
For different values of "worked". It does something on supporting
browsers with CSS enabled, assuming that no other style sheet overrides it.
In order to try and formalise things I decided to use a style sheet so I
linked it in and every other style i have set works fine.
That's a good idea, especially since doing things in such a centralized
manner lets you fix errors more easily when you notice that e.g. wasting
20 pixels on the left is not that fine.
.. in my page now the body tag has no attributes apart from one.

<BODY vlink="blue" >
That's _very_ poor practice. Never touch a color without setting other
colors, and never set visited link color to the common default color of
unvisited links. But this has nothing to do with margins.
and in the linked style sheet/

BODY { margin-left:20px }
If this does not work and <BODY style="margin-left:20px;"> works, then
you have
a) an error in your HTML markup
b) an error elsewhere in the style sheet
c) a faulty browser.
What am I doing wrong ?


You are not showing the URL to us, to begin with.
Jan 21 '06 #2

P: n/a
Thanks for your reply.

One more question if you dont mind please?

Do the nested tags inherit the enclosing tag style attributes, for example,
if the body tag had a margin-left:nn then would all paragraphs enclosed
therin also have this margin by default ?

--

"Jukka K. Korpela" <jk******@cs.tut.fi> wrote in message
news:dq**********@phys-news4.kolumbus.fi...
Terry Moon wrote:
I was using <BODY leftmargin=20 > which worked ok.


For some odd values of "worked". It is proprietary markup that is
supported by some browsers only, so you didn't test well. Besides, it sets
the margin in pixels, not relative to font size.
but then I changed it to <BODY style="margin-left:20px;" and this works
fine as well.


For different values of "worked". It does something on supporting browsers
with CSS enabled, assuming that no other style sheet overrides it.
In order to try and formalise things I decided to use a style sheet so I
linked it in and every other style i have set works fine.


That's a good idea, especially since doing things in such a centralized
manner lets you fix errors more easily when you notice that e.g. wasting
20 pixels on the left is not that fine.
.. in my page now the body tag has no attributes apart from one.

<BODY vlink="blue" >


That's _very_ poor practice. Never touch a color without setting other
colors, and never set visited link color to the common default color of
unvisited links. But this has nothing to do with margins.
and in the linked style sheet/

BODY { margin-left:20px }


If this does not work and <BODY style="margin-left:20px;"> works, then you
have
a) an error in your HTML markup
b) an error elsewhere in the style sheet
c) a faulty browser.
What am I doing wrong ?


You are not showing the URL to us, to begin with.

Jan 21 '06 #3

P: n/a
Sat, 21 Jan 2006 16:08:47 +0200 from Jukka K. Korpela
<jk******@cs.tut.fi>:
Terry Moon wrote:
<BODY style="margin-left:20px;" and this works fine as well.


For different values of "worked". It does something on supporting
browsers with CSS enabled, assuming that no other style sheet overrides it.


_Could_ any other style sheet override it? I thought an inline style
always overrides any attached or embedded sheet.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Jan 21 '06 #4

P: n/a
On 21/01/2006 16:27, Stan Brown wrote:

[snip]
_Could_ any other style sheet override it? I thought an inline style
always overrides any attached or embedded sheet.


An in-line style declaration is more specific than any other selector,
so an author style sheet couldn't override it. However, a user style
sheet could.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 21 '06 #5

P: n/a
Michael Winter <m.******@blueyonder.co.uk> wrote:
_Could_ any other style sheet override it? I thought an inline style
always overrides any attached or embedded sheet.
An in-line style declaration is more specific than any other selector,
so an author style sheet couldn't override it.


An author style sheet can override it by using !important.
However, a user style sheet could.


By using !important, as a user style sheet would have to do to override any
declaration in an author style sheet.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jan 21 '06 #6

P: n/a
"Terry Moon" <Te*******@hotmail.co.uk> wrote:
Thanks for your reply.
Please learn to quote properly on Usenet:
http://www.netmeister.org/news/learn2quote.html
Do the nested tags inherit the enclosing tag style attributes, for
example, if the body tag had a margin-left:nn then would all paragraphs
enclosed therin also have this margin by default ?


Tags inherit nothing. Elements may inherit properties, but margin properties
are not inherited. Thus, setting margin-left for the body element affects
that element only.

On the other hand, the paragraphs (p elements) are descendents of the body
element, so they normally appear inside the block generated for the body
element - and this block has the margins assigned for the body element.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jan 21 '06 #7

P: n/a
On 21/01/2006 17:03, Jukka K. Korpela wrote:

[snip]
An author style sheet can override [an in-line declaration] by using
!important.


Yes, of course. Sorry. It would be a silly thing to force oneself to do,
though.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 21 '06 #8

P: n/a
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:
An in-line style declaration is more specific than any other selector,
so an author style sheet couldn't override it.


An author style sheet can override it by using !important.


Nope.

--
Spartanicus
Jan 21 '06 #9

P: n/a
Spartanicus <in*****@invalid.invalid> wrote:
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:
An in-line style declaration is more specific than any other selector,
so an author style sheet couldn't override it.


An author style sheet can override it by using !important.


Nope.


Please check http://www.w3.org/TR/REC-CSS2/cascade.html#cascade
The _primary_ sort is by weight and origin. Only when this does not resolve
the issue, specificity will be considered.

Did you try it?

<style type="text/css">
body { margin: 0 !important; }
</style>
<body style="margin-left:20px">

By CSS specs, you should get zero margins. And even IE obeys this.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jan 21 '06 #10

P: n/a
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:
An in-line style declaration is more specific than any other selector,
so an author style sheet couldn't override it.

An author style sheet can override it by using !important.


Nope.


Please check http://www.w3.org/TR/REC-CSS2/cascade.html#cascade
The _primary_ sort is by weight and origin. Only when this does not resolve
the issue, specificity will be considered.

Did you try it?


I initially checked to make sure with a quick test case, I must have
goofed when creating it, I couldn't repeat the result when I re-created
the test, apologies.

--
Spartanicus
Jan 21 '06 #11

P: n/a
Sat, 21 Jan 2006 11:27:08 -0500 from Stan Brown
<th************@fastmail.fm>:
Sat, 21 Jan 2006 16:08:47 +0200 from Jukka K. Korpela
<jk******@cs.tut.fi>:
Terry Moon wrote:
<BODY style="margin-left:20px;" and this works fine as well.


For different values of "worked". It does something on supporting
browsers with CSS enabled, assuming that no other style sheet overrides it.


_Could_ any other style sheet override it? I thought an inline style
always overrides any attached or embedded sheet.


As several people pointed out, I forgot about !important. Thanks.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Jan 21 '06 #12

P: n/a
> If this does not work and <BODY style="margin-left:20px;"> works, then
you have
a) an error in your HTML markup
b) an error elsewhere in the style sheet
c) a faulty browser.
What am I doing wrong ?


You are not showing the URL to us, to begin with.


There is a more prosaic possibility: that your link to the stylesheet is
incorrect somehow.

Again, post your URL and someone on the newsgroup would very quickly be
able to tell you if this is the case

Dan
Jan 22 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.