CSS中的三角形在一个盒子里面

时间:2023-02-09 09:06:53

Well I don't know how to explain it correctly. Here, check this screenshot which has what I want to make. My designer gave me this. If I don't find a solution i'll use images and no code. Is it possible to do this with CSS3?

好吧,我不知道如何正确解释它。在这里,查看我想要制作的截图。我的设计师给了我这个。如果我找不到解决方案,我将使用图像而不使用代码。用CSS3可以做到这一点吗?

Here is the image

这是图像

CSS中的三角形在一个盒子里面

See the triangle inside that box? I want to do this. Thank you!

看到那个盒子里面的三角形?我想做这个。谢谢!

1 个解决方案

#1


10  

Creative use of borders to achieve this effect, no images were harmed in the following sample and you can even set the position of the arrow on the element itself - becomes more straightforward if you can hardcode it for your design.

创造性地使用边框来实现这种效果,在下面的示例中没有图像受到损害,您甚至可以在元素本身上设置箭头的位置 - 如果您可以为您的设计进行硬编码,则会变得更加直截了当。

HTML

HTML

<div class="top">
    <span class="arrow" style="left:40%"></span>
</div>

CSS

CSS

.top {
    background:url(http://blog.positscience.com/wp-content/uploads/2013/08/ice-cream3.jpg);
    background-size:cover;
    width:300px;
    height:300px;
    border:1px solid #888;
    position:relative;
    overflow:hidden;
}
.arrow {
    border:30px solid #aaa;
    border-bottom:none;
    border-color:transparent #aaa transparent #aaa;
    position:absolute;
    left:0;
    bottom:0;
}
.arrow:before, .arrow:after {
    content:'';
    position:absolute;
    width:5000px;
    bottom:0;
    height:30px;
    background:#aaa;
}
.arrow:before {
    right:30px;
}
.arrow:after {
    left:30px;
}

Working JSfiddle sample.

工作JSfiddle样本。

Or the full integrated sample here.

或者这里的完整集成示例。

#1


10  

Creative use of borders to achieve this effect, no images were harmed in the following sample and you can even set the position of the arrow on the element itself - becomes more straightforward if you can hardcode it for your design.

创造性地使用边框来实现这种效果,在下面的示例中没有图像受到损害,您甚至可以在元素本身上设置箭头的位置 - 如果您可以为您的设计进行硬编码,则会变得更加直截了当。

HTML

HTML

<div class="top">
    <span class="arrow" style="left:40%"></span>
</div>

CSS

CSS

.top {
    background:url(http://blog.positscience.com/wp-content/uploads/2013/08/ice-cream3.jpg);
    background-size:cover;
    width:300px;
    height:300px;
    border:1px solid #888;
    position:relative;
    overflow:hidden;
}
.arrow {
    border:30px solid #aaa;
    border-bottom:none;
    border-color:transparent #aaa transparent #aaa;
    position:absolute;
    left:0;
    bottom:0;
}
.arrow:before, .arrow:after {
    content:'';
    position:absolute;
    width:5000px;
    bottom:0;
    height:30px;
    background:#aaa;
}
.arrow:before {
    right:30px;
}
.arrow:after {
    left:30px;
}

Working JSfiddle sample.

工作JSfiddle样本。

Or the full integrated sample here.

或者这里的完整集成示例。