multiple link styles without classes?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a site that pulls half its content from a database. Text that
will have links in it, that I won't be able to alter. They'll all be
<a href="link">blah</a>
But I want to give links within this database pulled text to have a
different style than the rest of the page.

Here's a couple of ways I can think of to do it, but I'd like to know
if there's a better way.

Set up a style for the generic link which will affect those pulled from
the database, and then in all the static links on the page, use a
separate class.
Use PHP to replace
<a href...
<a class="blah" href...

Is there some other way that would be better?

Thanks for any tips!

Re: multiple link styles without classes? wrote:

Quoted text here. Click to load it

In your CSS:

#stuffFromDatabase a {

In your HTML:

<div id="stuffFromDatabase">

This will make any <a> inside that <div> block appear with the style
defined in the style sheet. This makes it much simpler as you don't
need to add any class information to the <a> tags themselves.

If you need to make it appear in several areas of the page instead of
just one block then you could make them use a class instead of an id
like this:

..stuffFromDatabase a {

<div class="stuffFromDatabase">


<div class="stuffFromDatabase">

Chris Hope | |

Re: multiple link styles without classes?

On Sat, 21 May 2005 09:26:58 +1200, Chris Hope

Quoted text here. Click to load it

That's the neat way to do it, although personally I'd make one change.
Rather than an id "stuffFromDatabase" I'd make that a class   (so it's
..stuffFromDatabase a { }  in the CSS too).

The reasons are twofold:

 - We don't know that there couldn't be more than one
<div class="stuffFromDatabase" >  on the same page. As we don't _need_
to rule this out, we shouldn't rule it out.

 - I don't like applying CSS to large blocks of HTML via id rather than
class.  Id has a high priority in CSS and so it tends to have "sticky"
effects.  This is OK on a small area, but it can be awkward if you want
to apply another link style within that area, by using another class.

Re: multiple link styles without classes?

Andy Dingley wrote:
Quoted text here. Click to load it

Great! Thanks for the suggestions and replies!

Site Timeline