473,382 Members | 1,665 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,382 software developers and data experts.

How to change link colors using CSS Classes?

Hello,

I want to override my css for a page on my site. I am looking to change all of the link attributes to a style i have in place.

The code I have under the style is :

.style14 {font-size: 12px; color: #000000; text-indent: 20px; font-weight: bold; }


I want to add the following to it:

a{font size: 12px,}
a:link {text-decoration: none; color: #00000}
a:visited {text-decoration:non; color: #00000}
a:hover {color: #632568; text-decoration: underline}

Can someone please provide the correct code? I can't seem to figure it out. I am VERY new to css and xhtml.
Dec 18 '10 #1
7 4324
AutumnsDecay
170 100+
You can simply do:

Expand|Select|Wrap|Line Numbers
  1. <a href="yourpage.html" taget="_self"><span class="style14">This is a link</span></a>
  2.  
Style will then adopt all the properties of your 'a' classes, except those that it overwrites, such as font, or color, etc. Anything set by you in style14 will show.

Also, it looks like you're only adding a text-indent and making the font bold. As such, you can eliminate the color in your style, otherwise your link will always appear black. Your font size has also been set by 'a', so you're fine there too. Your style14 should like this:

Expand|Select|Wrap|Line Numbers
  1. .style14 {text-indent: 20px; font-weight: bold; }
  2.  
Dec 19 '10 #2
Thank You,

But what is the proper code to add the new link attributes to .style 14? Also, in the code you provided, should I remove or replace "this is a link"?

I tried the following but it's not working. I also changed .style 14 to "categories":



.Categories {font-size: 12px; color: #000000; text-indent: 20px; font-weight: bold ;
a:{font size: 12px,}
a:link {text-decoration: none; color: #00000}
a:visited {text-decoration:non; color: #00000}
a:hover {color: #632568; text-decoration: underline}
}

<a href="necklaces2.html" taget="_self"><span class="categories">This is a link</span></a>

ISSUE # 2
Also, is there a way to keep a link colour different ONLY when in a certain page? I am building a site to showcase jewellery and I have categories on the left side of the page ie. bracelets/necklaces etc. I would like the category name to appear in a different colour when a viewer is in that specific page. So if I was looking at necklaces, I would like the word necklaces to be in purple and all other categories in black. All of the categories have .categories style attached to them.
Dec 19 '10 #3
AutumnsDecay
170 100+
As mentioned earlier, <span> will inherit the attributes from <a>. So if <a>'s color is black <span>'s color will be black unless you set it to something different.

Your css has "Categories" and your html calls for "categories". Classes are case-sensitive, as in 'categories' and 'Categories' are different. You also forgot a closing } in your CSS for Categories.

The proper code should be:

Expand|Select|Wrap|Line Numbers
  1. .Categories {font-size: 12px; color: #000000; text-indent: 20px; font-weight: bold; }
  2.  
  3. a:{font size: 12px,}
  4. a:link {text-decoration: none; color: #00000}
  5. a:visited {text-decoration:nonn; color: #00000}
  6. a:hover {color: #632568; text-decoration: underline}
  7. }
  8.  
  9. <a href="necklaces2.html" taget="_self"><span class="Categories">This is a link</span></a>
  10.  
  11.  
Also, no, 'This is a link' is just something I threw in there. You can change that to whatever you want, such as 'Necklaces' or 'Bracelets', etc.

As for different colored links, just make another class called Active or something, and change the color attribute to whatever you'd like. Then in your <span> you could do something like:

<span class="Categoris Active">Blah</span>

I believe that should work.
Dec 19 '10 #4
Thank you! It worked but not for all my pages.
Also for a:hover the text decoration works which is underline, but the change of colour does not.e Why would that be?

Also, What is the purpose of changing "this is a link" to "necklaces or bracelets?"

I need to get this to work on several different pages. Right now it's only working on necklaces2.html.
Here's the code I plugged in:

.Categories {font-size: 12px; color: #000000; text-indent: 20px; font-weight: bold ;}

a:{font size: 12px,}
a:link {text-decoration: none; color: #00000}
a:visited {text-decoration:none; color: #00000}
a:hover {color: #632568; text-decoration: underline}

<a href="necklaces2.html" taget="_self"><span class="Categories">This is a link</span></a>

<a href="necklaces3.html" taget="_self"><span class="Categories">This is a link</span></a>

<a href="Poducts.html" taget="_self"><span class="Categories">This is a link</span></a>

}
Dec 25 '10 #5
AutumnsDecay
170 100+
Do you have your stylesheet linked, or is it static on every page?

If it's the same on every page, you'll have to modify all your pages.
Dec 25 '10 #6
The style sheet .Categories is in a CSS file which is on everypage. So the above code I gave you was entered in my .CSS. It didn't work that way so I just modified it on every page which was a pain in the arse but it worked.

Do you have any idea why the hover colour wouldn't be working? The hover text decoration is working and I find that really weird.

In the future when doing something like this is there a generic way of applying the span. Meaning instead of specifying which word I want it applied to, to just have it applied it to everything under the >categories style?


The website is practically done just some minor tweaking. Once it is I will post the link for you to check it out.

Thanks for all your help :)
Dec 27 '10 #7
AutumnsDecay
170 100+
The issue with doing it like this is that <span> will overwrite whatever the <a> attribute has, including a:hover.

What you could do is:

Expand|Select|Wrap|Line Numbers
  1. <a href="yourpage.html" target="_self"><span class="Categories" onmouseover="this.style='color:#ff8b00;'" onmouseout="this.style='color:#YOUR ORIGINAL COLOR'">Your Link</span></a>
  2.  
I know it seems like a lot, but changing the way a link acts on each page, without creating <a> attributes in CSS on every page is a little work.

Additionally what you could do is have all your CSS in one file (style.css, for example). Have your HTML pages use the "<link rel='stylesheet'>" function, but have different <a> attributes on each page.

Hope this clears things up.
Dec 27 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Will Hartung | last post by:
Can someone clarify that multiple classes in the "class" attribute are ok and "legal" and not some fluke? So, I can do: ..pink {color: pink} ..bold {font-weight: bold} ..medium {font-size:...
3
by: janek | last post by:
I have a question: what differences are between: namespace Mary { int r = 5 ; char m ;
3
by: hutch | last post by:
Hi, I'm making use of this VERY useful function for a so called 'standards compliant' replacement for target="_blank": function externalLinks() { if (!document.getElementsByTagName) return;...
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
9
by: Kobe | last post by:
Is there any difference in: template <class T> vs. template <typename T> ?
3
by: Sudhanshu | last post by:
I have a c code that uses "class" as the variable name in a function prototype I want to use this in c++ file How can I use it ? Any ideas Sudhanshu
4
by: rebeccatre | last post by:
please help me with this, <style> #a, option.message {background-color: green; color: white;} #b, option.message {background-color: yellow; color: black;} </style> <select id="thisselect">...
8
by: cj | last post by:
I've seen examples of web services written with <%@ WebService Language ="Vb" Class=".... at the top. Is it not used in VB 2008?
3
by: Matt | last post by:
Hi everyone, can someone point out the difference between defining a class with the public access modifier and just leaving it as it is (default in vs.net "class") I think that the default...
7
by: BobBlock | last post by:
I have a box defined like this: <div id="shadow-container1"> <div class="shadow1"> <div class="shadow2"> <div class="shadow3"> <div class="container"> the innermost "container" is where...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.