-1
带状徽章我有一个小盒子,用斜角,看起来像这样:创建CSS
的斜角与这个片段的帮助下完成的:https://codepen.io/myf/pen/FLzva。但是为了以防万一链接死了,我会在这里把我的SCSS代码:
.product-info {
position: relative;
padding: $spacer * .5;
padding-right: $spacer * 2;
overflow: hidden;
&-link {
display: block;
a {
color: $gray-dark;
transition: color $animation-fast;
&:hover {
color: $brand-primary;
text-decoration: none;
}
}
}
&-price {
color: $brand-primary;
}
&:before,
&:after {
position: absolute;
content: "";
left: 0;
z-index: -1;
background-color: $gray-lighter;
border-color: $gray-lighter;
}
&:before {
top: 0;
right: 0;
bottom: 35px;
}
&:after {
top: auto;
right: -5px;
bottom: 0;
border-style: solid;
border-width: 35px 35px 0 0;
background-color: transparent;
border-right-color: transparent;
}
}
我现在需要能够将徽章加入此框。我想过用数据属性来做这件事。 <div class="product-info" data-badge="New">...</div>
并且如果div.product-info
具有数据属性,则徽章将出现。徽章必须是这样的:
我不知道如何实现这一目标,很遗憾。向正确的方向推动将不胜感激!
如果你看看其中的一些,有些类似应该让你去https://codepen.io/tag/ribbon/ –
你尝试过什么吗? – DaniP
@DarrenSweeney谢谢,会看看! –