当前位置:首页 > CSS

css制作加号按钮

2026-02-13 11:36:22CSS

使用伪元素实现加号按钮

通过CSS的::before::after伪元素创建横竖两条线,组合成加号形状。这种方法无需额外HTML元素,兼容性良好。

.plus-btn {
  width: 40px;
  height: 40px;
  position: relative;
  background: #3498db;
  border-radius: 4px;
  cursor: pointer;
}

.plus-btn::before,
.plus-btn::after {
  content: "";
  position: absolute;
  background: white;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.plus-btn::before {
  width: 60%;
  height: 4px;
}

.plus-btn::after {
  width: 4px;
  height: 60%;
}

使用边框旋转实现加号

通过旋转45度并叠加两个矩形边框来创建加号效果。这种方法适合需要动态旋转效果的场景。

.plus-icon {
  width: 20px;
  height: 20px;
  position: relative;
}

.plus-icon:before, 
.plus-icon:after {
  content: "";
  position: absolute;
  background: #000;
}

.plus-icon:before {
  left: 50%;
  margin-left: -1px;
  width: 2px;
  height: 100%;
}

.plus-icon:after {
  top: 50%;
  margin-top: -1px;
  height: 2px;
  width: 100%;
}

SVG实现矢量加号

使用内联SVG创建可缩放的矢量加号,适合高分辨率显示需求。

<button class="svg-plus">
  <svg viewBox="0 0 24 24" width="24" height="24">
    <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" fill="currentColor"/>
  </svg>
</button>
.svg-plus {
  background: transparent;
  border: none;
  padding: 8px;
  color: #2c3e50;
  cursor: pointer;
}

.svg-plus:hover {
  color: #e74c3c;
}

纯Unicode符号方案

最简单的实现方式,使用Unicode加号字符,适合快速原型开发。

<button class="unicode-plus">+</button>
.unicode-plus {
  width: 40px;
  height: 40px;
  font-size: 24px;
  line-height: 40px;
  text-align: center;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

交互动画效果

为加号按钮添加点击动画,提升用户体验。

css制作加号按钮

.animated-plus {
  width: 50px;
  height: 50px;
  background: #9b59b6;
  position: relative;
  border-radius: 50%;
  transition: all 0.3s;
}

.animated-plus::before,
.animated-plus::after {
  content: "";
  position: absolute;
  background: white;
  transition: all 0.3s;
}

.animated-plus::before {
  width: 24px;
  height: 4px;
  left: 13px;
  top: 23px;
}

.animated-plus::after {
  width: 4px;
  height: 24px;
  left: 23px;
  top: 13px;
}

.animated-plus:hover {
  transform: scale(1.1);
  background: #8e44ad;
}

.animated-plus:active {
  transform: scale(0.9);
}

标签: 加号按钮
分享给朋友:

相关文章

vue实现单选按钮

vue实现单选按钮

实现单选按钮的基本方法 在Vue中实现单选按钮通常使用v-model指令绑定数据,结合input元素的type="radio"属性。以下是一个基础示例: <template> <…

vue实现按钮控制

vue实现按钮控制

Vue 实现按钮控制的方法 在 Vue 中实现按钮控制可以通过多种方式,包括禁用按钮、动态样式、条件渲染等。以下是几种常见的方法: 使用 v-bind:disabled 控制按钮禁用状态 通过绑定…

vue实现点击按钮

vue实现点击按钮

实现点击按钮的基本方法 在Vue中实现点击按钮功能可以通过v-on指令或@语法糖绑定事件。以下是一个基础示例: <template> <button @click="handl…

react如何点击按钮动态渲染

react如何点击按钮动态渲染

动态渲染的实现方法 在React中,通过点击按钮动态渲染内容通常需要结合状态管理(useState)和事件处理。以下是几种常见场景的实现方式: 条件渲染组件 通过状态控制是否渲染特定组件: imp…

react如何点击按钮保存图片

react如何点击按钮保存图片

使用HTML5的<a>标签下载 在React中,可以通过创建一个隐藏的<a>标签并模拟点击来实现图片下载。将图片URL或Base64数据作为href,设置download属性指…

css 按钮制作

css 按钮制作

基础按钮样式 使用CSS制作基础按钮需要定义background-color、color、padding和border-radius等属性。以下是一个简单的按钮样式示例: .button { b…