具有渐变背景的CSS渐变双箭头形状 [英] CSS Gradient double-arrow shape with gradient background

查看:69
本文介绍了具有渐变背景的CSS渐变双箭头形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了以下问题和答案:

解决方案

我将分3个步骤进行操作:

  1. 创建具有背景渐变(例如,从橙色到红色)的普通矩形元素
  2. 创建具有背景色的伪元素 :: before ,渐变从(例如,橙色)开始
  3. 创建具有背景色的伪元素 :: after ,渐变以(例如红色)结尾

现在,您只需要正确放置伪元素并使用 border 属性创建

I saw this question and answer: CSS Gradient arrow shape with inner shadow and gradient border and I'm looking to create the same thing but with an arrow on each side.

Here is what the final result would looks like:

解决方案

I would do it in 3 steps:

  1. create a normal rectangular element with a background gradient (e.g. from orange to red)
  2. create a pseudo element ::before with a background color, the gradient is starting with (e.g. orange)
  3. create a pseudo element ::after with a background color, the gradient is ending with (e.g. red)

Now you just need to position the pseudo elements properly and use the border property to create the triangle shape:

div {
  position: relative;
  display: inline-block;
  text-transform: uppercase;
  color: white;
  height: 3em;
  min-width: 10em;
  line-height: 3em;
  font-family: Arial;
  font-size: 1.5em;
  font-weight: bold;
  text-align: center;
  background: linear-gradient(to right, orange, red);
  padding: 0 1em;
  margin: 0 1em;
}

div::before,
div::after {
  content: '';
  position: absolute;
  height: 0;
  width: 0;
  border-top: 1.5em solid transparent;
  border-bottom: 1.5em solid transparent;
}

div::before {
  left: -1em;
  border-right: 1em solid orange;
}

div::after {
  right: -1em;
  border-left: 1em solid red;
}

<div>Exemple</div>

这篇关于具有渐变背景的CSS渐变双箭头形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