html - 如何在 CSS 和 HTML 中创建价格标签形状

标签 html css css-shapes

所以我找到了这个答案 - CSS3 menu shape, style但不知道如何把它放在左边。我已经搜索过了,但没有找到。

这就是我要实现的目标:

enter image description here

我也找到了这个 - Change the shape of the triangle .我怎样才能让它在对面工作?我的意思是箭头需要在左侧。是否可以用一个 div 来做到这一点?

最佳答案

想要一个可以覆盖任何背景颜色的颜色吗?

simple Price tag shape in css, html

jsBin demo

只有这个 HTML:

<span class="pricetag"></span>

还有这个 CSS:

.pricetag{
    white-space:nowrap;
    position:relative;
    margin:0 5px 0 10px;
    displaY:inline-block;
    height:25px;
    border-radius: 0 5px 5px 0;
    padding: 0 25px 0 15px;
    background:#E8EDF0;
    border: 0 solid #C7D2D4;
    border-top-width:1px;
    border-bottom-width:1px;
    color:#999;
    line-height:23px;
}
.pricetag:after{
    position:absolute;
    right:0;
    margin:1px 7px;
    font-weight:bold;
    font-size:19px;
    content:"\00D7";
}
.pricetag:before{
    position:absolute;
    content:"\25CF";
    color:white;
    text-shadow: 0 0 1px #333;
    font-size:11px;
    line-height:0px;
    text-indent:12px;
    left:-15px;
    width: 1px;
    height:0px;
    border-right:14px solid #E8EDF0;
    border-top:  13px solid transparent;
    border-bottom:  13px solid transparent;
}

基本上遵循这个原则:How to create a ribbon shape in CSS


如果你想在四周添加边框:

enter image description here

jsBin demo with transform: rotate(45deg) applied to the :before pseudo

.pricetag{
    white-space:nowrap;
    position:relative;
    margin:0 5px 0 10px;
    displaY:inline-block;
    height:25px;
    border-radius: 0 5px 5px 0;
    padding: 0 25px 0 15px;
    background:#E8EDF0;
    border: 1px solid #C7D2D4;
    color:#999;
    line-height:23px;
}
.pricetag:after{
    position:absolute;
    right:0;
    margin:1px 7px;
    font-weight:bold;
    font-size:19px;
    content:"\00D7";
}
.pricetag:before{
    position:absolute;
    background:#E8EDF0;
    content:"\25CF";
    color:white;
    text-shadow: 0 0 1px #aaa;
    font-size:12px;
    line-height:13px;
    text-indent:6px;
    top:3px;
    left:-10px;
    width: 18px;
    height: 18px;
    transform: rotate(45deg);
    border-left:1px solid #C7D2D4;
    border-bottom:1px solid #C7D2D4;
}

关于html - 如何在 CSS 和 HTML 中创建价格标签形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25195526/

相关文章:

html - Bootstrap 4、嵌套表格、文本环绕图像

css - Bootstrap 进度条圆圈不响应所有设计

html - 边框半径 CSS3

javascript - jQuery 更改保存在变量中的 html 值

javascript - HTML5 Javascript FileReader - 将数据提取到父函数中

javascript - 动态启用和禁用必填字段

html - 如何将两个 div 元素放在一行中?

javascript - 文档.querySelector (".class h1")

html - 如何创建这个倒置的两层边框?

css - 背景图片,线性渐变锯齿状边缘结果需要平滑边缘