Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Pseudo Classes in CSS

Pseudo Classes in CSS

? Pseudo-classes in CSS

Pseudo-classes let you style elements based on their state or position without needing extra classes or JavaScript.

They use a colon : followed by the pseudo-class name.


Common Pseudo-classes

Pseudo-classDescriptionExample
:hoverWhen the mouse pointer is over an elementa:hover { color: red; }
:focusWhen an element is focused (e.g., input focus)input:focus { border-color: blue; }
:activeWhen an element is being activated (clicked)button:active { background: gray; }
:visitedFor links that have been visiteda:visited { color: purple; }
:first-childFirst child element of its parentp:first-child { font-weight: bold; }
:last-childLast child element of its parentli:last-child { margin-bottom: 0; }
:nth-child(n)The nth child of its parentli:nth-child(2) { color: green; }
:not(selector)Negates a selectordiv:not(.highlight) { opacity: 0.5; }

Example Usage

/* Change link color on hover */a:hover {  color: orange;}/* Highlight focused input */input:focus {  outline: 2px solid blue;}/* Style every even list item */li:nth-child(even) {  background-color: #f0f0f0;}/* Style all paragraphs except those with class 'special' */p:not(.special) {  color: gray;}

Why Use Pseudo-classes?

  • Style interactive states like hover, focus, active.

  • Target elements by position without extra markup.

  • Create more dynamic, responsive designs with pure CSS.


Want me to cover pseudo-elements like ::before and ::after next?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql