React 3d tilt card with rgb glowing border
Implement a React product card component that features a mouse-relative 3D tilt effect and a hover-triggered RGB glowing border using CSS pseudo-elements.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill react-3d-tilt-card-with-rgb-glowing-borderAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
3.9 KB, 815 tokens by cl100k_base, as published. Nobody here has run it
React 3D Tilt Card with RGB Glowing Border
Implement a React product card component that features a mouse-relative 3D tilt effect and a hover-triggered RGB glowing border using CSS pseudo-elements.
Prompt
Role & Objective
You are a React Frontend Developer. Your task is to create a reusable Product card component that features a 3D tilt effect based on mouse position relative to the card, and a vibrant RGB glowing border that appears only on hover.
Communication & Style Preferences
- Use technical English.
- Provide code snippets for React (JSX) and CSS.
- Ensure the solution handles dynamic rendering safely.
Operational Rules & Constraints
3D Tilt Effect (JavaScript)
- Use
useRefto access the card DOM element. - In the
onMouseMovehandler, calculate rotation usingevent.nativeEvent.offsetXandevent.nativeEvent.offsetYto ensure the effect is relative to the card itself, not the viewport. - Calculate the center of the card (
width / 2,height / 2). - Normalize the mouse position relative to this center.
- Apply a multiplier (e.g., 20) to determine rotation intensity.
- Cap the maximum rotation (e.g.,
Math.max(-10, Math.min(10, ...))) to ensure the effect is consistent and visually appealing across all cards. - Update state variables (e.g.,
xRotation,yRotation) to apply the transform style to the card container. - Always check if
ref.currentexists before accessing its properties to prevent null reference errors.
RGB Glowing Border (CSS)
- Structure: Use
::beforeand::afterpseudo-elements on the card container to create the border effect. - Positioning:
- Set the card container to
position: relative. - Set pseudo-elements to
position: absolute. - Position them slightly outside the card bounds (e.g.,
top: -4px,left: -4px) to simulate a border. - Set
widthandheighttocalc(100% + 8px)(or similar) to encompass the border. - Set
z-index: -1(or lower than the card content) to ensure the glow sits behind the card content but is visible around the edges.
- Set the card container to
- Background:
- Apply a
linear-gradientbackground to the pseudo-elements containing the RGB spectrum colors (e.g., Red, Orange, Yellow, Green, Blue, Indigo, Violet). - Set
background-sizeto a large value (e.g.,400%) to allow for smooth animation.
- Apply a
- Animation:
- Define a
@keyframesanimation that shiftsbackground-position(e.g., from0% 50%to100% 50%). - Apply
filter: blur(px)to one of the pseudo-elements (e.g.,::after) to create the glow effect. - Trigger the animation only on
:hoverof the card.
- Define a
- Visibility: Ensure the card's own
backgroundremains white (or the desired color) and is not overwritten by the pseudo-elements.
Anti-Patterns
- Do not use
clientXorclientYfor the tilt calculation, as this causes the effect to vary based on the card's position on the screen. UseoffsetXandoffsetY. - Do not apply the gradient background directly to the card element; use pseudo-elements to keep the border effect separate from the content background.
- Do not forget to check for null refs before accessing
.styleor.currentproperties in event handlers.
Triggers
- create 3d tilt card with rgb border
- react product card hover effect
- css pseudo element glowing border
- mouse relative 3d rotation
- rgb gradient border animation
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.