表白爱心html代码
时间: 2023-11-30 16:43:13 浏览: 72
html语言爱心表白代码
以下是基于JavaScript实现的两套表白爱心HTML代码,你可以根据自己的需求选择其中一套使用:
第一套:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表白爱心</title>
<style>
body {
background-color: #f8f8f8;
}
.love {
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
width: 200px;
height: 200px;
background-color: #f00;
transform: rotate(45deg);
}
.love:before,
.love:after {
content: "";
position: absolute;
width: 200px;
height: 200px;
background-color: #f00;
}
.love:before {
top: -100px;
left: 0;
}
.love:after {
top: 0;
left: -100px;
}
</style>
</head>
<body>
<div class="love"></div>
<script>
document.onclick = function() {
var love = document.createElement("div");
love.className = "love";
document.body.appendChild(love);
setTimeout(function() {
document.body.removeChild(love);
}, 1000);
}
</script>
</body>
</html>
```
第二套:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表白爱心</title>
<style>
body {
background-color: #f8f8f8;
}
.love {
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
width: 200px;
height: 200px;
background-color: #f00;
transform: rotate(45deg);
animation: love 1s ease-in-out infinite;
}
.love:before,
.love:after {
content: "";
position: absolute;
width: 200px;
height: 200px;
background-color: #f00;
}
.love:before {
top: -100px;
left: 0;
}
.love:after {
top: 0;
left: -100px;
}
@keyframes love {
0% {
transform: rotate(45deg) scale(1);
}
20% {
transform: rotate(45deg) scale(1.2);
}
40% {
transform: rotate(45deg) scale(1);
}
}
</style>
</head>
<body>
<div class="love"></div>
</body>
</html>
```
阅读全文