Html link clicked style

With CSS, links can be styled in many different ways.

Links can be styled with any CSS property (e.g. color , font-family , background , etc.).

Example

In addition, links can be styled differently depending on what state they are in.

The four links states are:

  • a:link — a normal, unvisited link
  • a:visited — a link the user has visited
  • a:hover — a link when the user mouses over it
  • a:active — a link the moment it is clicked

Example

/* unvisited link */
a:link color: red;
>

/* visited link */
a:visited color: green;
>

/* mouse over link */
a:hover color: hotpink;
>

/* selected link */
a:active color: blue;
>

When setting the style for several link states, there are some order rules:

Text Decoration

The text-decoration property is mostly used to remove underlines from links:

Example

a:visited text-decoration: none;
>

a:hover text-decoration: underline;
>

a:active text-decoration: underline;
>

Background Color

The background-color property can be used to specify a background color for links:

Example

a:link <
background-color: yellow;
>

a:visited background-color: cyan;
>

a:hover background-color: lightgreen;
>

a:active background-color: hotpink;
>

This example demonstrates a more advanced example where we combine several CSS properties to display links as boxes/buttons:

Example

a:link, a:visited <
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
>

a:hover, a:active background-color: red;
>

More Examples

Example

This example demonstrates how to add other styles to hyperlinks:

Example

Another example of how to create link boxes/buttons:

a:link, a:visited <
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
>

a:hover, a:active background-color: green;
color: white;
>

Example

This example demonstrates the different types of cursors (can be useful for links):

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

If you are using a CMS or any platform with pre-defined CSS files, it is possible that a browser-specific CSS file is causing the issue, as it can override the primary CSS file. In such cases, it can be challenging to use the «element» to create a consistent design across different browsers using CSS alone. A possible solution could be to modify the CSS file or explore alternative options.

My goal is to generate link buttons that modify one another’s css styling after being clicked. I came across some instructional materials on accomplishing this task, but the solution is only partially functional, as demonstrated in this fiddle.

Upon clicking the link and loading the page, the css-styling of the link resets back to normal, which is the only issue at hand. However, it is desired that the styling remains intact until another link is pressed.

From my perspective, utilizing javascript is necessary to achieve this effect. However, this particular area of the internet is not where my strengths lie.

Consider utilizing jQuery, which provides a pre-existing set of functions. To address this issue, focus on the .css() category found at http://api.jquery.com/css/.

Your code would resemble the following.

JQuery can be utilized in conjunction with JavaScript, providing a simpler alternative to using pure JavaScript. Afterward, the onclick event can be triggered by invoking a function.

change color of the second button will change color if you click on the first button 

Ensure that you declare the JQuery library in the HTML along with other necessary steps.

Just replace the href=»#» with void

This function with no return value prevents the browser from making any query requests.

I resolved the issue independently by incorporating the buttons into an unordered list that already contained the same function.

Implementing link into HTML/CSS button, Dec 21, 2012 at 12:16. Add a comment. 3. If you really need to use the . I think it would be more consistent thought to use tags instead of

Оцените статью