In the development of front-end websites, hyperlinks are an important component, and good-looking hyperlink styles can add points to the front-end pages. So how to set the hyperlink style? This article will give you a brief introduction to how to set hyperlink styles with CSS. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
First let’s take a look at the initial hyperlink style on the browser:
Do you think it doesn’t look good? The font color is blue. There are underlines. If displayed like this on the page, it will be very abrupt and make the page less beautiful. So how to modify the font color of hyperlinks and remove the underline of hyperlinks? Next we will introduce how to set the hyperlink style using css.
css sets the text style in hyperlinks
Through a simple code example, let’s learn about css setting the text style in hyperlinks Methods.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>超链接样式</title> <style> .demo { width: 300px; height: 300px; margin: 100px auto; } .demo .a{ text-decoration:none; /*清除下划线 */ font-family: "楷体";/*设置字体种类*/ color: red;/*设置字体颜色*/ font-size: 30px;/*设置字体大小*/ } </style> </head> <body> <div class="demo"> <a href="#">php中文网</a><br /><br /> <a href="#" class="a">php中文网</a> </div> </body> </html>
Rendering:
Description:
text-decoration:none;: Clear the underline of the hyperlink
font-*: Set the font style, such as: font type, size, style (italic, text italic, etc.), thickness, etc.
css pseudo-class to set dynamic hyperlink style
:link: Select an unvisited link and set its style; that is: Defines the style of normal (not visited) links.
:hover: Select the element on which the mouse pointer is floating and set its style; that is, define the style when the mouse is hovering over the link.
:active: Select an active link and set its style; that is: define the style when the mouse clicks on the link.
:visited: Select the visited link and set its style; that is: define the style of the visited link.
Through a simple code example, let’s learn about the method of setting dynamic hyperlink styles using css pseudo-classes
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>超链接样式</title> <style> .demo a { font-size: 30px; /*设置字体大小*/ } a:link { color: #000000; text-decoration: none; } a:visited { color: #00FF00; text-decoration: none; } a:hover { color: #FF0000; text-decoration: underline; } a:active { color: #0081EF; text-decoration: none; } </style> </head> <body> <div class="demo"> <a href="#" class="a">php中文网</a> </div> </body> </html>
The link color defined in the above example is black, and the visited link is green. The link is red when the mouse is hovering over it and blue when clicked. You can try it yourself to see the effect. Setting styles using css pseudo-classes requires following a certain order, let’s take a look.
The order of css pseudo-class setting styles:
There are no rules without rules. There are also rules for css pseudo-class setting link styles. If the writing order of these four items is slightly wrong, the link effect will be affected. There may not be any, so every time you define a link style, be sure to confirm the order of definition, link--visited--hover-active, which is what we often call LoVe
HAte principle (capital letters are their first letters).
Summary: The above is the entire content of the method of setting hyperlink styles in css. What needs to be paid attention to is the order when using pseudo classes to set styles. I hope it will be helpful to everyone's learning. For more related tutorials, please visit: CSS basic video tutorial, HTML video tutorial, bootstrap video tutorial!
The above is the detailed content of How to set hyperlink style with css? How to set hyperlink style with css (code example). For more information, please follow other related articles on the PHP Chinese website!