Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

CSS Selectors 101

You've written some HTML. Now you want to make it look good with CSS. But how do you tell CSS which elements to style? That's where selectors come in. Why Do We Need CSS Selectors? Imagine you're in a classroom and you want to…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

You've written some HTML. Now you want to make it look good with CSS. But how do you tell CSS which elements to style?



That's where selectors come in.






Why Do We Need CSS Selectors?



Imagine you're in a classroom and you want to give instructions:



Without selectors:

"Everyone, stand up!"



With selectors:

"Students wearing red shirts, stand up!"

"Student named John, stand up!"

"Students in row 3, stand up!"



CSS selectors work the same way. They let you target specific HTML elements and apply styles to them.



Without selectors: You can't style anything

With selectors: You control exactly what gets styled





Basic HTML for Our Examples



Let's use this HTML throughout the blog:




<body>
<h1>Welcome</h1>
<p>This is a paragraph.</p>
<p class="highlight">This is highlighted.</p>
<p id="special">This is special.</p>
<div class="box">
<p>Paragraph inside box</p>
</div>
</body>






Now let's see how to select different parts.






1. Element Selector



The element selector targets all elements of a specific type.



Syntax:




tagname {
/* styles */
}






Example:




p {
color: blue;
}






What this does:

Targets ALL <p> elements and makes them blue.



Result:




  • "This is a paragraph." → Blue

  • "This is highlighted." → Blue

  • "This is special." → Blue

  • "Paragraph inside box" → Blue



Use when: You want to style all elements of one type.





More Examples



Style all headings:




h1 {
font-size: 32px;
color: darkblue;
}






Style all divs:




div {
background-color: lightgray;
padding: 10px;
}









2. Class Selector



The class selector targets elements with a specific class.



Syntax:




.classname {
/* styles */
}






Notice the dot (.) before the class name.



Example:




.highlight {
background-color: yellow;
}






What this does:

Targets only <p class="highlight"> and gives it a yellow background.



Result:




  • "This is highlighted." → Yellow background

  • Other paragraphs → No yellow background



Use when: You want to style specific elements that share a purpose or style.





Multiple Classes



An element can have multiple classes:




<p class="highlight bold">Text</p>






Target it:




.highlight {
background-color: yellow;
}

.bold {
font-weight: bold;
}






Both styles apply!






Classes vs Elements



Element selector (all paragraphs):




p {
color: blue;
}






Every <p> becomes blue.



Class selector (specific paragraphs):




.highlight {
color: red;
}






Only <p class="highlight"> becomes red.






3. ID Selector



The ID selector targets a single unique element.



Syntax:




#idname {
/* styles */
}






Notice the hash (#) before the ID name.



Example:




#special {
font-size: 20px;
color: red;
}






What this does:

Targets only <p id="special"> and makes it red with larger text.



Result:




  • "This is special." → Red, 20px font

  • Other paragraphs → No change



Important: IDs should be unique. Only ONE element should have a specific ID.





Class vs ID



Class:




  • Use for multiple elements

  • Starts with .

  • Example: class="button"



ID:




  • Use for one unique element

  • Starts with #

  • Example: id="header"



HTML example:




<!-- Multiple elements can share a class -->
<button class="btn">Click</button>
<button class="btn">Submit</button>

<!-- Only one element should have an ID -->
<div id="main-content">...</div>






CSS:




.btn {
background-color: blue;
}

#main-content {
width: 80%;
}









4. Group Selectors



Group selectors let you apply the same styles to multiple selectors.



Syntax:




selector1, selector2, selector3 {
/* styles */
}






Use commas to separate selectors.



Example:




h1, h2, h3 {
color: navy;
font-family: Arial;
}






What this does:

All <h1>, <h2>, and <h3> elements get navy color and Arial font.



Another example:




p, .highlight, #special {
line-height: 1.5;
}






All paragraphs, elements with class "highlight", AND the element with id "special" get line-height of 1.5.



Use when: Multiple different selectors need the same styling.






5. Descendant Selectors



Descendant selectors target elements inside other elements.



Syntax:




parent child {
/* styles */
}






Use a space between selectors.



Example:




div p {
color: green;
}






What this does:

Targets <p> elements that are inside <div> elements.



Given this HTML:




<p>Outside div</p>
<div>
<p>Inside div</p>
</div>






Result:




  • "Outside div" → Not green (not inside a div)

  • "Inside div" → Green (inside a div)






More Examples



Target links inside navigation:




