【问题标题】:div clip path according to the parent rectangle根据父矩形的div剪辑路径
【发布时间】:2019-03-04 06:58:16
【问题描述】:

我正在尝试将此表带夹到父矩形中。
图片-


HTML 代码:

<div class="pricing_plan ultimate">
    <div class="strap">
        <P>RECOMMENDED</P>
    </div>
    <div class="p_name">
        <p>Ultimate</p>
    </div>
    <div class="p_plan">
        <p><strike>&#8377; 2388</strike></p>
        <h3>&#8377; 1,099</h3>
        <p>Save 53%</p>
    </div>
    <div class="p_duration">
        <p>12 Months</p>
        <p>356 Days</p>
    </div>
    <a href="">
        <button class="pricing_button ultimate">BUY</button>
    </a>
</div>

CSS

.s2 .pricing_plans .ultimate .strap{
    position: relative;
    top:  -13px;
    right: 65px;
    transform: rotate(-35deg);
    clip-path: inset(0px 50px 50px 0px); 
}



.s2 .pricing_plans .ultimate .strap p{
    background-color: white;
    font-size: 10px;
    color: #3499E0;
    padding-left: 20px;
    padding-right: 20px;
    margin-top: 0px;
    margin-bottom: 0px;
}

我怎样才能把它剪成矩形,这样它就不会流到外面。 我试过overflow: hidden 好像不行。

最好的方法是什么,以便最适合响应式设计?

【问题讨论】:

  • 你能创建一个runnable 演示吗?这样我们会更容易提供帮助。
  • 当然,我会更新的。

标签: css html clip


【解决方案1】:

您必须将position:relative 用于父块,position:absolute 用于子块:

.bloc{
  background: red;
  position: relative;
  overflow: hidden;
  width: 200px;
  height: 300px;
}

.bloc .label{
  position: absolute;
  top: 15px;
  left: -20px;
  width: 120px;
  height: 20px;
  background: black;
  color: #fff;
  text-align: center;
  transform: rotate(-35deg);
}
<div class="bloc">
  <div class="label">
    Label here
  </div>
</div>

【讨论】:

  • 嘿,我尝试使用它,但又遇到了一个问题。我正在使用 flex 行来对齐我所有的定价卡,现在当我使卡片的位置相对于它失去宽度并且没有响应时,作为一个 flex 项目。
  • 没关系!雷米,我搞定了。谢谢你的帮助。
猜你喜欢
  • 1970-01-01
  • 2012-02-14
  • 2017-07-04
  • 2016-11-27
  • 2015-09-23
  • 2020-11-10
  • 1970-01-01
  • 1970-01-01
  • 2018-05-07
相关资源
最近更新 更多