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

html – 带有直角梯形的盒子形状,第1张

概述我想知道如果这个形状可以在css3中尽可能少的html来完成: 到目前为止,我已经设法做到这一点: .wrapper { position: relative;}.box { width: 100px; height: 100px; border: 1px solid #000; position: absolute; top: 100px; left: 100px 我想知道如果这个形状可以在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 >  <div ></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>
总结

以上是内存溢出为你收集整理的html – 带有直角梯形的盒子形状全部内容,希望文章能够帮你解决html – 带有直角梯形的盒子形状所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1103122.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存