CSS3 Basics: Hover Effects and Background Images

This article introduces two fundamental CSS3 cnocepts: hover-based color change and background image styling. The examples demonstrate how pseudo-classes work and how to control bcakground images.

1. Hover Color Change

The following example shows how to change the color and font size of a hyperlink when hovering over it. It also covers other link states.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hover Effect Demo</title>
    <style>
        a:hover {
            color: #ffbf00;
            font-size: 30px;
        }
        a:link {
            color: green;
        }
        a:visited {
            color: yellow;
        }
        a:active {
            color: blueviolet;
        }
    </style>
</head>
<body>
    <a href="input.html">Hover to change color</a>
    <p class="box"></p>
    <div class="box"></div>
    <span></span><span></span><span></span>
</body>
</html>

2. Background Image with Fixed Attachment

This example demonstrates how to add a background image to a div element, with control over size, repeat, position, and scroll behavior.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Background Image 1</title>
    <style>
        div {
            color: #ffbf00;
            font-size: 50px;
            font-weight: 90;
            width: 400px;
            height: 400px;
            background-color: #a45858;
            background-image: url("1.jpg");
            background-size: 100px;
            background-repeat: no-repeat;
            background-position: center, top;
            background-attachment: fixed;
        }
        p {
            color: blueviolet;
            font-size: 39px;
            width: 700px;
            height: 700px;
            background-color: cornflowerblue;
        }
    </style>
</head>
<body>
    <div>Div element</div>
    <p>Paragraph element</p>
</body>
</html>

3. Background Image with Fixed Scrolling

The final example shows how to apply a fixed background image to the entire page, so it does not scroll with the content.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Background Image 2</title>
    <style>
        body {
            width: 1000px;
            height: 1000px;
            background-image: url("2.jpg");
            /* background-attachment: fixed keeps the background from scrolling */
            background-attachment: fixed;
        }
    </style>
</head>
<body>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
    <p>Testing fixed vs. scrolling background</p>
</body>
</html>

Tags: CSS3 hover background-image pseudo-classes

Posted on Sat, 15 Aug 2026 16:45:55 +0000 by netzverwalter