纯CSS标签div,带有圆角三角形指针

如何解决纯CSS标签div,带有圆角三角形指针

我正在寻求以购物标签的形状创建一个div,并且已经走得很远了,但是我想通过在顶点处以及混合到标签之前四舍五入三角形指针来使其像素完美。

enter image description here

更多细节

enter image description here

想要,这里的圆角类型:

enter image description here

如果我能在某个地方得到一个小白点(我尝试过运气:“·”,运气不佳),奖励积分。

我已经查看了圆角三角形上的stackoverflow项目,因此这似乎可行,但是它们都是独立的三角形,未添加到div的末尾。而且我正在尝试不在矩形div旁边制作一个独立的三角形。

谢谢您的任何想法!

curl -d param1=value1 -d param2=value2 -H "Content-Type: application/json" -X POST http://localhost/<path>
.tag {
  background-color: red;
  border-radius: 0 3px 3px 0;
  color: #fff;
  display: inline-block;
  font-family: verdana;
  font-size: 12px;
  height: auto;
  line-height: 12px;
  margin-left: 9px;
  padding: 3px 6px 3px 3px;
  position: relative;
}

.tag:before {
  content: "";
  line-height: 6px;
  position: absolute;
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 9px solid #f00;
  top: 0;
  left: -9px;
}

---建议后编辑---

<div class="tag">hello</div>
.tag {
    background-color: red;
    border-radius: 0 3px 3px 0;
    clip-path: polygon(10px 0,100% 0,100% 100%,10px 100%,0 50%);
    color: #fff;
    display: inline-block;
    font-family: verdana;
    font-size: 12px;
    filter: url('#goo');
    height: auto;
    line-height: 12px;
    margin-left: 15px;
    padding: 3px 12px 3px 15px;
    position: relative;
}

那里看起来很近,而且这个点有点舍入。但是通向矩形的边缘仍然很锐利,并且现在已经在标签的右侧进行了很大的倒圆角处理。我猜需要调整模糊值,所以我现在朝那个方向看,尽管这对我来说是一个新话题。

解决方法

您可以将clip-path用于形状,将SVG滤镜用于圆角(调整stdDeviation以控制半径),并为点使用渐变色:

.box {
  display: inline-block;
  filter: url('#goo');
}

.box div {
  margin: 10px;
  padding: 20px 40px 20px 20px;
  font-size: 35px;
  font-weight: bold;
  font-family: sans-serif;
  color:#fff;
  transform-origin: right center;
  transform:rotate(-45deg);
  background: 
    radial-gradient(8px at calc(100% - 20px) 50%,#fff 99%,transparent),/* the dot */
    linear-gradient(60deg,red,orange); /* gradient coloration */
  clip-path: polygon(0 0,calc(100% - 30px) 0,100% 50%,calc(100% - 30px) 100%,0 100%);
}
<div class="box">
  <div>SALE</div>
</div>

<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
    <defs>
        <filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur" />    
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="goo" />
            <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
        </filter>
    </defs>
</svg>

使用遮罩在点内具有透明度:

.box {
  display: inline-block;
  filter: url('#goo');
}

.box div {
  margin: 10px;
  padding: 20px 40px 20px 20px;
  font-size: 35px;
  font-weight: bold;
  font-family: sans-serif;
  color:#fff;
  transform-origin: right center;
  transform:rotate(-45deg);
  -webkit-mask: radial-gradient(9px at calc(100% - 20px) 50%,transparent 99%,#fff);
  background:linear-gradient(60deg,0 100%);
}

body {
  background:linear-gradient(to right,#888,#fff);
}
<div class="box">
  <div>SALE</div>
</div>

<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
    <defs>
        <filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur" />    
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="goo" />
            <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
        </filter>
    </defs>
</svg>

,

基于上述Temani的回答,它使我想到了:before的背景和旋​​转方式,以及剪辑:before元素的能力。因此,我只是在其前面放一个盒子,给它一些边界半径,将其旋转成菱形,然后将其正确地放置在标签上。哇!

我也可以使用剪切路径去除菱形的右侧,但就我而言,我不需要。

.tag {
    background-color: red;
    border-radius: 0 3px 3px 0;
    color: #fff;
    display: inline-block;
    font-family: verdana;
    font-size: 12px;
    font-weight: 300;
    height: auto;
    line-height: 12px;
    margin-left: 15px;
    padding: 5px 6px 3px 12px;
    position: relative;
}

.tag:before {
    background: red radial-gradient(2px at 8px 50%,transparent);
    content: "";
    height: 16px;
    width: 16px;
    position: absolute;
    border-radius: 4px 3px;
    top: 2px;
    transform: rotate(45deg);
    left: -7px;
}
<div class="tag">Hello</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-