[英]I would like to have a triangle in my web and filled it with images
I'm designing a little web page, just for practicing(I'm a begginer), and as the title says, I need to create a triangle with a background image. 我正在设计一个用于练习的小网页(我是个初学者),正如标题所述,我需要创建一个带有背景图像的三角形。 I have this model that I created : My website
我创建了这个模型: 我的网站
I'm talking about the triangles on the up-right corner of the "posts" 我说的是“柱子”右上角的三角形
The only way I know of creating a triagle is with borders in CSS, but that won't help because of the image I need to use. 我知道创建triagle的唯一方法是在CSS中使用边框,但是由于需要使用图像,因此这无济于事。
Maybe you have other idea Thanks ! 也许您还有其他想法,谢谢!
Tell me if you need help getting this in to your own code, here's the example: 告诉我,如果您需要帮助将其输入自己的代码中,请参见以下示例:
div { position: absolute; width: 128px; height: 128px; background-image: url(http://i.imgur.com/envk4PP.png); background-repeat: no-repeat; background-size: cover; -webkit-clip-path: polygon(0 12%, 0 86%, 35% 50%); clip-path: polygon(0 0%, 100% 100%, 100% 0%); }
<div></div>
I have to do something similar for a website, this is my example. 我必须为网站做类似的事情,这是我的例子。 I hope you can use it.
希望您可以使用它。
.overheader{ padding: 40px 0; -webkit-clip-path: polygon(0 0, 0% 0, 20.3% 100%, 0% 100%); -moz-clip-path: polygon(0 0, 0% 0, 20.3% 100%, 0% 100%); clip-path: polygon(0 0, 0% 0, 20.3% 100%, 0% 100%); background-image: url('http://www.todofermentacion.cl/assets/img/cerveza.png'); } .page-header { padding: 50px; }
<div class="page-header"> <div class="overheader"> </div> </div>
You have to modify the parameters of polygon to make the triangle anyway you want 无论如何,您都必须修改多边形的参数以使三角形成为可能
Another option: 另外一个选项:
.post { /* not important */ margin: 100px; width: 10rem; height: 5rem; border: solid 1px black; background: ivory; padding: 1rem; /* important */ position: relative; overflow: hidden; } .post:after { position: absolute; display: block; content: " "; background-image: url(https://www.gravatar.com/avatar/614f3577183f1a9219884f73ec2538fd); transform: rotate(45deg); width: 50px; height: 50px; /* move it half the width*/ top: -25px; right: -25px; }
<div class="post"> Here is my post </div>
:root{ --imageblockwidth: 105px; --imageblockheight: 80px; /*css variables*/ } .imagediv { width: var(--imageblockwidth); height: var(--imageblockheight); background-image: url(https://i.ytimg.com/vi/2fb-g_V-UT4/hqdefault.jpg); background-size: contain; background-repeat: no-repeat; } .imageoverlapper { width: var(--imageblockwidth); height: var(--imageblockheight); box-sizing: border-box; /*triangles using borders*/ border-top: var(--imageblockheight) solid rgba(0,0,0,0); border-left: var(--imageblockwidth) solid yellow; position: relative; top : calc(-1*var(--imageblockheight)); }
<div class="imagediv"></div> <div class="imageoverlapper"></div>
Just overlap rectangle with background image by triangle 只是将矩形与背景图像按三角形重叠
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.