CSS定制边框半径倒置的梯形

时间:2018-07-23 02:27:09

标签: html css

我想使用CSS和HTML自定义此形状。它是相同的梯形,但边框半径倒置。如何自定义? 这是这样的图像。

Image here

我想要的是它将能够调整其中的文本大小。 (也许叫显示内联...我不确定。)例如:我有短文本,应该是100px,长文本应该是400px。

.dxTitle {
  /* I use Image instead of Custom transformed shape */
  background: url('https://image.ibb.co/eF0oRy/title_1.png') no-repeat;
  background-size: 100% 100%;
  background-position: left 0px;
  height: 34px;
  color: white;
  padding: 5px;
  /* Seem not important */
  margin-bottom: 20px;
}
<div class="dxTitle">
  <span style="font-weight:500">
    The Headers with short text
  </span>
</div>
<div class="dxTitle">
  <span style="font-weight:500">
    The Headers with long long long long text
  </span>
</div>

谢谢!

1 个答案:

答案 0 :(得分:4)

您可以使用以下内容:

div {
  border-top: solid 1px #06f;
  margin: 1rem;
  padding: 0;
  border-radius: .2em 0 0 .2em;
  overflow: hidden;
  font-size: 2rem;
}

h1 {
  display: inline-block;
  margin: 0 0 0 -1em;
  padding: 0 1em 0 2em;
  line-height: 1.4;
  border-radius: 0 0 .2em 0;
  background: #06f;
  transform: skewX(-25deg);
  font-size: inherit;
  font-weight: 500;
}

span:before,
span:after {
  content: '';
  position: absolute;
  width: .4em;
  height: .4em;
  background: #06f;
  right: -1.57em;
  border-radius: 0 0 .2em 0;
}

span:after {
  width: .5em;
  height: .5em;
  transform: skewX(-25deg);
  border-radius: .2em 0 0;
  background: #fff;
  right: -1.7em
}

span {
  position: relative;
  display: inline-block;
  color: #fff;
  transform: skewX(25deg);
}
<div>
  <h1><span>Header</span></h1>
</div>
<div>
  <h1><span>Header with a short text</span></h1>
</div>
<div>
  <h1><span>Header with a long long long text</span></h1>
</div>