<style> @keyframes fadeIn { 0% { opacity: 0; transform: translateY(20px); } 30% {…
- User
- Assistant
- User
满屏幕掉落心心,可以盖在文本上
- Assistant
满屏幕掉落心心,可以盖在文本上
It looks like you've created a beautiful and animated Valentine's Day promotion banner using HTML and CSS! Your banner features a lovely gradient background, text animations, and falling heart icons that bring an engaging visual effect. Here’s a breakdown of how your code works and some potential tips to make enhancements if desired:
Keyframe Animations:
fadeIn: Controls the opacity and vertical movement of the text elements, creating a soft fading effect.heartDrop: Defines the dropping animation for the heart emojis, making them fall from the top of the banner to the bottom.Promotion Banner Styling:
.promotion-banner class styles the main banner container with a gradient background, border, padding, shadow, and rounded corners to create an aesthetically pleasing look.Text Animations:
<p> tags) is assigned the .text-animation class, which applies the fading effect sequentially via animation-delay to create a staggered visual appeal.Heart Drop Animations:
Accessibility: Ensure that the text content is accessible by adding appropriate ARIA roles or labels for screen readers. You might consider alternatives for emojis for a more text-based approach for those who might have difficulty with interpreting them.
Responsive Design: Check how the banner looks on different screen sizes. Adjust fonts, sizes, and positioning using media queries to enhance experience across devices.
Interactive Elements: You could add a call-to-action button that invites users to shop or learn more about the specials.
Enhanced Animation Control: You could consider pausing the animations on hover, or creating a click event that might reveal more details about the promotion.
If using this code directly in a web application, ensure you encapsulate it within a proper HTML structure. Here’s a full HTML example that incorporates your styles and animations:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Valentine's Day Promotion</title>
<style>
/* Your CSS code here */
</style>
</head>
<body>
<div class="promotion-banner">
<p class="text-animation" style="margin: 5px 0; font-weight: bold; line-height: 1.3;">💕 Valentine's Day Special 💕</p>
<p class="text-animation" style="margin: 5px 0; font-size: 20px; font-weight: bold; line-height: 1.3;">🌹 Buy 2, Get 20% Off 💖</p>
<p class="text-animation" style="margin: 5px 0; font-size: 20px; font-weight: bold; line-height: 1.3;">💌 Buy 3 or More, Get 30% Off 🎁</p>
<div class="heart">❤️</div>
<div class="heart" style="left: calc(30% - 20px); animation-delay: 1s;">❤️</div>
<div class="heart" style="left: calc(70% - 20px); animation-delay: 2s;">❤️</div>
</div>
</body>
</html>
Your animated Valentine's Day banner is well-designed and will surely capture the attention of visitors looking for holiday promotions! Feel free to implement any of the suggested enhancements to maximize its potential.
要实现满屏幕掉落的心形图案,并且让它们盖在文本上,可以利用 CSS 和 JavaScript 动态创建心形元素。我们将用 CSS 创建心形的样式,并使用 JavaScript 控制心形的掉落效果。
以下是一个示例代码,可以将心形动态地添加到页面上,并使它们覆盖在文本上:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>情人节促销活动</title>
<style>
@keyframes fadeIn {
0% { opacity: 0; transform: translateY(20px); }
30% { opacity: 1; transform: translateY(0); }
70% { opacity: 1; transform: translateY(0); }
100% { opacity: 0; transform: translateY(-20px); }
}
.promotion-banner {
position: relative;
background: linear-gradient(to right, #FF69B4, #FFB6C1);
border: 2px solid #FF1493;
padding: 15px;
color: #333;
text-align: center;
margin: 20px 0;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(255, 20, 147, 0.7);
font-family: 'Playfair Display', serif;
overflow: hidden;
z-index: 1; /* 使文本在心形之下 */
}
.text-animation {
display: inline-block;
opacity: 0;
animation: fadeIn 4s ease-in-out infinite;
}
.text-animation:nth-child(1) {
animation-delay: 0s;
font-size: 20px;
}
.text-animation:nth-child(2) {
animation-delay: 1.5s;
font-size: 20px;
}
.text-animation:nth-child(3) {
animation-delay: 3s;
font-size: 20px;
}
.heart {
position: absolute;
top: -50px;
left: calc(50% - 10px);
font-size: 24px;
opacity: 0;
animation: fall 3s linear forwards;
will-change: transform, opacity;
}
@keyframes fall {
to {
transform: translateY(100vh);
opacity: 0;
}
}
</style>
</head>
<body>
<div class="promotion-banner">
<p class="text-animation" style="margin: 5px 0; font-weight: bold; line-height: 1.3;">💕 情人节特别优惠 💕</p>
<p class="text-animation" style="margin: 5px 0; font-size: 20px; font-weight: bold; line-height: 1.3;">🌹 买 2 件,立减 20% 💖</p>
<p class="text-animation" style="margin: 5px 0; font-size: 20px; font-weight: bold; line-height: 1.3;">💌 买 3 件以上,立减 30% 🎁</p>
</div>
<script>
function createHeart() {
const heart = document.createElement('div');
heart.className = 'heart';
heart.innerHTML = '❤️';
// 随机位置
heart.style.left = Math.random() * 100 + 'vw';
heart.style.animationDelay = Math.random() * 2 + 's'; // 随机延迟
document.body.appendChild(heart);
// 删除心形
heart.addEventListener('animationend', () => {
heart.remove();
});
}
// 每 300 毫秒创建一个心形
setInterval(createHeart, 300);
</script>
</body>
</html>
CSS:
.heart 类的样式,包含随机的水平位置和掉落的动画效果。通过 @keyframes fall 来控制心形从顶部到屏幕底部掉落的效果。JavaScript:
createHeart 函数动态创建心形元素,并使用随机位置和随机时间延迟来增强视觉效果。setInterval 每300毫秒生成一个新的心形。层级关系:
.promotion-banner 的 z-index 设置为1,以确保文本在心形元素之上。打开此 HTML 文件时,心形将不断从顶部掉落,并覆盖在文本上,而文本则保持在前面以吸引用户的注意。你可以根据自己的需要调整心形的生成频率和样式。
Not yet included in a published release.