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

推荐订阅源

D
Docker
博客园 - 【当耐特】
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
Y
Y Combinator Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理

Danb Blog

August 2026: What I've Been Working On · Danb Blog Great Tech: Intel 2500k CPU · Danb Blog July 2026: What I've Been Working On · Danb Blog My Experience with Ubuntu Desktop 26.04 · Danb Blog Thumbnails for Orca 3MF in GNOME Files · Danb Blog Cheaper Sodastream Gas with a Big Tank · Danb Blog June 2026: What I've Been Working On · Danb Blog Running Snyk On Forgejo/Codeberg Actions · Danb Blog Tuta & Proton: An Open Source Client Does Not Result in an Open Source Service · Danb Blog May 2026: What I've Been Working On · Danb Blog 3D Printing Parts for my Greenhouse, Round 2 · Danb Blog Great Devices: Nexus 7 2013 · Danb Blog R36S Console RetroArch Stuck Menu Issue · Danb Blog April 2026: What I've Been Working On · Danb Blog Basic OpenCode Sandboxing with Docker · Danb Blog Games Played in 2025 · Danb Blog March 2026: What I've Been Working On · Danb Blog Shivam Mathur's "node-docker" Images are Awesome for PHP CI · Danb Blog February 2026: What I've Been Working On · Danb Blog Your BookStackApp project was assigned as a project for my Software Architecture course · Danb Blog My Sovol SV08 3D Printer Setup in 2026 · Danb Blog January 2026: What I've Been Working On · Danb Blog Epson Printer: The administrator password you entered was not recognized · Danb Blog Pressure to Follow Process · Danb Blog Online Shopping Email Notifications · Danb Blog My HomeLab Setup in 2026 · Danb Blog Linux Label Printing with the Phomemo D30 · Danb Blog Reporting to the CMA: Google Android Developer Verification · Danb Blog OPNsense & Dnsmasq: Responding with specific DNS servers · Danb Blog An Impromptu Introduction to ZFS Drive Replacement at 1am · Danb Blog
Cat Images in WebP · Danb Blog
2022-01-17 · via Danb Blog

This post is a little test to play around with a few things:

  1. Images in WebP
  2. CSS grid image gallery
  3. CSS only image expand/overlay

View the page source at around this point to see the CSS & HTML used. Below is the bash script used to convert the images from JPEG:

#!/bin/bash
for filepath in ./original/*.jpg
do
filename=$(basename -s ".jpg" "$filepath")
echo $filename
convert "$filepath" -quality 10 -resize '1200' -define webp:lossless=false -define webp:method=6 "./out/$filename.webp"
done

Loaded in are 42 1200px wide images of my cat Ruby, totalling 2.6MB total image filesize. Images are set to lazy-load so they may not all be fetched upon page load. The image expand/overlay functionality is simplistic, just to get something barely functional. Could achieve greater functionality by wrapping each img tag in a div but I wanted to see what I could quickly achieve with a plain list of image tags within a single grid parent.

Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat Ruby cat

Discoveries

WebP works very nicely for photographic images. In the above I used a quality setting of 10% to really get the filesize down, and they've held up quite well. Seems to "break down" in quality in a much more natural way compared to JPEG with more of a blur than a blocky-mess. An average of 61KB per image seems quite reasonable at 1200px wide.

The gallery works on old focus-based tricks with some newer CSS added in. Since it's focused-based you can use tab to traverse the gallery. Grid works nicely to lay out the images with ease using auto-fit repeating columns to adapt the column count. The newer object-fit and aspect-ratio properties are used to fix the images into the square grid without odd blank spaces.

One of the main challenges with the pop-up image view was getting the image somewhat central, while working with a set max-width to not over-stretch the image. This would be easy with a wrapping element but, lacking that here, I found a left position of max(calc((100% - 1200px) / 2), 4vw) to do the trick.

Another challenge was mobile Safari specific. I needed the "Back" button (Shown above the popup image) to take focus away from the selected image. Most browsers did this by default but Safari needed something focusable. I instead had to make the gallery wrapper (Which also contains the button) focusable and then adjust the button CSS selector to .cat-image-grid:focus-within:not(:focus):after to ensure it shows when an image within the grid is focused but not when the grid itself is the focus.

PS. I'm pretty sure these methods are not great for accessibility and there are tweaks and improvements to be made. Again, this was just for playing around and discovering some new techniques.