Home > Article > Web Front-end > css underline removal
In web design, underline is a decorative line commonly used to add style to hyperlinks. However, in some cases we may need to remove the underline from a hyperlink. In css, there are several ways to make a hyperlink without underline.
In css, the text-decoration attribute can be used to control the decorative lines of text. By setting text-decoration:none, the underline of the hyperlink can be removed.
For example, the following code can remove the underline from all hyperlinks:
a { text-decoration: none; }
Another method is to use border -bottom attribute to simulate underlines. Underlines can be removed by setting border-bottom:none.
For example, the following code can remove the underline from all hyperlinks and add a 1-pixel bottom border using the border-bottom attribute:
a { text-decoration: none; border-bottom: 1px solid #000; }
We can also use the background-image attribute to remove underlines. The underline can be removed by setting the hyperlink background image to a blank pixel. This method can also be used to add a custom underline.
For example, the following code can remove the underline of all hyperlinks and set the underline to a 1-pixel-high, blue line:
a { text-decoration: none; background-image: url("data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="); background-repeat: repeat-x; background-position: bottom; background-color: blue; height: 1px; }
Finally, we can also use the :after selector to add an underline. This method can add a pseudo element to the hyperlink and add a style to the element to achieve the underline effect.
For example, the following code can remove the underline of all hyperlinks and add a 1-pixel-high, black underline using the :after selector:
a { text-decoration: none; position: relative; } a:after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 1px; background-color: black; }
To summarize, by setting text- With decoration:none, border-bottom:none, background-image and other methods, we can remove the underline of a hyperlink or add a custom underline. Using the :after selector allows us to control the underline style more flexibly. In practical applications, we can choose the most suitable method to remove underlines according to the specific situation.
The above is the detailed content of css underline removal. For more information, please follow other related articles on the PHP Chinese website!