简体   繁体   English

CSS / HTML中的响应性对角线

[英]Responsive diagonal line in CSS/HTML

What I'm trying to achieve is to have a diagonal line go from a bottom border, to a top border, behind a nav box and have two different background colours on each side of the diagonal. 我想要达到的目的是使对角线从导航框后面的底部边框延伸到顶部边框,并且在对角线的每一侧都有两种不同的背景颜色。

And, to top it off, it needs to be responsive. 而且,最重要的是,它需要响应能力。

Hopefully this makes sense, if it doesn't, heres an image. 希望这有道理,如果没有的话,这是一张图片。

In the image, the bottom-left diagonal comes out too far, it would end in line with the left nav box element, so could use the location of each of the corners as anchors. 在图像中,左下角的对角线太远,它将与左侧导航框元素在一条直线上结束,因此可以将每个角的位置用作锚点。

在此处输入图片说明

More than happy to use whatever method is proposed. 乐于使用建议的任何方法。

Thanks! 谢谢!

EDIT I can make a parallelogram in css pretty easy but it is not responsive. 编辑我可以使CSS中的平行四边形相当容易,但它没有响应。

#parallelogram {
    width: 700px;
    height: 200px;
    -webkit-transform: skew(-40deg);
    background: red;
    margin-left: 100px;
}

http://jsfiddle.net/cbiggins/fVeDD/ http://jsfiddle.net/cbiggins/fVeDD/

EDIT 2 Updated fiddle, now calculating angle and applying change on resize. 编辑2更新了小提琴,现在计算角度并在调整大小上应用更改。 Note this only works on Chrome (and Safari?) atm. 请注意,这仅适用于Chrome(和Safari?)atm。

http://jsfiddle.net/cbiggins/fVeDD/5/ http://jsfiddle.net/cbiggins/fVeDD/5/

We might be leaving it now though, I'm not sure how feasible this is now with the time constraints we have in our current project. 尽管我们现在可能会离开,但我不确定当前项目中的时间限制现在是否可行。

You can use css3 transformation something like below: 您可以使用css3转换,如下所示:

.border_div{
  width: 200px; // you may also need to apply position absolute
  height: 2px;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  transform: rotate(45deg);
}

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

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