CSS Tutorial : Introduction of the CSS Pseudo-classes :lang(), :link, :hover, :visited

CSS Tutorial : Introduction of the CSS Pseudo-classes :lang(), :link, :hover, :visited

In this CSS tutorial, we will discuss the four more Pesudo-classes ":lang(), :link, :hover, :visited".

CSS Tutorial

1. :lang() class

:lang() CSS pseudo-class can be used to apply CSS to a tag using the "lang" attribute of a tag. Suppose a web page has three paragraphs or the three paragraphs use the "lang" attribute or we want to apply different "CSS" to the three paragraphs then we can use the "lang" attribute.

SYNTAX

<style>
    :lang(language-code) {
        /* CSS properties */
    }
</style>

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RAYS Coding: Pseudo-class Example</title>
    <style>
        body{
            background: #1b1b1b;
        }
        /* Style for English paragraphs */
        p:lang(en) {
            color: white;
            font-weight: bold;
            font-size: 40px;
            font-family: sans-serif;
        }
        /* Style for Spanish paragraphs */
        p:lang(es) {
            color: green;
            font-size: 20px;
            font-style: italic;
        }
        /* Style for French paragraphs */
        p:lang(fr) {
            color: red;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <p lang="en">This is an English paragraph.</p>
    <p lang="es">Este es un párrafo en español.</p>
    <p lang="fr">Ceci est un paragraphe en français.</p>
    <p lang="en">Another English paragraph.</p>
    <p lang="es">Otro párrafo en español.</p>
</body>
</html>

CSS Tutorial


2. :link class

In CSS, the :link pseudo-class is used to mark a link (anchor tag) that has not yet been visited. When you create a link on a webpage, if that link has not yet been clicked, :link is applied to it.

SYNTAX

<style>
    selector:link {
        property: value;
    }
</style>

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RAYS Coding: Pseudo-class Example</title>
    <style>
        body {
            background: #1b1b1b;
            color: #ffffff;
            font-family: Arial, sans-serif;
        }
        a:link {
            color: #1e90ff;
            text-decoration: none;
        }
        a:link:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <h1>Welcome to RAYS Coding</h1>
    <p>
        Check out our <a href="https://www.example.com">tutorials</a> to learn more!
    </p>
</body>
</html>

CSS Tutorial

3. :hover

:hover is a CSS pseudo-class that applies CSS when the mouse pointer is moved over an element. This class is activated when you hover over an element, such as a button or link. This allows you to change the style of the element, such as the background color, text color, and yes, the border.

SYNTAX

<style>
    tag:hover {
        property: value;
    }
</style>

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RAYS Coding: Pseudo-class Example</title>
    <style>
        body {
            background: #1b1b1b;
            color: #ffffff;
            font-family: Arial, sans-serif;
        }
        a {
            color: #00ff00;
            text-decoration: none;
            transition: color 0.3s;
            font-size: 40px;
        }
        a:hover {
            color: #ff0000;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <h1>Welcome to RAYS Coding</h1>
    <p>Is example mein aap hover effect dekh sakte hain:</p>
    <a href="#">Click Here</a>
</body>
</html>

CSS Tutorial
Before Hover

CSS Tutorial
After Hover

4. :visited

The :visited pseudo-class is used for links, indicating whether a link has already been visited. When you click a link, it becomes visited, and you can change the style of the link with the class.

SYNTAX

<style>
    element:visited {
        property: value;
    }
</style>

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RAYS Coding: Pseudo-class Example</title>
    <style>
        body {
            background: #1b1b1b;
            color: #ffffff;
            font-family: Arial, sans-serif;
        }
        a {
            color: royalblue;
            text-decoration: none;
            font-size: 70px;
        }
        a.weblink:visited {
            color: tomato;
        }
    </style>
</head>
<body>
    <h1>Welcome to RAYS Coding</h1>
    <p>
        Click the link below to visit OpenAI:
        <a class="weblink" href="https://www.rayscoding.com" target="_blank">Rays Coding</a>
    </p>
</body>
</html>


CSS Tutorial

Post a Comment

Previous Post Next Post

Recent in Technology