tags:

views:

151

answers:

5

I was given the task of doing a facelift to our current site. I am moderately well versed in CSS so I am converting the bazillion tags to CSS styles and deleting about 2 times that many that were simply not necessary.

It's all going well until I run into a certain product page that is only a wrapper into which other HTML files are pulled by a server.execute(filename) command. (we're using aspx for the wrapper page.)

There are almost 700 of these pages and they all are cursed with this and that. Past editors with FrontPage that only know how to drag pretty things on the screen.

Anyway, I am wondering if there is a way to use CSS in the wrapper page to override the tag behavior so I can make it something sane that fits with the rest of my pages. I'd even be open to something JavaScript that would remove the tags, but that's my less preferred solution. Thanks!

+8  A: 
font[size="2"] {
   property: value !important;
   ...
}

The !important after property values is what you're looking for.

Eli Grey
Very nice, but won't work with IE6 - still (sadly) worth noting.
Pekka
Thanks for the answer I was looking for. I'll have to deal with IE6 swiftly and harshly (I wish).
Deverill
This doesn't work for me in IE7.
Pekka
I don't understand why, but I can't get this to work even in IE8. Am I just overlooking something? Anyone been successful?
Pekka
@Pekka Works for me, are you using a doctype?
James
@James nope, doesn't work for me even with a doctype. Anyway, it may just be time for me to call it a day, it's probably just a typo somewhere.
Pekka
+3  A: 

You can use the CSS attribute selector to match your font tag:

font[size="2"] {
    font-size: 12px;
    font-weight: bold;
}
James
Won't work with IE6 though. If the client is using `font` tags on their site this may be an issue.
Pekka
Thanks James. +1 for the answer too.
Deverill
A: 

If you can - that means if you can ignore IE6 - use the CSS method Eli Grey and James Goodwin propose.

A cleaner, but more tedious way would be to do a intelligent search+replace changing all <font size='2'> to <span class='size_2'> or something. It would get you rid of the crappy code, and work in all browsers.

Pekka
since we're doing the right thing, that 'size_2' would be better named as something semantic. To say nothing of the closing /font
Adriano Varoli Piazza
@Adriano true re the class name. The closing font is why I'm saying "intelligent" search+replace - it would have to be a tool capable of recognizing and replacing tags. Dreamweaver used to have that feature, there are other tools around, too.
Pekka
+1  A: 

A simple reset would do for this case, e.g.

font {
    font-size: 100%;
}
Paul D. Waite
+1 very nice solution (if the OP doesn't need to give the `size=2` a specific other size in exchange.)
Pekka
@Pekka but the size attribute will override this. He needs an `!important`.
Eli Grey
@Eli Grey: I beg to differ — http://www.pauldwaite.co.uk/test-pages/2465665/
Paul D. Waite
Oh, sorry. My mistake.
Eli Grey
“if the OP doesn't need to give the `size=2` a specific other size in exchange” — Ah yes, this does assume he just wants to get rid of the effect of presentational tags entirely. Personally, I’d edit the pages, 700 isn’t that many. It’d be a bit boring, but a day or two of judicious find-and-replace in a decent text editor, and you could turn a dog’s breakfast into some decent code.
Paul D. Waite
A: 

Since Internet Explorer ignores the !important rule, you could try a Javascript approach such as the following (uses jQuery) to replace all the FONT elements with SPANs and have the appropriate stylesheets to apply formatting.

$('font').each(function(){
  var fontFree = $('span');
  fontFree.append($(this).contents());
  fontFree.addClass('size_'+$(this).attr('size'))
  $(this).replaceWith(fontFree);
});
Dancrumb