Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to control link color in a DIV's inline style?

Status
Not open for further replies.

Tore

Technical User
May 18, 2001
29
0
0
NO
I want to control link color in a DIV.

Inline style in the DIV and not using class.
And not by using inline style in each A tag either.

Hopefully something like this:
Obviously linkcolor does not work, but is there a way to implement it like the example below?

<div style="linkcolor:#aaaaaa;">

some text here
<a href="
</div>
 
use css to format the link color
Code:
<style type="text/css">
<!--
a:link {color: #0000ff; text-decoration: underline; }
a:active {color: #0000ff; text-decoration: underline; }
a:visited {color: #ff00ff; text-decoration: underline; }
a:hover {color: #ff0000; text-decoration: none; }
-->
</style>
 
You did not answer my question.

Is it possible to do it the way I described or not?
 
You can do it if you give the div an ID, or class (say, myDiv) and then specify the links like so:

Code:
<style type="text/css">
<!--
#myDiv a:link {color: #0000ff; text-decoration: underline; }
#myDiv a:active {color: #0000ff; text-decoration: underline; }
... etc

You cannot specify ONLY the links in that particular div unless you give the div a unique ID or a class.

Why not simply give the div in question an id or class, set your style rules up for the div using an external stylesheet or in your <head> tag?

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Thanks for answer.

But not doable for me.

I'm working on a CMS system where the editors should be able to set background-color, color and link color for their content.
They shall be able to nest DIV tags, and each of those nested DIV's can have different background-colors, and therefore would be nice to be able to control link color within each of the DIV's.

One page consist of several independent content which are fetched from a database.
It would be nice to be able to output the settings in an inline style way because then I could just loop through the records to be posted once. If not I have to loop through the records twice..... 1 pass to get and set the styles for the content to be displayed, next loop for displaying the actual content.

That was why I was hoping that it was possible for a any A tags within a given DIV tag to inherit its styling set in the parent DIV and not on a per page level.

Anyway.... thanks for trying :)
 
I am certain you can achieve what you want to do with CSS if you step back and rethink your methodology a bit.

Even if you were to rethink your DB query I am sure you could get the info you need from the database.

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Is it possible to do it the way I described or not?
Not.

If your editors are picking colours from a limited pallette, you could consider making a class for each colour and applying that to the <div>:
Code:
.redlink a { color: red; }
.bluelink a { color: blue; }
... etc ...
Otherwise you're gonna have to build a <style> element dynamically for the page as well as the <div>s. Whether this requires two passes through the database depends on how you code it, but it's no big deal - computers are good at that sort of thing.

Form a usability point of view, I think it's quite a bad idea for links to be different colours in different bits of content. At least one of your editors is gonna have really lousy colour sense, and make the whole page look bad. It's the job of a CMS (in my view) to unify the presentation of information from different people, rather than to vary it like this.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks for replies.

I think I do the following:

I let the editors create different style classes which he then can bind to a DIV container or nested DIV's if he would like.
Something like this:

/* white-on-gray */
.white-on-gray { background-color:gray; color:white ... font styling here... line-height styling here ... etc }

/* title */
.white-on-gray h1 { color:#color; font-size:ypx; margin-top:zpx; margin-bottom:kpx; }

/* sub-title */
.white-on-gray h2 { color:#color; font-size:ypx; margin-top:zpx; margin-bottom:kpx; }

/* a tag */
.white-on-gray a { color:#color; text-decoration:underline; }

I then store each sites styles in a db-table from where I can either dynamically recreate an external css file every time he changes any of the custom styles.
Or I can dynamically fetch the styles from the table on page creation and put them inside "script type=text/css".
The first option is probably best since it will use less cpu resources on the server.

Doing it this way, it should be very easy for the editor to control the looks of a block, such as background-color, title, subtitle, text, link, padding, alignment etc.
And should be really easy for the editor laiter to change the styles for the whole site at any time.

Thanks for the input.

Happy coding



 
It's the job of a CMS (in my view) to unify the presentation of information from different people, rather than to vary it like this.

Absolutely. I did wince when I imagined a page with lots of different colours combos used for links.

But ours is not to reason why.

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top