html – 带有直角梯形的盒子形状

我想知道如果这个形状可以在css3中尽可能少的html来完成:

到目前为止,我已经设法做到这一点:

.wrapper {
  position: relative;
}
.Box {
  width: 100px;
  height: 100px;
  border: 1px solid #000;
  position: absolute;
  top: 100px;
  left: 100px;
}
.Box:before {
  content: "";
  border: 1px solid #000;
  border-bottom: 1px solid #fff;
  width: 50%;
  height: 10px;
  position: absolute;
  top: -12px;
  left: -1px;
}
.Box:after {
  content: "";
  border: 1px solid #000;
  border-top: 1px solid #fff;
  width: 50%;
  height: 10px;
  position: absolute;
  bottom: -12px;
  right: -1px;
}
<div class="wrapper">
  <div class="Box"></div>
</div>

小提琴是here,但我不知道如何扭曲它,使我在顶部和底部有直角梯形.

解决方法

形状不需要额外的元素

可以使用< div&gt ;:::创建形状
>左边是左边的div,top和bottom的边框.
>右边是由…制成的:之前和它的顶部,右边和底部的边界
>加入两个框的跨度是用以下方式创建的:感谢skewY

Note the browser support of the transform property. IE 9需要-ms-前缀,Safari和Android浏览器需要-webkit-.

工作实例 – 只是形状

CSS已被压缩,伪元素的边框样式从div本身继承.

div {
  border: solid 4px #000;
  border-right-width: 0;
  width: 100px;
  height: 200px;
  position: relative;
}
div:before,div:after {
  content: '';
  display: block;
  height: 100%;
  width: 100%;
  border: inherit;
  border-right-width: 4px;
  border-left: none;
  position: absolute;
  left: 100%;
  top: 13px;
  margin-left: 20px;
}
div:after {
  width: 20px;
  border-right: none;
  top: 5px;
  transform: skewY(40deg);
  margin: 0;
}
<div></div>

工作示例 – 带文本

通过上面的例子,内容将不会被包含在整个形状内.相反,它将被限制在div的半宽度内.内容需要包裹在< span>宽度为200%,可以将其打印到divs约束之外.

div {
  border: solid 4px #000;
  border-right-width: 0;
  width: 100px;
  height: 200px;
  position: relative;
}
div:before,div:after {
  content: '';
  display: block;
  height: 100%;
  width: 100%;
  border: inherit;
  border-right-width: 4px;
  border-left: none;
  position: absolute;
  left: 100%;
  top: 13px;
  margin-left: 20px;
}
div:after {
  width: 20px;
  border-right: none;
  top: 5px;
  transform: skewY(40deg);
  margin: 0;
}
span {
  width: 200%;
  display: block;
  padding: 20px 10px 10px;
}
<div><span>This is me writing a large amount of words into the div. I think that you may want a span in order to contain them.</span></div>

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些