简体   繁体   English

如何获得一个穿过右上角的css三角形?

[英]How do I get a css triangle that crosses the top right corner?

So I would like to have a triangle on my page, as a background, but I would like to do it without any images. 因此,我想在页面上有一个三角形作为背景,但我希望没有任何图像。 I have already tried using a :before element on my <aside> , but since I need jquery access, I replaced it with a div (.triangle) that sits within the aside. 我已经尝试在<aside>上使用:before元素,但是由于我需要jquery访问,因此我将其替换为放在一边的div(.triangle)。 On the desktop it looked okay, though the diagonal edge was kind of jagged. 在桌面上看起来还不错,尽管对角线边缘有些锯齿。 Code below and snapshot here . 下面的代码和快照在这里

.triangle
{
    position: absolute;
    top: 0; right: 0;
    z-index: -1;
    width: 0; height: 0;
    border: solid transparent;
    border-top-color: #CDC7D2;
    border-left-color: #CDC7D2;
}

I tried using "border-width: 3000px;", but the element then started accounting for quite a scroll (obviously). 我尝试使用“ border-width:3000px;”,但随后该元素开始占据相当大的滚动空间(显然)。

Next I tried using a CSS3 gradient and that worked, but the color-stop transition was blurry rather than hard on my phone (iPhone 4) so unless I'm missing something there, that's a dead end too. 接下来,我尝试使用CSS3渐变并且效果很好,但是颜色停止过渡是模糊的,而不是在我的手机(iPhone 4)上比较困难,因此除非我在那里缺少任何东西,否则这也是死路一条。 Code below and snapshot here . 下面的代码和快照在这里

body
{
    background-image: -webkit-linear-gradient(315deg, #CDC7D2 50%, #FFFFFF 50%);
    -webkit-background-size: 100% 100%;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

Using a rather big image is an easy fix, but I'd like to see if I missed something while trying to code this. 使用较大的图像很容易解决,但是我想看看在尝试编码时是否错过了某些内容。

您是否尝试过以下JQuery 插件

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

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