gpt4 book ai didi

css - 如何将 CSS Ribbon Generator 代码用于特定特色图片

转载 作者:行者123 更新时间:2023-11-27 23:56:02 25 4
gpt4 key购买 nike

我想使用 CSS Ribbon Generator 中的这段代码,但只需要它用于某些特色图片 - 不是全部。

我有 CSS 和 HTML。目前尚不清楚我会将 HTML 包含在我的子主题中以使 CSS 正常工作的文件。

我只想要某些特色图片的色带。我见过的所有插件都已过时。

.box {
width: 200px; height: 300px;
position: relative;
border: 1px solid #BBB;
background: #EEE;
}
.ribbon {
position: absolute;
right: -5px; top: -5px;
z-index: 1;
overflow: hidden;
width: 75px; height: 75px;
text-align: right;
}
.ribbon span {
font-size: 10px;
font-weight: bold;
color: #FFF;
text-transform: uppercase;
text-align: center;
line-height: 20px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
width: 100px;
display: block;
background: #79A70A;
background: linear-gradient(#F70505 0%, #8F0808 100%);
box-shadow: 0 3px 10px -5px rgba(0, 0, 0, 1);
position: absolute;
top: 19px; right: -21px;
}
.ribbon span::before {
content: "";
position: absolute; left: 0px; top: 100%;
z-index: -1;
border-left: 3px solid #8F0808;
border-right: 3px solid transparent;
border-bottom: 3px solid transparent;
border-top: 3px solid #8F0808;
}
.ribbon span::after {
content: "";
position: absolute; right: 0px; top: 100%;
z-index: -1;
border-left: 3px solid transparent;
border-right: 3px solid #8F0808;
border-bottom: 3px solid transparent;
border-top: 3px solid #8F0808;
}
<div class="box">
<div class="ribbon"><span>PREMIUM</span></div>
</div>

如何添加此代码以用于特定特色图片以及我应将 HTML 代码放入哪个文件以使 CSS 起作用?

最佳答案

您可以通过将特定图像与其他图像分开来设置仅在特定图像上使用功能区,然后使用 JS 仅将功能区添加到满足特定条件的图像。

我在这里使用 featured 类将图像与其他图像分开,然后使用 javascript 将 ribbon 类添加到这些图像。

let feat = document.querySelectorAll('.featured')
feat.forEach((img)=>{
img.classList.add('ribbon')
})
.box {
width: 200px; height: 300px;
position: relative;
border: 1px solid #BBB;
background: #EEE;
}
.ribbon {
position: absolute;
right: -5px; top: -5px;
z-index: 1;
overflow: hidden;
width: 75px; height: 75px;
text-align: right;
}
.ribbon span {
font-size: 10px;
font-weight: bold;
color: #FFF;
text-transform: uppercase;
text-align: center;
line-height: 20px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
width: 100px;
display: block;
background: #79A70A;
background: linear-gradient(#F70505 0%, #8F0808 100%);
box-shadow: 0 3px 10px -5px rgba(0, 0, 0, 1);
position: absolute;
top: 19px; right: -21px;
}
.ribbon span::before {
content: "";
position: absolute; left: 0px; top: 100%;
z-index: -1;
border-left: 3px solid #8F0808;
border-right: 3px solid transparent;
border-bottom: 3px solid transparent;
border-top: 3px solid #8F0808;
}
.ribbon span::after {
content: "";
position: absolute; right: 0px; top: 100%;
z-index: -1;
border-left: 3px solid transparent;
border-right: 3px solid #8F0808;
border-bottom: 3px solid transparent;
border-top: 3px solid #8F0808;
}
<div style="display:flex; justify-content: space-between; flex-wrap: wrap;">
<div class="box">
<div class="featured"><span>PREMIUM</span></div>
</div>
<div class="box">
<div class="featured"><span>PREMIUM</span></div>
</div>
<div class="box">
<div class=""><span>PREMIUM</span></div>
</div>
<div class="box">
<div class="featured"><span>PREMIUM</span></div>
</div>
<div class="box">
<div class=""><span>PREMIUM</span></div>
</div>
<div class="box">
<div class="featured"><span>PREMIUM</span></div>
</div>
</div>

关于css - 如何将 CSS Ribbon Generator 代码用于特定特色图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56265592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com