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

推荐订阅源

Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
I
InfoQ
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
月光博客
月光博客
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
G
Google Developers Blog
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI
V
Visual Studio 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
Stop Using JS for Everything: Harnessing the Power of Pur...
Zil Norvilis · 2026-06-03 · via DEV Community

I remember when building a simple dropdown menu or a sticky header required a library like jQuery. Later, we moved to writing Stimulus controllers or React hooks for every single tiny interaction on the screen.

As a developer, my instinct was always: "If it moves, write JavaScript."

But in 2026, the browser has changed. CSS has evolved so much that many of the things we used to do in JS are now built natively into the stylesheet. Moving this logic to CSS isn't just about being "cool" - it makes your site significantly faster, reduces "layout shift," and means you have less code to maintain.

Here is how I’ve started replacing JavaScript with pure CSS in my Rails 8 projects.

1. The "Parent" Selector (:has)

For decades, we wanted a way to style an element based on what was inside it.

The Old Way (JS):
You would write a script to check if a checkbox was ticked, then add a class like .is-active to the parent container.

The 2026 Way (CSS):
We now have the :has() selector. It is a game-changer.

/* Style the card only if it contains a checked checkbox */
.card:has(input[type="checkbox"]:checked) {
  background-color: #f0fdf4;
  border-color: #22c55e;
}

This replaces hundreds of lines of "state-toggling" JavaScript. You can use it for form validation, menu states, and complex grid layouts.

2. Native Popovers (The popover Attribute)

Tooltips and dropdowns are usually the first things people use JavaScript for. In 2026, we don't need a JS library for this anymore.

The Modern Way:
You use the HTML popover attribute and target it with CSS.

<button popovertarget="my-menu">Open Menu</button>

<div id="my-menu" popover class="p-4 rounded-lg shadow-xl">
  <p>This is a pure CSS/HTML dropdown!</p>
</div>

With zero lines of JavaScript, the browser automatically handles:

  • Showing/hiding the element.
  • "Light dismiss" (closing when you click outside).
  • Putting the menu on the "top layer" so it isn't cut off by parent containers.

3. Container Queries (No more JS Resize Listeners)

We used to use JavaScript ResizeObserver to change a component's layout if its container got too small (like a sidebar moving to the bottom).

The 2026 Way:
Container queries allow an element to style itself based on its own size, not the size of the whole browser window.

.card-container {
  container-type: inline-size;
}

@container (max-width: 400px) {
  .card {
    flex-direction: column;
    padding: 1rem;
  }
}

This is perfect for Rails developers using ViewComponents. Your component can now be "smart" and responsive no matter where you drop it in your layout.

4. Scroll-Driven Animations

I used to hate writing JS scroll listeners. They are terrible for performance and often feel "janky" on mobile phones.

In 2026, we can link animations directly to the scroll position using pure CSS. Want a progress bar at the top of your blog post?

@keyframes grow-progress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.progress-bar {
  animation: grow-progress auto linear;
  animation-timeline: scroll();
}

The browser handles the math. It is buttery smooth and consumes zero CPU cycles compared to a JS scroll event.

5. Native Smooth Scrolling and Snap

If you are building a landing page with a carousel or a "back to top" button, you might be tempted to use a JS library.

Don't.

html {
  scroll-behavior: smooth;
}

.carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.carousel-item {
  scroll-snap-align: center;
}

This gives you that premium, "app-like" sliding feel natively.

Summary: Why this matters for Rails 8

When we use Hotwire and Turbo, we want to keep the "State" on the server as much as possible. Every time we add a custom Stimulus controller for a tiny UI animation, we are adding "Client-side State" that we have to manage.

By using these 2026 CSS features:

  1. Your HTML is cleaner.
  2. Your JavaScript bundle is smaller.
  3. Your UX is more resilient (CSS doesn't "crash" like JS does).

Next time you are about to run rails generate stimulus, ask yourself: "Can I do this with :has() or a container query instead?" Most of the time, the answer is now yes.