惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
WordPress大学
WordPress大学
B
Blog RSS Feed
A
About on SuperTechFans
V
Visual Studio Blog
J
Java Code Geeks
U
Unit 42
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
IT之家
IT之家
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
C
Check Point Blog
博客园 - 叶小钗
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
B
Blog
S
SegmentFault 最新的问题
Microsoft Azure Blog
Microsoft Azure Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Media Queries, Transitions, Positions, and Units (rem vs ...
Ezhil Abinaya K · 2026-05-27 · via DEV Community
Cover image for Media Queries, Transitions, Positions, and Units (rem vs em) Explained

Ezhil Abinaya K

Media Queries: Making Web Pages Responsive
A Media Query is a CSS technique used to apply specific styles only when certain conditions are met, such as a user's screen size, resolution, or orientation. It is the backbone of Responsive Web Design.

/* Default style for mobile screens */
body {
  background-color: white;
  font-size: 14px;
}

/* Style applied ONLY when the screen is 768px wide or larger (Tablets/Desktops) */
@media (min-width: 768px) {
  body {
    background-color: lightblue;
    font-size: 18px;
  }
}

Transitions
A Transition allows you to change property values smoothly over a specified duration, instead of having the change happen instantly. It makes user interactions (like hovering over a button) feel professional and polished.
The 4 Main Properties

  • transition-property: The name of the CSS property you want to animate (e.g., background-color).
  • transition-duration: How long the animation takes (e.g., 0.3s).
  • transition-timing-function: The speed curve of the effect (e.g., ease-in-out).
  • transition-delay: A pause before the animation starts.
.btn {
  background-color: blue;
  color: white;
  padding: 10px 20px;
  transition: background-color 0.3s ease;
}
.btn:hover {
  background-color: darkblue;
}

Position
The position property defines how an element is positioned on the web page. There are five main positioning types:
The Five Positioning Types

1. Static: The default value. Elements follow the normal page flow. Top/bottom/left/right properties have no effect.
2. Relative: Positioned relative to its original, normal position. Moving it doesn't affect surrounding elements.
3. Absolute: Positioned relative to its nearest positioned ancestor (an ancestor with absolute, relative, or fixed position). It is completely removed from the normal page flow.
4. Fixed: Positioned relative to the browser viewport window. It stays in the exact same place even when you scroll (like a sticky chat widget).
5. Sticky: Toggles between relative and fixed depending on the user's scroll position (perfect for navigation bars).

.parent-box {
  position: relative; /* Acts as an anchor for the absolute child */
  width: 300px;
  height: 300px;
}

.child-badge {
  position: absolute;
  top: 10px;
  right: 10px; /* Sits perfectly in the top-right corner of the parent */
}

rem vs em
Both rem and em are relative units used for sizing fonts, padding, margins, and layouts. They are much better for accessibility than fixed px (pixels).
- rem (Root EM): Relative strictly to the root element's font size (the <html> tag). If the root font size is 16px, then 1rem = 16px, and 2rem = 32px. It remains consistent everywhere.
- em: Relative to the font size of its immediate parent element (or the element itself when used for margins/padding). It cascades and can compound.

html {
  font-size: 16px; /* Root size */
}

.parent {
  font-size: 20px;
}

.child-one {
  font-size: 2rem; /* 2 x 16px = 32px (Ignores parent, looks at root) */
}

.child-two {
  font-size: 2em;  /* 2 x 20px = 40px (Looks at parent font size) */
}