html - 使用 CSS 的锐利边框

标签 html css

我正在尝试标签 SOLD OUT 如下图所示 figure

enter image description here

但能够达到如下图所示的一定程度

enter image description here

使用以下 HTML 和 CSS

<a href="some-href">
  <img src="img-url">
  <div class="wp-sold-out-strip">SOLD OUT</div>
</a>

.wp-sold-out-strip {
text-align: center;
background-color: #8760AF;
width: 142px;
color: #FFF;
font-size: 13px;
font-weight: bold;
padding: 0px 0px;
position: absolute;
margin-top: -47px;
transform: rotate(-26deg);    
}

最佳答案

你需要做一些事情:

  • 设置 parent 的positionrelative (在你的情况下)和 overflowhidden .
  • 设置“售罄”的width到会溢出的东西和图像的heightwidth100%填充父级

您需要 position:relative父级的,因此“售罄”将在 position:absolute 时与其父级对齐和 overflow:hidden将应用于它。

.parent {overflow: hidden; position: relative; display: block; width: 200px; height: 200px;}
.parent img { width: 100%; height: 100%;}
.wp-sold-out-strip {
text-align: center;
background-color: #8760AF;
width: 242px;
color: #FFF;
font-size: 13px;
font-weight: bold;
padding: 0px 0px;
position: absolute;
margin-top: -47px;
transform: rotate(-26deg);    
}

<a href="some-href" class="parent">
  <img src="http://i.stack.imgur.com/Mmww2.png">
  <div class="wp-sold-out-strip">SOLD OUT</div>
</a>

https://jsfiddle.net/ivankovachev/snxt61an/

关于html - 使用 CSS 的锐利边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38451638/

相关文章:

javascript - HTML 文本编辑器 div - 强制文本从底部开始 - 从下到上文本框

html - 创建 "navigation breadcrumb"

jquery - 不倾斜导航栏下拉仅 HTML5/CSS/jQuery

html - 尽管有 "display:inline-block",为什么这些 div 没有显示在同一行中?

html - 表格宽度 100% 偏移一个像素(取决于实际宽度)

javascript - 如何在具有一致不透明度的 Canvas 上进行绘制?

jquery - 使用 Jquery 的悬停效果标题?

jquery - 突出显示文本

html - 二维变换过渡不适用于 IE11 中的 VW 和 VH 单元

html - 将关键帧值设置为偏移量?