Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the bare minimum styling for a <a href=""> element

After years of using the <a> tag I've never found an answer to a long-asked question.

To crack down on the stylings of a <a> tag I usually apply four styles:

.element:link{text-decoration:none;color:#CCC;}
.element:hover{text-decoration:none;color:#CCC;}
.element:active{text-decoration:none;color:#CCC;}
.element:visited{text-decoration:none;color:#CCC;}

Because as most of you probably know, browsers tend to apply a default underline and royal blue colour to links.

When I say What is the bare minimum styling for a element is there a way I don't have to apply all of these styles? Will the :hover, :active and :visited inherit the :link style? and is it compatible across all browsers?

P.S.

I know that the above is the same as

.element:link, .element:hover, .element:active, .element:visited{text-decoration:none;color:#CCC;}

So please don't answer with that (:

like image 575
George Avatar asked Dec 03 '12 13:12

George


People also ask

What is Element A in HTML?

<a>: The Anchor element. The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address. Content within each <a> should indicate the link's destination.

How do you style a tag in CSS?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section.

How do you define style in HTML?

The <style> tag is used to define style information (CSS) for a document. Inside the <style> element you specify how HTML elements should render in a browser.

What is the correct way to include a stylesheet named style CSS in the head of your document?

The <style> element must be included inside the <head> of the document. In general, it is better to put your styles in external stylesheets and apply them using <link> elements.


3 Answers

The bare minimum is no styling at all -- so that the browser will automatically apply its default styles.

The usual default is indeed royal blue for link, red or purple for visited, and nothing in particular for the rest.

like image 172
Roy Dictus Avatar answered Nov 15 '22 04:11

Roy Dictus


Answered because @Rob said I should put it here

a.element{} 

or

.element {}
like image 37
Duniyadnd Avatar answered Nov 15 '22 05:11

Duniyadnd


You just use

.element {text-decoration:none;color:#CCC;}

and that's it.
If you want to additionally style :hover or :active state, you do it after .element {}
If you want it to apply to all your links, you can use

a {text-decoration:none;color:#CCC;}
like image 37
ttkalec Avatar answered Nov 15 '22 05:11

ttkalec