473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

multiple link styles without classes?

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
like
<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...
with
<a class="blah" href...

Is there some other way that would be better?

Thanks for any tips!
Liam

Jul 24 '05 #1
3 2261
ne**@celticbear.com wrote:
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
like
<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...
with
<a class="blah" href...

Is there some other way that would be better?


In your CSS:

#stuffFromDatabase a {
...
}

In your HTML:

<div id="stuffFromDatabase">
...
</div>

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>

....

<div class="stuffFromDatabase">
...
</div>
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 24 '05 #2
On Sat, 21 May 2005 09:26:58 +1200, Chris Hope
<bl*******@electrictoolbox.com> wrote:
<div id="stuffFromDatabase">
...
</div>


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.

Jul 24 '05 #3
Andy Dingley wrote:
On Sat, 21 May 2005 09:26:58 +1200, Chris Hope
<bl*******@electrictoolbox.com> wrote:
<div id="stuffFromDatabase">
...
</div>
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).

Great! Thanks for the suggestions and replies!
Liam

Jul 24 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: LRW | last post by:
Below I'll paste my CSS and the HTML in question. But what's happening is, I'm trying to establish a link behavior for a class that's separate from the normal link class. I've established a: 's...
5
by: Jacob | last post by:
Hello, I would like to define some internal styles within an HTML page, but have those style overridden by an external style sheet if it exists at the location specified by a <link> element. ...
7
by: Sandman | last post by:
I have a script that generates a hierarchical menu, but I am having problems assigning styles to each manu items different possible states. The possible states a menu item can be in is (and all of...
7
by: codeslayer | last post by:
Greetings to everyone in ‘forum-land': I have a problem that has plaguing me to no end. It is a CSS-related question, and I have not seen this question posted anywhere in forums or through...
0
by: Emil Christopher Melar | last post by:
I wanted to use App_Theme, because then I might have some automation when it comes to not hard coding paths for the css. And as you know, you know that mozilla and IE renders differently, and...
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
3
by: spolsky | last post by:
hi, it is possible to apply multiple styles as shown in the following example. <STYLE TYPE="text/css"><!-- BODY { background-color:salmon; } P { margin-left:20px; } .clsCode {...
14
by: Jeff | last post by:
Let's say we have this: <div class="some_class some_other_class"> Is it possible to change *one* of the classnames. Jeff
4
by: henry | last post by:
Folks: As a follow-up to my recent posts, I want to ask some more general questions about multiple instances of a CSS link in a page as seen by browsers due to server-side file inclusion. Let...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.