Forum Moderators: not2easy

Message Too Old, No Replies

creating CSS for different attributes

         

quarryshark

1:41 am on Jan 18, 2007 (gmt 0)

10+ Year Member



Hi
I am redoing my site with a new template. Trying to bring it up with the times. Just learning the basics of CSS. I already have a CSS controling my fonts, H1 tags, H2 tags, links, ect.
I tried to validate the homepage and a large majority of the errors were due to body margin.
"Line 14 column 16: there is no attribute "TOPMARGIN".
the code it's refering to:
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" link="#0000FF">"
I though that I would create a CSS to control this attribute. Do I need to make a new external style sheet?
Any tutorials for this particular item?
TIA

encyclo

1:46 am on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you already have an external stylesheet, you can add the following:

body {
margin:0;
padding:0;
}

That will replace the proprietary

topmargin
etc. attributes on your
body
opening tag.

For the link style, you can add the following:

a {
color:0000ff;
}

That will leave your HTML reading just this:

<body>

And you will have the same visual effect on your pages. :)

quarryshark

2:25 am on Jan 18, 2007 (gmt 0)

10+ Year Member



"For the link style, you can add the following:

a {
color:0000ff;
}

That will leave your HTML reading just this:

<body> "
Do you mean add this to the same external style sheet as well as the prior?

encyclo

2:39 am on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, add all the styles to your one external stylesheet - this will ensure the rules will be used on all the pages on your site. :)

quarryshark

3:08 am on Jan 18, 2007 (gmt 0)

10+ Year Member



Your great! Appreciate the help.
I set this site up 8 years ago using FP98. My how things have changed. I feel like I am back in 1st grade again :)

quarryshark

3:21 am on Jan 18, 2007 (gmt 0)

10+ Year Member



OK, another one. What is wrong with this?
Line 35 column 72: there is no attribute "HEIGHT".
...ding="0" cellspacing="0" width="100%" height="63">

Never mind, I just deleted it.

penders

11:27 am on Jan 18, 2007 (gmt 0)

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



What is wrong with this?
Line 35 column 72: there is no attribute "HEIGHT".
...ding="0" cellspacing="0" width="100%" height="63">

The 'height' attribute on the table element has never actually been part of the W3C spec, so would never validate. However, it has been supported by browsers in the past... although you might get into problems if you are using a proper DOCTYPE (standards mode), or XHTML in particular. Although browsers have supported it, I don't think it was ever recommeded... better leaving the browser decide how big the table should be, based on its contents.

So, in short, better not using it.

You could, however, set the height attribute on table cells (td's) - although that is now deprecated in the W3C Spec (so still allowed with a Transitional DOCTYPE)

If you still want to set the height of a table, however, and make it validate, you can set the height using CSS, something like:

table#specialtable { 
height:63px;
}

cmarshall

1:36 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The 'height' attribute on the table element has never actually been part of the W3C spec, so would never validate. However, it has been supported by browsers in the past... although you might get into problems if you are using a proper DOCTYPE (standards mode), or XHTML in particular. Although browsers have supported it, I don't think it was ever recommeded... better leaving the browser decide how big the table should be, based on its contents.

So, in short, better not using it.

Like this [validator.w3.org]?

quarryshark

2:40 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Lol

encyclo

3:44 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Like this?

Yes, but you've got to learn the rules before learning how to break them. ;) Using

height
on a table is like using
embed
, or
target
with a strict doctype. It may trigger an error, but you shouldn't sacrifice functionality or user benefit for errors which you know are inconsequential. The trick is knowing which errors are inconsequential or not. :)

quarryshark

3:51 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Man, my verisign seal is driving me nut.
Errors below.

Error Line 372 column 55: character "-" is not allowed in the value of attribute "TABINDEX".
...sedown="return v_mDown();" tabIndex="-1" target="VRSN_Splash" href="https://s

and

Warning Line 372 column 144: cannot generate system identifier for general entity "dn".
....com/splash?form_file=fdf/splash.fdf&dn=WWW.#*$!#*$!#*$!.COM&lang=en">

and

Error Line 372 column 144: general entity "dn" not defined and no default entity.
....com/splash?form_file=fdf/splash.fdf&dn=WWW.#*$!#*$!xx.COM&lang=en">

and

Error Line 372 column 146: reference to entity "dn" for which no system identifier could be generated.
...om/splash?form_file=fdf/splash.fdf&dn=WWW.#*$!#*$!.COM&lang=en">

and

Info Line 372 column 143: entity was defined here.
...n.com/splash?form_file=fdf/splash.fdf&dn=#*$!#*$!xx.COM&lang=e..

Every time I change something, the code stops working.
Any ideas? Been playing with this for 45 minutes.

encyclo

3:59 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try removing the
tabindex
attribute (should be unnecessary), then replace each occurance of
&
by
[b]&amp;[/b]
- your problem is with unescaped ampersands which are used to denote entity references.

quarryshark

4:16 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Thanks, that worked. I had to remove the attribute though. I was messing up the &amp; by forgetting the ";" lol

One more
Error Line 373 column 29: there is no attribute "ONCONTEXTMENU".
<img oncontextmenu="return false;" alt="This Web site has chosen one

I tried removing this attribute and it distorted the verisign seal.

cmarshall

4:20 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, but you've got to learn the rules before learning how to break them. ;) Using height on a table is like using embed, or target with a strict doctype. It may trigger an error, but you shouldn't sacrifice functionality or user benefit for errors which you know are inconsequential. The trick is knowing which errors are inconsequential or not. :)

Excellent and practical argument.

I tend to validate because it is a debug aid, but that's because I do this part-time, and don't have a staff of people that can take two hours to track down a bug that can be found in five minutes with a validator failure.

Sites like Amazon, on the other hand, do nothing but, and they probably test more rigorously than we can imagine. Their site fails validation like crazy, but it works, and works well.

penders

7:46 pm on Jan 18, 2007 (gmt 0)

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



> Like this?

Yes, but you've got to learn the rules before learning how to break them. ;) ....

Ha, I had not realised this site [webmasterworld.com] used the height attrib in this way (on a table), but like encyclo suggests, I doubt that it's compromising browser compatibility.

Just to note, this site [webmasterworld.com] also renders the page in quirksmode, which I believe is actually beneficial in this respect. The height *could* be rendered differently in standards mode (apart from not validating), leading to a

height="100%"
(for example) causing problems.

quarryshark

10:22 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Well, from 49 errors down to 2...yipee!
However, these 2 are giving me fits.
first:
Error Line 81 column 19: there is no attribute "BACKGROUND".
<td background="images/title_bar_bg.gif" width="20">&nbsp;</td>

and the second:

Error Line 331 column 29: there is no attribute "ONCONTEXTMENU".
<img oncontextmenu="return false;" alt="This Web site has chosen one

Any ideas?

Setek

10:55 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Error Line 81 column 19: there is no attribute "BACKGROUND".
<td background="images/title_bar_bg.gif" width="20">&nbsp;</td>

Use CSS to determine the background image:

<td style="background-image:url('images/title_bar_bg.gif'); width:20px;">&nbsp;</td>

Error Line 331 column 29: there is no attribute "ONCONTEXTMENU".
<img oncontextmenu="return false;" alt="This Web site has chosen one

I'm guessing the purpose of the proprietary "oncontextmenu" is to disable right-clicking. You can either remove it, or find a more compliant javascript solution :)

One more
Error Line 373 column 29: there is no attribute "ONCONTEXTMENU".
<img oncontextmenu="return false;" alt="This Web site has chosen one

I tried removing this attribute and it distorted the verisign seal.

How did it distort it?

quarryshark

11:00 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Its acually a verisign seal. When I played with the code, all or portions of the seal would dissapear.

Thanks for the tip on the other problem. I will add it to my external CSS.

quarryshark

11:23 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



Error Line 81 column 19: there is no attribute "BACKGROUND".
<td background="images/title_bar_bg.gif" width="20">&nbsp;</td>

"Use CSS to determine the background image:

<td style="background-image:url('images/title_bar_bg.gif'); width:20px;">&nbsp;</td> "


OK, still a novice here. How would I do this?

cmarshall

11:33 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Suggestion:

If you are displaying an image as a background-image, then it cannot be resized. You must either resize it before uploading it, or use an <img> element with either discrete width, height (or both), or a style (or class) that specifies the size. If it will be a background-image, then you need to position it correctly, and specify the repeat (I often use a 1-pixel wide/high image as a repeat-x or repeat-y to fill a space). Whatever is sitting on top of the image MUST be the correct size for the image to display, or it will be cut off.

If you are using floated <divs> over a <div> with a background-image, the floaters will not cause the substrate <div> to expand vertically, and you will need to put one more blank <div> in there with a "clear:both" attribute, or the background-image will not display.

Sounds like a pain, but properly done, it can work a charm. I use this method extensively in my sites. The major drawback is that, if you have an image-heavy site (like mine), it can take several seconds to render, as background-image attributes are given the very lowest priority in rendering pages. You are actually better off using background-color for areas you want to show up quickly (like white text over a dark background-image). The background-color will be eventually replaced by the background-image.