Forum Moderators: not2easy

Message Too Old, No Replies

Does CSS and HTML have to validate?

         

Rooster92

9:41 am on May 21, 2006 (gmt 0)

10+ Year Member



Does any one know if the css and html has to validate to the w3c standard to become worthy of being listed by the search engines? Do they penalise your website if its not?

My website wont validate html but does validate css.
I think I know why it wont validate html tho,
I have inline elements wrapped around block elements. Namely <p> inside <a>, but I cant seem to find another method for using a block as a hyperlink?
Hope I make sense I have only realy become serious with css recently.

Thanks

DanA

10:13 am on May 21, 2006 (gmt 0)

10+ Year Member



Valid html is easier to index.
Valid css is better for users and different browsers.
You can declare a.anyclass as display:block;.

Rooster92

3:30 pm on May 22, 2006 (gmt 0)

10+ Year Member



Hi, I added display block to my css code
a.mycode{display:block; etc

But I cant really see how this will help validate my HTML, my CSS knowledge is limited perhaps I am missing an important point?

Thanks

4hero

6:18 pm on May 22, 2006 (gmt 0)

10+ Year Member



can you post the validation errors and we'll take a look?

doodlebee

6:21 pm on May 22, 2006 (gmt 0)

10+ Year Member



It's not *necessary* to validate. However, you should, for several reasons.

One reason is that if you have the correct doctype and your site validates, then the site will be viewed using web standards and makes it more accessible and easier for the search engines to navigate your pages. Now, there's no real *proof* that SEO is increased by using web standards and CSS, but it seems to help and it makes sense that it dies, because the spiders don't have to wade through *anything* but content on your page, and as well all know, "content is king" when it comes to rankings.

However, if you have a doctype and it *doesn't* validate, you're throwing your browser into "quirks" mode. Which means that it will *guess* at what you want it to display. Sometimes the guesses are right, and sometimes they're wrong. It's the wrong ones that'll screw ya, because you'll then try and figure out how to get this position fixed and this display moved and end up screwing up every browser known to man, and utlizing hacks to try and fix things that don't need fixing - except to just validate your code.

In other words, if you *don't* a lot of times you're digging yourself into a hole that you can't seem to get out of. You'd be surprised how often simply validating (X)HTML will suddenly snap your "weirdness" back into place - ir at least make it more sensible and easier to fix.

But no, search engines don't penalize you for invalid code. It's just that valid code is better all around - for design *and* accessibility.

Rooster92

6:33 pm on May 22, 2006 (gmt 0)

10+ Year Member



Heres my Doc type, I'm pretty sure its okay:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Heres the error I keep getting:

# Error Line 76 column 32: document type does not allow element "P" here; missing one of "APPLET", "OBJECT", "MAP", "IFRAME", "BUTTON" start-tag.

<p align="center" class="velvet">Velvet</p>

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").

I'm working on it right now trying to get it sorted, I'm pretty sure It's still to do with the inline elements wrapped around block elements.
At least I dont think its the doctype I have tried several combinations.

Thanks

4hero

6:53 pm on May 22, 2006 (gmt 0)

10+ Year Member



hmm, try <p><a class="block" href="#">your link</a></p>

with the following css

a.block {display:block}

is this what you're aiming for?

Rooster92

7:03 pm on May 22, 2006 (gmt 0)

10+ Year Member



Hi, hmm not sure, I tried.
What I have is a fairly large .jpg displayed on the page, with some text aligned inside it. But the whole image/jpeg or 'image area' is a link.

The html validator hates what I have done. Maybe it would be easier just to post the code, so here it is:
HTML:

<a class="background-pic" href="target-page.html">
<p class="some-copy">blah,blah,blah</p>

CSS:

a.background-pic{
display: block;
position:relative;
float:left;
top:-95px;
width:600px;
height:300px;
background-image: url(target.jpg)
}

p.some-copy{
position:relative;
line-height:15px;
vertical-align: bottom;
left: 170px;
height:10px;
float: left;
width:160px;
top: 75px;
color: #FEFEFE;
font-size: 12px;
font-family: Arial, "Times New Roman", Verdana;
}

4hero

7:52 pm on May 22, 2006 (gmt 0)

10+ Year Member



can you tell me what exactly you are trying to achieve?

Are you looking to have a link (with a background picture) and some text within?

Rooster92

8:00 pm on May 22, 2006 (gmt 0)

10+ Year Member



Yes that’s exactly it!
“a link (with a background picture) and some text within”

What am I doing wrong?
In fact what I have done does actually work and work fine in both IE and Firefox. It just wont validate, so I guess the html MUST be dodgy.

4hero

8:30 pm on May 22, 2006 (gmt 0)

10+ Year Member



you could try this:

css
a.pic {
display: block;
position:relative;
float:left;
width:600px;
padding:140px 0;
text-align:center;
color: #FEFEFE;
font-size: 1em;
font-family: Arial, "Times New Roman", Verdana;
background:#ccc url(target.jpg) center center no-repeat}

padding:140px 0; centers the text vertically, this may need adjusting to suit your image..

the html
<a class="pic" href="target-page.html">Some text goes here</a>

worth a shot ;)

Rooster92

8:26 am on May 23, 2006 (gmt 0)

10+ Year Member



Hi, yeah but how does the text get precisely positioned inside the background jpeg?

Rooster92

6:04 pm on May 23, 2006 (gmt 0)

10+ Year Member



Hi,
here is a link to a section of the website in question.
The greyed out areas represent the images in which the 'blah' text is placed.
These grey boxes link to their seperate target pages.
No text whithin the grey boxes needs to link anywhere, as its only the grey boxes themselves that need to link.

[inzanemedia.co.uk...]

Thanks a lot.