Html转换属性

时间:2016-09-28 17:28:49

标签: html css3

如何在此div上直接设置文字和背景?变换属性使其弯曲。



#paralelogram {
  margin-left: 190px;
  width: 200px;
  height: 80px;
  transform: skew(-30deg);
  background-image: url('http://lorempixel.com/200/80/animals/8/');
  position: relative;
  overflow: hidden;
}
#cena {
  font-size: 20px;
  font-family: monospace;
  font-weight: bold;
  text-align: center;
  vertical-align: middle;
  position: absolute;
  margin-left: 35px;
  margin-top: 25px;
}

<div class="col-xs-12 volks">
  <div id="paralelogram">
    <p id="cena">136,380 Kn</p>
  </div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

对图像使用伪,然后反转其上的偏斜以及p transform: skew(30deg);

&#13;
&#13;
#paralelogram {
  margin-left: 190px;
  width: 200px;
  height: 80px;
  transform: skew(-30deg);
  position: relative;
  overflow: hidden;
  background: gray;
}
#paralelogram:before {
  content: '';
  width: 240px;
  height: 100%;
  top: 0;
  left: -20px;
  transform: skew(30deg);
  background-image: url('http://lorempixel.com/240/80/animals/8/');
  background-repeat: no-repeat;
  position: absolute;
}
#cena {
  font-size: 20px;
  font-family: monospace;
  font-weight: bold;
  text-align: center;
  vertical-align: middle;
  position: absolute;
  margin-left: 35px;
  margin-top: 25px;
  transform: skew(30deg);
}
&#13;
<div class="col-xs-12 volks">
  <div id="paralelogram">
    <p id="cena">136,380 Kn</p>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

另一个想法是使用clip-path来掩盖平行四边形而不是transform:skew。目前的一个警告是有限的browser compatibility

我的示例基于Harry's answer to "Shape with a slanted side (responsive)"

&#13;
&#13;
#parallelogram {
  position: relative;
  width: 240px;
  height: 80px;
  line-height: 80px;
  text-align: center;
  color: red;
  background-color: grey;
  background-image: url(http://lorempixel.com/g/240/80/);
  -webkit-clip-path: polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%);
  clip-path: polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%);
}
&#13;
<div id="parallelogram">136,380 Kn</div>
&#13;
&#13;
&#13;