简体   繁体   English

具有边框和背景色的纯CSS响应梯形

[英]Pure CSS Responsive Trapezoid with borders and background colour

So i wanted to create a responsive trapezoid where you can apply a border and a background colour to it I already created one using 3 div blocks but i cant get the border at the top of the trapezoid to stay inline when the width and height is changed So my question is either. 所以我想创建一个自适应梯形,您可以在其中应用边框和背景色。我已经使用3 div块创建了一个梯形,但是当宽度和高度更改时,我无法使梯形顶部的边框保持内嵌所以我的问题是。 can someone help me figure out how to keep the line at the top of the trapezoid in line with the left and right border or if anybody knows of a different solution? 有人可以帮助我弄清楚如何使梯形顶部的线与左右边框保持一致,或者有人知道其他解决方案吗? Here is my code.... 这是我的代码。

 .trapezoid-container{ position: relative; margin-left: 100px; width: 200px; height: 200px; } .trapezoid { background: green; position: relative; position:absolute; content:""; width: 70%; height: 100%; border-top: 5px solid black; border-bottom: 5px solid black; left: 20px; } .trapezoid:before { background: green; position:absolute; content:""; width: 60%; height: 100%; left: 63%; border-right: 5px solid black; border-bottom: 5px solid black; transform: skew(20deg); } .trapezoid:after { background: green; position:absolute; content:""; width: 60%; height: 100%; left: -28%; border-left: 5px solid black; border-bottom: 5px solid black; transform: skew(-20deg); } 
 <div class="trapezoid-container"> <div class="trapezoid"> </div> </div> 

Thanks guys :) 多谢你们 :)

A better solution found on How to draw a trapezium/trapezoid with css3? 如何使用css3绘制梯形/梯形中找到更好的解决方案 Which answers my question, thought id post it 哪个回答了我的问题,以为id发布了

 #container { position: relative; margin-left: 200px; width: 200px; height: 200px; } .trapezoid { position: relative; width: 30%; height: 50%; background: red; transform: perspective(2px) rotateX(1deg); border: solid 4px black; left: 20%; top: 70%; } 
 <div id="container"> <div class="trapezoid"> </div></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM