Forum Moderators: not2easy

Message Too Old, No Replies

Body css not working, please help

         

Acternaweb

2:41 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



I am trying to control the page margins and font(s) via css and not having luck. Do I need to refer to it in a state class (ie <body class="body">?

Here is what I currently have;

body {
font-family: comic sans ms, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
leftmargin:20%;
topmargin:0%;
marginwidth:0%;
marginheight:0%;

}

Any thoughts?

Thanks,

zendak

3:08 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Hi Acternaweb,
Try this:

body {
font-family: comic sans ms, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
margin-left:20%;
margin-top:0%;
}

You need not specify <body class="body">, the style rule defines the body properties, so using just <body> is fine.

Important: leftmargin, topmargin, marginwidth and marginheight are not CSS properties and are therefore ignored by browsers. As far as I know, they used to be proprietary HTML tags that Netscape introduced in the dark ages of the internet and should not be used any more. You can read up about the different ways of correctly using margins in CSS at [w3.org...]

[edited by: zendak at 3:17 pm (utc) on Feb. 6, 2004]

aevea

3:13 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Also, multiple word font names need to be enclosed in quotes:


body {
font: 12px "comic sans ms", Helvetica, sans-serif;
color: #000000;
margin: 0 0 0 20%;
}

Adam

Acternaweb

3:28 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Thanks that worked for the margins, but not the type face, I tried using only one font face and still no success. Nieither does font size work, but color does work. Any ideas?

zendak

3:40 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Also, multiple word font names need to be enclosed in quotes

Sorry, forgot to correct that.

Nieither does font size work, but color does work. Any ideas?

a) Make sure you're not using anything like
<font size="3">Text</font>

in your html document, as the font tags will override your css rule.

b) Make sure you didn't declare the font attributes twice in your css, as identical rules will override each other, namely always the last one given will make the previous ones useless.

c) Browser could be configured to show a fixed text size.. Which one(s) are you using?

Another thing: if a value equals zero, no unit needs to be given, i.e.
margin-left: 0;
has the same result as
margin-left: 0%;

Omitting that per cent sign has already reduced your document size by one byte ;)
When possible, use shorthand properties as aevea demonstrated, they'll save some space, too.

choster

3:44 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



aevea's code works for me, both font and margin settings, though you can compress it just a bit further :-):

body {
font: 12px "Comic Sans MS", Helvetica, sans-serif;
color: #000;
margin: 0 0 0 20%;
}

What browsers are you testing on? Are you sure that Comic Sans and/or Helvetica are both installed on your test machines?

Acternaweb

3:45 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



HI
I don't have other body fonts but I do have font-family for lists, headers, etc
Do they all have to be the same, in this case the font face is the same but the font size will varry. Is that an issue?

Thanks,

zendak

3:45 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Goes for typeface too of ourse, so don't use
<font face="Whatever">blabla</font>

either.

zendak

4:14 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



I don't have other body fonts but I do have font-family for lists, headers, etc
Do they all have to be the same, in this case the font face is the same but the font size will varry. Is that an issue?

That shouldn't be a problem. That's the whole point of CSS, being able to style the different elements separately. But basically the body shouldn't be affected by any list or header stylings, as the body is the parent element of all those.

Example:

body {font: 12px Arial, sans-serif; color: green}
h1 {font: 14px;}
li {font: Verdana, sans-serif;}
td {font: 10px; color: red;}

will result in:

Level 1 headers = 14px Arial green
List items = 12px Verdana green
Table cell content = 10px Arial red

As you can see, you only really need to specify those properties that differ from the parent element's. In my example I did not specify the font face and colour for h1 again, as it inherits the values from the body. Only the size is different, so that was specified. Etc.

Go through your CSS and HTML with that in mind. If you can't find the problem, maybe post a link to your page or post more complete HTML and CSS.

Hope it helps :)

Acternaweb

4:36 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



OK I attribute my being dumba55 to being Friday. I have my body content in a table, thus it was taking the style from <td>. I am using the body tags just for page margins now, will that cause a problem.

Thanks for the help

zendak

4:58 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Yeah Friday gets us all sometimes :)

No, shouldn't be a problem to just use the body selector for the margins if you define your fonts etc for the table.

I should mention that Netscape 4 ignores what you defined in body for td. As an example you should use

body, td {font: 16px Helvetica; color: #000; background-color: #fff;}

instead of just

body { ... }

Otherwise NN4 will use the browser defaults for your table which will look pretty ugly in your design.

PS: Going into another topic, you should also make sure that you really need tables for what you're doing. If you're new to using tableless layouts I recommend researching it as it has many advantages for both you as a designer and for your audience. Useful links: [w3.org...] and [glish.com...]

bumpaw

7:30 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



I went to the link for w3.org and got exposed to something new for me. This is from the source:

<a href="http://www.w3.org/"><img
src="/Icons/w3c_home" alt="W3C" /></a>

I noticed that the image w3c_home.bmp leaves out the file extension. I couldn't make it work like that, and haven't a clue why.

g1smd

10:20 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look for information on content negotiation to solve that one.

bumpaw

10:59 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Content-Negotiation is a mechanism defined in the HTTP specification that makes possible to serve different "versions" of a document (or more generally of a resource) at the same URL, so that user agents can choose which version fit their capacities the best.

One of the most classical usage of this mechanism is to serve an image as both GIF and PNG, so that browser that don't understand PNG still gets the GIF version.
[w3.org ]


Thanks for the clue!