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

React卡片背景不显示问题:添加指定CSS动画代码后卡片背景变为透明

Fixing Transparent Card Backgrounds When Adding CSS Animation

Hey Maryam, I see exactly what's going on with your restaurant card backgrounds turning transparent once you add that stars/twinkling/clouds animation code. Let's break down the issue and fix it right away:

What's Causing the Problem

The CSS snippet you added for .stars, .twinkling, .clouds sets these elements to position:absolute and stretches them to fill their parent container (using top:0; left:0; right:0; bottom:0;). If these animation elements are nested inside your food card components, they're covering the entire card area. Since these elements don't have their own background color, they appear transparent and end up blocking or overriding the card's original background—making it look like the card itself is see-through.

Quick Fixes to Try

1. Push Animation Elements to the Background Layer

Add a z-index: -1; property to the animation CSS. This will send them behind the card's content and background, so they don't interfere with the card's visibility:

.stars, .twinkling, .clouds {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  width:100%;
  height:2400px;
  display:block;
  z-index: -1; /* Move animations behind card content */
}

Just double-check that your food card container has position: relative; set—this ensures the absolute positioning works relative to the card, and the z-index adjustment takes effect properly.

2. Relocate Animations to the Page Level (If They're Full-Page)

If this star/twinkle effect is meant to be a full-page background (not per-card), move the .stars, .twinkling, and .clouds elements out of your card components and place them directly inside the <body> tag. This way, they'll act as the page's background without messing with individual card styles at all.

Verify the Fix

After making either change, hover over your food images again—you should see the food details pop up as expected, with the card background staying visible just like your first (working) screenshot.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 10:29:08