You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅用CSS实现鼠标悬停.tags元素时旁侧显示指定图片?

Pure CSS Solution for Hover-to-Show Aligned Image on .tags Elements

Got it, since you're stuck using only user stylesheets, we can make this work with pure CSS—no JavaScript or HTML edits needed. Here's a straightforward approach tailored to your needs:

Core Concept

We’ll use the ::after pseudo-element attached to your .tags cells to embed the legend image. By default, this element stays hidden; when someone hovers over a .tags cell, we’ll toggle it visible and position it perfectly aligned next to the target cell.

Full CSS Code

/* Anchor the pseudo-element to the .tags cell */
.tags {
  position: relative;
}

/* Create the hidden image container */
.tags::after {
  content: '';
  /* Keep hidden by default */
  display: none;
  /* Position relative to the parent .tags cell */
  position: absolute;
  /* Align to the top-right edge of the cell (adjust values as needed) */
  top: 0;
  left: calc(100% + 8px); /* Add a small gap between cell and image */
  /* Match your image's native dimensions (tweak if your image is different) */
  width: 320px;
  height: 240px;
  /* Load and scale the image properly */
  background-image: url('https://mal-stats.glitch.me/tagslegend.png');
  background-size: contain;
  background-repeat: no-repeat;
  /* Ensure the image sits above other page content */
  z-index: 10;
}

/* Show the image when hovering over the .tags cell */
.tags:hover::after {
  display: block;
}

Quick Adjustments for Perfect Alignment

  • Vertical Centering: If you want the image to align vertically with the cell, replace top: 0; with top: 50%; transform: translateY(-50%);.
  • Gap Size: Modify the 8px value in left: calc(100% + 8px); to make the space between the cell and image larger or smaller.
  • Image Scaling: Use width: auto; height: 100%; instead of fixed dimensions if you want the image to scale with the cell’s height.

This works entirely within user stylesheets, so you can drop it into your browser’s custom CSS tool (like Stylus, Stylish, or Firefox’s userContent.css) and it’ll behave exactly as you need.

内容的提问来源于stack exchange,提问作者user3310334

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:32:55