当前位置:首页 > CSS

css制作笑脸

2026-04-01 05:48:15CSS

使用CSS制作笑脸

使用CSS的border-radiustransform属性可以轻松绘制一个简单的笑脸。以下是一个完整的实现方法:

HTML结构

<div class="smiley">
  <div class="eyes">
    <div class="eye left"></div>
    <div class="eye right"></div>
  </div>
  <div class="mouth"></div>
</div>

CSS样式

.smiley {
  width: 200px;
  height: 200px;
  background-color: #FFD700;
  border-radius: 50%;
  position: relative;
  margin: 50px auto;
}

.eye {
  width: 30px;
  height: 40px;
  background: #000;
  border-radius: 50%;
  position: absolute;
  top: 50px;
}

.left { left: 50px; }
.right { right: 50px; }

.mouth {
  width: 100px;
  height: 50px;
  border-bottom: 5px solid #000;
  border-radius: 0 0 50px 50px;
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
}

制作动画笑脸

为笑脸添加简单的动画效果,使其更生动:

.mouth {
  /* 原有样式 */
  transition: all 0.3s ease;
}

.smiley:hover .mouth {
  height: 30px;
  border-radius: 50px 50px 0 0;
  border-bottom: none;
  border-top: 5px solid #000;
}

使用伪元素简化结构

可以通过伪元素减少HTML标记:

<div class="smiley"></div>
.smiley::before,
.smiley::after {
  content: '';
  width: 30px;
  height: 40px;
  background: #000;
  border-radius: 50%;
  position: absolute;
  top: 50px;
}

.smiley::before { left: 50px; }
.smiley::after { right: 50px; }

响应式笑脸

添加媒体查询使笑脸适应不同屏幕尺寸:

css制作笑脸

@media (max-width: 600px) {
  .smiley {
    width: 150px;
    height: 150px;
  }

  .eye {
    width: 20px;
    height: 30px;
    top: 40px;
  }

  .left { left: 40px; }
  .right { right: 40px; }

  .mouth {
    width: 80px;
    bottom: 30px;
  }
}

标签: 笑脸css
分享给朋友:

相关文章

vue制作css

vue制作css

在Vue中制作CSS的方法 Vue提供了多种灵活的方式来编写和管理CSS,可以根据项目需求选择适合的方法。 使用内联样式 内联样式可以直接在Vue组件的模板中编写,适用于简单的样式需求。 <…

css下拉框制作

css下拉框制作

使用原生HTML和CSS制作下拉框 HTML的<select>元素结合CSS可以创建基础下拉框: <select class="custom-dropdown"> <…

css制作流程图

css制作流程图

使用CSS制作流程图的方法 基础布局结构 采用HTML的<div>元素构建流程节点,结合CSS的flexbox或grid布局实现整体排列。节点间用伪元素或独立元素(如<span>…

css尾部制作

css尾部制作

如何制作CSS尾部(页脚) 固定定位法 将页脚固定在页面底部,无论内容多少。使用position: fixed结合bottom: 0实现: footer { position: fixed;…

css制作三角形

css制作三角形

使用边框制作三角形 通过设置元素的宽度和高度为0,并利用边框属性,可以创建不同方向的三角形。例如,要创建一个向下的三角形: .triangle-down { width: 0; height…

css如何制作圆

css如何制作圆

使用 border-radius 属性 通过设置 border-radius 属性可以轻松创建圆角或圆形元素。值为 50% 时,元素会呈现为圆形。 .circle { width: 100p…