简体   繁体   English

如何从图片来源围绕CSS组件制作框架

[英]How to make a frame around CSS component from a picture source

I have a png picture that has some borders around and is empty inside http://i.imgur.com/ji4M0VW.png I wanted to use it as a frame for some text/picture that could be fit inside, sometimes this effect is visible on webpages when people are presenting content inside eg an iphone - the picture is just the border and the component inside is fully responsive. 我有一个png图片,周围有一些边框,并且在http://i.imgur.com/ji4M0VW.png中是空的。我想将其用作一些可能适合其内部的文本/图片的框架,有时这种效果是当人们在iphone等内部展示内容时,在网页上可见-图片只是边框,内部组件具有充分的响应能力。 I played around, but I only managed to achieve something far from the expected result here https://jsfiddle.net/m6r2whyu/ . 我玩了,但是在这里https://jsfiddle.net/m6r2whyu/只能达到与预期结果相差甚远的效果。 So far my CSS: 到目前为止,我的CSS:

#borderimg2 { 
    border: 10px solid transparent;
    padding: 15px;
    -webkit-border-image: url(http://i.imgur.com/ji4M0VW.png) 30 stretch; /* Safari 3.1-5 */
    -o-border-image: url(http://i.imgur.com/ji4M0VW.png) 30 stretch; /* Opera 11-12.1 */
    border-image: url(http://i.imgur.com/ji4M0VW.png) 30 stretch;
}

does not work well. 效果不好。 Does anyone know what could I fix here? 有人知道我可以在这里解决什么吗?

The way that i've accomplished this task before is to use Photoshop. 我之前完成此任务的方式是使用Photoshop。 There is an easy-to-use tool called the 'background eraser tool' that will allow you to erase the white space in the centre of your image so that it is transparent. 有一个易于使用的工具,称为“背景橡皮擦工具”,可让您擦除图像中心的空白区域,使其透明。 Once you have a transparent inside, you could use the image as an overlay for another image. 一旦有了透明的内部,就可以将图像用作其他图像的叠加层。

Added some styles, the result is more or less ok 添加了一些样式,结果或多或少都可以

 #borderimg2 { border: 10px solid transparent; padding: 15px; -webkit-border-image: url(http://i.imgur.com/ji4M0VW.png) 30 stretch; /* Safari 3.1-5 */ -o-border-image: url(http://i.imgur.com/ji4M0VW.png) 30 stretch; /* Opera 11-12.1 */ border-image: url(http://i.imgur.com/ji4M0VW.png) 30 stretch; border-image-slice: 9% 15% 12% 15%; border-image-width: 33px; height: 300px; width: 300px; } 
 <p id="borderimg2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut placerat aliquet pellentesque. Pellentesque iaculisdiam sit amet vehicula mattis. Cras gravida sed libero sed consequat. Nam efficitur sed sem sed vehicula. Aliquam ultrices aliquam mattis. Nunc odio urna, pharetra a augue tempus, laoreet scelerisque odio. Cras non rutrum lectus. Vestibulum condimentum vehicula scelerisque. Sed sed mattis nibh. Aliquam porta dui a risus sodales accumsan. Nullam in neque diam.</p> 

resources 资源

properties explained 属性说明

online generator 在线发电机

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

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