CSS Only Folded Corner Div

时间:2013-06-24 02:31:16

标签: css css3

所以我一直在抨击我的头撞墙,在网上尝试了几种不同的方法,无法让任何事情发挥作用。

我有div需要流畅的宽度,其高度也需要变化。

div位于可拼图的背景图像之上。它周围有一个1px border

我需要将div的右下方折叠起来,就像一张纸。

我尝试使用图像,在一个固定在底部的div中。但据我所知,这需要固定的宽度或高度。

我尝试了this method但它需要坚实的背景色。我有一个重复的图像。

我尝试this method,它使用渐变来控制角落的不透明度,这几乎可以工作,但我的div需要边框。应用边界破坏了效果。

background:
    linear-gradient(45deg,  rgba(255,0,0,0.4), rgba(255,0,0,0.4)),
    linear-gradient(135deg, rgba(255,0,0,0.4), rgba(255,0,0,0.4)),
    linear-gradient(225deg, transparent 10px,  rgba(255,0,0,0.4)
background-size: 14px 14px, 50% 100%, 50% 50%, 50% 50%;
background-position: 100% 0, 0 0, 100% 100%, 100% 0;
background-repeat: no-repeat;

//then an :after pseudo class to create the corner fold

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:4)

这个问题让我忙了一段时间,这对CSS来说似乎真的很难。我设法实现了你想要的效果(带有元素边框的纸张翻转),但它需要很多CSS,我不知道你想走多远。我将border-radius应用于右上角,并使用三角形重叠边框半径。这并未涵盖整个border radius,因此我使用span形成2个形状以覆盖剩余的差距。

看看这个小提琴的结果,欢迎任何改进

http://jsfiddle.net/EnVnW/

<强> CODE:

body {
    background: #444 url('http://leaverou.me/ft2010/img/darker_wood.jpg') bottom;
}

.arrow_box {
    color:red;
    position: relative;
    background: #88b7d5;
    border: 4px solid #c2e1f5;
    height:400px;
    border-radius:0 300px 0 0; /* here we give the box a round corner on the top right side */
}

.arrow_box:after, .arrow_box:before { /* we create 2 triangles in the top right corner, one for the border and one for the filling */
    -ms-transform:rotate(-135deg); /* rotate to make the triangle have the right angle */
    -webkit-transform:rotate(-135deg); 
     transform:rotate(-135deg);
    bottom: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    top:42px;
    right:-20px;
}

/* here we position the triangles in the top right corner */
.arrow_box:after {
    border-color: rgba(200, 265, 0, 0);
    border-bottom-color: #00b7d5;
    border-width: 100px;
    left: 100%;
    margin-left: -240px;
}
.arrow_box:before {
    border-color: rgba(194, 225, 245, 0);
    border-bottom-color: #c2e1f5;
    border-width: 105px;
    left: 100%;
    top:39px;
    margin-left: -245px;
}

/* we still have a massive gap next to the triangle, so we fill it up with 2 rectangles. One on the left side of the triangle and one on the bottom side of the triangle, we also will give them a border to finish the line around the element */
.arrow_box span {
    border-top: 4px solid #c2e1f5;
    position:absolute;
    width:150px;
    height:140px;
    background-color:black;
    right:140px;
    top:-4px;
    background: #88b7d5;
}

.arrow_box span:after {
    border-right: 4px solid #c2e1f5;  
    content: "";
    position:absolute;
    width:150px;
    height:150px;
    background: #88b7d5;
    left:140px;
    top:140px;
}

使用CSS4,这将更容易做到,在这里你可以阅读它;

http://dev.w3.org/csswg/css-backgrounds-4/#border-corner-shape

相关问题