nav a {
color: white;
text-decoration: none;
}






Target paragraphs inside a specific class:




.box p {
font-size: 14px;
}






Deeper nesting:




div ul li {
list-style: square;
}






Targets <li> elements inside <ul> inside <div>.






Combining Selectors



You can combine different selector types for precision.



Class inside element:




div .highlight {
background-color: yellow;
}






Targets elements with class "highlight" inside <div>.



Element with class:




p.highlight {
color: red;
}






Targets <p> elements that have class "highlight" (no space between p and .highlight).



ID inside element:




section #special {
font-weight: bold;
}









Selector Priority (Specificity)



What happens if multiple selectors target the same element?



Simple rule: More specific selector wins.



Priority order (low to high):




  1. Element selectors (p)

  2. Class selectors (.highlight)

  3. ID selectors (#special)



Example:




<p class="text" id="intro">Hello</p>









p {
color: blue;
}

.text {
color: green;
}

#intro {
color: red;
}






Result: Text is red because ID has highest priority.



Simple to remember:




  • ID beats class

  • Class beats element

  • More specific beats less specific






Practical Examples






Example 1: Simple Blog Post






/* All paragraphs */
p {
line-height: 1.6;
color: #333;
}

/* Main heading */
h1 {
font-size: 36px;
color: #000;
}

/* Highlighted quotes */
.quote {
background-color: #f0f0f0;
border-left: 4px solid blue;
padding: 10px;
}

/* Author section */
#author {
font-style: italic;
color: gray;
}









Example 2: Navigation Menu






/* Style all nav links */
nav a {
color: white;
text-decoration: none;
padding: 10px;
}

/* Active link */
.active {
background-color: blue;
}









Example 3: Card Layout






/* All cards */
.card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
}

/* Card titles */
.card h2 {
color: #333;
margin-bottom: 10px;
}

/* Card paragraphs */
.card p {
color: #666;
line-height: 1.5;
}









Before and After Examples



HTML:




<h1>My Website</h1>
<p>Welcome to my site.</p>
<p class="important">This is important!</p>






Before CSS (no styling):




My Website
Welcome to my site.
This is important!






After CSS:




h1 {
color: blue;
font-size: 32px;
}

p {
color: gray;
}

.important {
color: red;
font-weight: bold;
}






Result:




  • "My Website" → Blue, 32px

  • "Welcome to my site." → Gray

  • "This is important!" → Red, bold






Quick Reference












































Selector Syntax Example What it targets
Element tagname p All <p> elements
Class .classname .highlight Elements with class="highlight"
ID #idname #header Element with id="header"
Group sel1, sel2 h1, h2 All h1 AND all h2
Descendant parent child div p
<p> inside <div>





Common Beginner Mistakes



1. Forgetting the dot for classes




/* Wrong */
highlight {
color: red;
}

/* Right */
.highlight {
color: red;
}






2. Forgetting the hash for IDs




/* Wrong */
header {
width: 100%;
}

/* Right */
#header {
width: 100%;
}






3. Using IDs for multiple elements




<!-- Wrong: Same ID used twice -->
<div id="box">Box 1</div>
<div id="box">Box 2</div>

<!-- Right: Use classes -->
<div class="box">Box 1</div>
<div class="box">Box 2</div>









Summary



CSS Selectors = Ways to target HTML elements for styling



Main types:





  • Element → p (all paragraphs)


  • Class → .highlight (elements with that class)


  • ID → #special (one unique element)


  • Group → h1, h2, h3 (multiple selectors)


  • Descendant → div p (p inside div)



Priority:

ID > Class > Element



Remember:




  • Use . for classes

  • Use # for IDs

  • Use space for descendant selectors

  • Use comma for group selectors



Selectors are the foundation of CSS. Master these, and you can style anything!

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - CSS Selectors 101
id: 819b865c-0211-4fea-b11d-e1bb5f84a396
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-27
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-27"
        description = "YARA Signature for "
    strings:
        $str = "CSS Selectors 101" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("CSS Selectors 101")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*CSS Selectors 101*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "CSS Selectors 101"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Analyse für identifizierte Bedrohung auf Basis von Live-CTI (ENISA EUVD): CVSS 0.0 · EPSS 0.0% · CISA KEV: nein. Handlungsableitung aus den verlinkten Hersteller-Quellen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten CSS Selectors 101

Thematisch verwandte Begriffe: Selectors · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100739 | A vulnerability was detected in mathurvishal CloudClassroom-PHP-Project…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag