html有意思的代码
以下是一些有趣的HTML代码:
用CSS制作的彩虹文字:
<h1 class="rainbow-text">Hello World!</h1>
<style>
.rainbow-text {
background: linear-gradient(to right, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8f00ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>
用CSS制作的动态背景:
<div class="animated-background"></div>
<style>
.animated-background {
background: linear-gradient(to right, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8f00ff);
background-size: 400% 400%;
animation: gradient 15s ease infinite;
}
@keyframes gradient {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
</style>
用CSS制作的3D按钮:
<button class="button-3d">Click Me!</button>
<style>
.button-3d {
background: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.button-3d:after {
content: "";
background: #8BC34A;
display: block;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 0;
z-index: -1;
transition: all 0.3s ease;
}
.button-3d:hover {
background: #8BC34A;
}
.button-3d:hover:after {
width: 100%;
}
</style>
用CSS制作的旋转动画:
<div class="rotate-animation"></div>
<style>
.rotate-animation {
width: 100px;
height: 100px;
background: #4CAF50;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: rotate 2s linear infinite;
}
@keyframes rotate {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}
</style>
用CSS制作的波浪动画:
<div class="wave-animation"></div>
<style>
.wave-animation {
width: 200px;
height: 100px;
background: #4CAF50;
position: relative;
overflow: hidden;
}
.wave-animation:before {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 50px;
background: #8BC34A;
transform: skewY(-12deg);
transform-origin: bottom left;
animation: wave 2s ease-in-out infinite;
}
@keyframes wave {
0% {
transform: skewY(-12deg) translateX(-100%);
}
100% {
transform: skewY(-12deg) translateX(100%);
}
}
</style>
用CSS制作的3D立方体:
<div class="cube">
<div class="face front">Front</div>
<div class="face back">Back</div>
<div class="face left">Left</div>
<div class="face right">Right</div>
<div class="face top">Top</div>
<div class="face bottom">Bottom</div>
</div>
<style>
.cube {
width: 100px;
height: 100px;
position: relative;
transform-style: preserve-3d;
animation: rotate 2s linear infinite;
}
.face {
position: absolute;
width: 100%;
height: 100%;
background: #4CAF50;
color: white;
text-align: center;
line-height: 100px;
font-size: 20px;
font-weight: bold;
}
.front {
transform: translateZ(50px);
}
.back {
transform: translateZ(-50px) rotateY(180deg);
}
.left {
transform: translateX(-50px) rotateY(-90deg);
}
.right {
transform: translateX(50px) rotateY(90deg);
}
.top {
transform: translateY(-50px) rotateX(90deg);
}
.bottom {
transform: translateY(50px) rotateX(-90deg);
}
@keyframes rotate {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(360deg);
}
}
</style>
用CSS制作的滑动菜单:
<div class="menu">
<input type="checkbox" id="toggle">
<label for="toggle">☰</label>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<style>
.menu {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 50px;
background: #4CAF50;
color: white;
z-index: 9999;
}
.menu label {
display: none;
}
.menu ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: flex-end;
align-items: center;
height: 100%;
}
.menu li {
margin: 0 10px;
}
.menu a {
color: white;
text-decoration: none;
font-size: 16px;
}
@media (max-width: 768px) {
.menu ul {
position: fixed;
top: 50px;
left: -100%;
width: 100%;
height: calc(100% - 50px);
background: #4CAF50;
flex-direction: column;
justify-content: center;
align-items: center;
transition: all 0.3s ease;
}
.menu ul li {
margin: 10px 0;
}
.menu ul li a {
font-size: 20px;
}
.menu input:checked ~ ul {
left: 0;
}
.menu label {
display: block;
position: absolute;
top: 0;
right: 10px;
font-_