当前位置:首页 > 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;
}

交互动画效果

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

.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);
}

css制作加号按钮

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

相关文章

css 制作按钮

css 制作按钮

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

css制作按钮

css制作按钮

基础按钮样式 创建一个基础的CSS按钮样式,可以通过以下代码实现。这个例子包含了按钮的基本属性,如背景色、边框、内边距和文字样式。 .button { background-color: #4C…

vue实现按钮组轮换

vue实现按钮组轮换

Vue 实现按钮组轮换的方法 在 Vue 中实现按钮组轮换功能,可以通过动态绑定数据和事件处理来实现。以下是几种常见的方法: 使用 v-for 动态渲染按钮组 通过 v-for 指令动态渲染按钮组…

css 制作按钮

css 制作按钮

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

vue实现按钮滑动

vue实现按钮滑动

Vue 实现按钮滑动效果 使用 CSS 过渡动画 在 Vue 模板中定义一个按钮元素,通过 CSS 的 transition 和 transform 属性实现滑动效果。利用 Vue 的 v-bind:…

vue实现移动按钮

vue实现移动按钮

Vue 实现移动按钮的方法 使用拖拽事件实现按钮移动 在Vue中可以通过监听拖拽事件来实现按钮的移动功能。需要利用@mousedown、@mousemove和@mouseup事件。 <tem…