Solved

Overriding CSS styles for specific links on a particular page

Posted on 2009-04-09
8
713 Views
Last Modified: 2012-05-06
I am building a web site using Dreamweaver CS3. I am using a grid of small photos as a navigational tool on a few pages. For aesthetic reasons, I don't want any link highlighting on these linked photos -- no link, visited, active or hover highlighting. I have a fade-in and fade-out behavior assigned to each linked photo and that's the only thing I want to change visually when the mouse passes over the images.

The link highlighting is controlled globally by a CSS style sheet. Is there a way to override the CSS link styles and apply no link styles to specific links on a specific page, while leaving the other links on that page unchanged (i.e., controlled by the CSS style sheet)?
0
Comment
Question by:don0don
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:level9wizard
ID: 24109285
You can manage that link with it's own css class. For example

/*  THE CSS */
<a href="page.html" class="custom"><img src="" alt="" /></a>


<!-- THE HTML -->
a.cusotm
{
     text-decoration: none;
     border: none;
}
0
 
LVL 11

Accepted Solution

by:
level9wizard earned 125 total points
ID: 24109320
Hah, had that backwards and typo'd - sorry about that. Here's a full working example.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>test </title>
 
	<style type="text/css">
	a.custom
	{
		 text-decoration: none;
		 border: none;
		 /* any other customizations to that link here you want to override the global/default*/
	}
	</style>
</head>
<body>
	<a href="page.html" class="custom">Sample</a>
</body>
</html>

Open in new window

0
 

Author Comment

by:don0don
ID: 24110569
I hope you'll forgive a newbie question, bit regarding the /* THE CSS */ part of your instructions: would I need to add a separate class for each image on each page that I want to exclude from the global CSS formatting? In other words, here would be a separate <a href> statement for each image, pointing to the page name and the <img src> of each image?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 42

Expert Comment

by:David S.
ID: 24111544
You would only need to use different classes if you wanted some of the styles to be different. Multiple elements may belong to the same class and an element may belong to multiple classes. The [X]HTML class attribute's value may be a space separated list of classes.

IDs, on the other hand, should be unique. In other words, two elements in the same document may not have the same ID.
0
 

Author Comment

by:don0don
ID: 24111743
OK.

I've added this to the top of the page, at the bottom of the HEAD section:

     <!-- CSS CUSTOM CLASS -->
             <style type="text/css">
             a.custom
             {
                      text-decoration: none;
                      border: none;
             }
             </style>

     </head>

... and I've added class="custom" to each of the <a href> statements, immediately after the page link (see the code snippet).

Doesn't work ... the linked images still have borders around them.

Obviously, I'm doing something wrong.

Sorry to be such a bonehead about this ...



        <td width="188"><a href="Billboards_Banners.htm" class="custom" target="_blank"><img src="picts/Cat_Bill_Bann.jpg" title="Billboards & Banners" width="188" height="125" onMouseOut="MM_effectAppearFade(this, 1000, 50, 100, false)" onMouseOver="MM_effectAppearFade(this, 1000, 100, 50, false)"></a></td>

Open in new window

0
 
LVL 42

Assisted Solution

by:David S.
David S. earned 125 total points
ID: 24113423
No, you did what was suggested. Actually the border is applied to the <img>, not the <a>. You can use the comma to make the rule apply to <a> elements that belong to the "custom" class and <img> elements that are descendants of such an element.
             <style type="text/css">
             a.custom, a.custom img
             {
                      text-decoration: none;
                      border: none;
             }
             </style>

Open in new window

0
 
LVL 13

Expert Comment

by:qwerty021600
ID: 24114561
a.custom img, img
             {
                      text-decoration: none;
                      border: 0;
             }
0
 

Author Closing Comment

by:don0don
ID: 31568607
I split the points because level9wizard was on the right track and Kravimir's tweak took it all the way to success. Thanks for your help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question