css家电制作
CSS家电制作方法
使用CSS绘制家电图标或界面元素,可通过纯代码实现矢量图形效果,无需图片资源。以下是常见家电的CSS实现示例:
电风扇
<div class="fan">
<div class="blade"></div>
<div class="blade"></div>
<div class="blade"></div>
<div class="center"></div>
</div>
.fan {
width: 200px;
height: 200px;
position: relative;
border-radius: 50%;
background: #f0f0f0;
}
.blade {
position: absolute;
width: 80px;
height: 30px;
background: #3498db;
top: 50%;
left: 50%;
transform-origin: left center;
}
.blade:nth-child(1) { transform: translate(0, -50%) rotate(0deg); }
.blade:nth-child(2) { transform: translate(0, -50%) rotate(120deg); }
.blade:nth-child(3) { transform: translate(0, -50%) rotate(240deg); }
.center {
position: absolute;
width: 40px;
height: 40px;
background: #2980b9;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
冰箱
<div class="fridge">
<div class="door"></div>
<div class="handle"></div>
</div>
.fridge {
width: 150px;
height: 300px;
background: linear-gradient(to bottom, #ffffff 0%, #e6e6e6 100%);
border: 5px solid #ccc;
border-radius: 10px;
position: relative;
}
.door {
position: absolute;
width: 140px;
height: 290px;
border: 2px solid #aaa;
border-radius: 5px;
}
.handle {
position: absolute;
width: 10px;
height: 50px;
background: #666;
right: 5px;
top: 50%;
transform: translateY(-50%);
}
电视机
<div class="tv">
<div class="screen"></div>
<div class="stand"></div>
</div>
.tv {
width: 250px;
height: 180px;
background: #333;
border-radius: 5px;
position: relative;
}
.screen {
width: 220px;
height: 140px;
background: #1a1a1a;
position: absolute;
top: 10px;
left: 15px;
border: 2px solid #666;
}
.stand {
width: 60px;
height: 10px;
background: #555;
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
}
动画效果实现
为家电添加交互动画,如旋转风扇:
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.fan {
animation: spin 2s linear infinite;
}
响应式调整
使用CSS变量实现尺寸自适应:
:root {
--appliance-size: 200px;
}
.fan {
width: var(--appliance-size);
height: var(--appliance-size);
}
@media (max-width: 600px) {
:root {
--appliance-size: 150px;
}
}
通过组合基本形状(矩形、圆形)、渐变、阴影和变换属性,可以构建各种家电的CSS表示。关键技巧包括合理使用border-radius创建圆角,box-shadow增加立体感,以及transform实现精确的定位和旋转效果。







