Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
CSS

CSS: Master Pseudo Elements (::before & ::after)

- 24.07.26 - ErcanOPAK

🎨 Pseudo Elements = Extra Content

Need extra elements without extra HTML? ::before and ::after add content via CSS.

📝 Pseudo Element Basics

/* Basic usage */
.element::before {
    content: "★";
    color: gold;
    margin-right: 5px;
}

.element::after {
    content: " →";
    color: blue;
}

/* Required: content property */
.element::before {
    content: ""; /* Empty for decoration */
    display: block;
    width: 100%;
    height: 2px;
    background: red;
}

/* Text content */
.quote::before {
    content: "\201C"; /* Left quote */
}
.quote::after {
    content: "\201D"; /* Right quote */
}

/* Counters */
.counter::before {
    counter-increment: section;
    content: "Section " counter(section) ": ";
}

/* Images with content */
.icon::before {
    content: url('icon.png');
    display: inline-block;
    width: 16px;
    height: 16px;
}

🎯 Practical Examples

/* Tooltip */
.tooltip {
    position: relative;
}
.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s;
}
.tooltip:hover::after {
    opacity: 1;
}

/* Clearfix */
.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* Required field star */
.required label::after {
    content: " *";
    color: red;
}

/* Decorative border */
.heading::after {
    content: "";
    display: block;
    width: 50px;
    height: 3px;
    background: #3498db;
    margin-top: 10px;
}

/* Quote marks */
blockquote::before {
    content: "\201C";
    font-size: 3em;
    color: #ddd;
    position: absolute;
    left: -20px;
    top: -10px;
}

/* List item markers */
li::before {
    content: "▸";
    color: #3498db;
    margin-right: 8px;
}

/* Pseudo Element Tips */
- Content property is required
- Can use attr() for dynamic content
- Great for decorations and icons
- Use with positioning for complex designs
- Display: block for block-level elements

💡 Pseudo Element Tips

  • Content property is required
  • Can use attr() for dynamic content
  • Great for decorations and icons
  • Use with positioning for complex designs
  • Display: block for block-level elements

“Pseudo elements add content without extra HTML. Essential for clean code.”

— CSS Developer

Related posts:

CSS: Use text-overflow: ellipsis for Truncated Text

CSS: Use :has() Selector to Style Parent Based on Child

CSS: Use Grid auto-fit and minmax for Responsive Layouts Without Media Queries

Post Views: 2

Post navigation

Windows 11: Use Windows Terminal for Modern CLI
HTML: Use ARIA Roles for Better Accessibility

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (624)
  • Add Constraint to SQL Table to ensure email contains @ (590)
  • Average of all values in a column that are not zero in SQL (553)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (526)
  • Find numbers with more than two decimal places in SQL (468)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com