2014-12-29 68 views
6

邊緣參差不齊我目前使用的圖片,我想知道如果theres產生這些參差不齊的邊緣生成CSS

大尺寸圖像的任何CSS庫/方法:(使用PNG的頂部和底部的內容) [http://i.imgur.com/LgyNSOJ.png][1] enter image description here

謝謝!

編輯:我注意到有關於關閉這個問題的投票,但我希望在今天餘下時間保持打開狀態,以防提供更多的solns。

+1

我不知道CSS,但也許你可以嘗試SVG? [*鏈接*](http://www.w3schools.com/svg/default.asp) – RobinvdA

+0

我會明天再試一次,然後回到這裏。 Ty – PenguinSource

+0

使用Photoshop創建一個'PNG'圖像作爲背景,並重復它 – Cattla

回答

3

您可以使用svgfilter s來獲得類似的效果。

body { 
 
    background: tan; 
 
} 
 
svg { 
 
    position: relative; 
 
    width: 500px; 
 
    left: 50%; 
 
    transform: translateX(-50%); 
 
} 
 
p { 
 
    color: peru; 
 
    padding: 45px; 
 
}
<svg width="500" height="500"> 
 
    <defs> 
 
    <filter id="filter" height="1.4" width="1.4"> 
 
     <feTurbulence baseFrequency="0.12" numOctaves="2" type="fractalNoise" result="result1" /> 
 
     <feDisplacementMap in2="result1" scale="99" result="result2" xChannelSelector="R" in="SourceGraphic" /> 
 
     <feComposite in2="result2" in="SourceGraphic" operator="atop" result="fbSourceGraphic" /> 
 
    </filter> 
 
    </defs> 
 
    <rect fill="saddlebrown" filter="url(#filter)" width="500" height="500" x="0" y="0" /> 
 
    <foreignObject width="500" height="500"> 
 
    <div> 
 
     <p> 
 
     Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
 
     in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
 
     <br /> 
 
     <br />Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem 
 
     quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam 
 
     eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit 
 
     qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? 
 
     </p> 
 
    </div> 
 
    </foreignObject> 
 
</svg>

+0

謝謝,這是最接近的,但我仍然會使用圖片我猜,他們只是看起來更平滑。 – PenguinSource

2

我會使用SVG。您可以在Illustrator/Sketch中輕鬆獲得精確的形狀,並從那裏導出SVG文件。

3

這隻適用於圖像,並且完全適用於圖像。如果它是您擔心的圖片的額外往返 - 將其嵌入到CSS中很容易,因此它很簡潔快速。您可以使用任何您喜歡的圖像類型作爲實際圖像 - 對於此特定目的,PNG或SVG是最可能的候選對象(PNG實際上更容易平鋪)。

Read this article on embedding images as Data URIs in your CSS

Here's a good online tool to create Date URIs

+0

謝謝,這是一個很好的閱讀。在上面的圖片中,我已經用png完成了,但我想看看是否可以用css創建相同的效果,這樣我可以在內容周圍留下粗糙的邊緣(因此可以使邊框效果)。 – PenguinSource

+0

對於那部分具體:看看邊界圖像屬性。現在支持很粗略,但保持雷達不變。 –

+0

[請參閱CSS3'border-image'上的瀏覽器支持](http://caniuse.com/#feat=border-image)。 –

1

我相信事情的進展,因爲這最初發布在2014年這一年是2017年,現在,我已經使用CSS創建粗糙/撕邊的外觀。在這裏看到代碼示例。我相信有更多的工作可以讓它更具說服力......但我喜歡這個結果給我的目的。

clip-path: polygon(3% 0, 7% 1%, 11% 0%, 16% 2%, 20% 0, 23% 2%, 28% 2%, 32% 1%, 35% 1%, 39% 3%, 41% 1%, 45% 0%, 47% 2%, 50% 2%, 53% 0, 58% 2%, 60% 2%, 63% 1%, 65% 0%, 67% 2%, 69% 2%, 73% 1%, 76% 1%, 79% 0, 82% 1%, 85% 0, 87% 1%, 89% 0, 92% 1%, 96% 0, 98% 3%, 99% 3%, 99% 6%, 100% 11%, 98% 15%, 100% 21%, 99% 28%, 100% 32%, 99% 35%, 99% 40%, 100% 43%, 99% 48%, 100% 53%, 100% 57%, 99% 60%, 100% 64%, 100% 68%, 99% 72%, 100% 75%, 100% 79%, 99% 83%, 100% 86%, 100% 90%, 99% 94%, 99% 98%, 95% 99%, 92% 99%, 89% 100%, 86% 99%, 83% 100%, 77% 99%, 72% 100%, 66% 98%, 62% 100%, 59% 99%, 54% 99%, 49% 100%, 46% 98%, 43% 100%, 40% 98%, 38% 100%, 35% 99%, 31% 100%, 28% 99%, 25% 99%, 22% 100%, 19% 99%, 16% 100%, 13% 99%, 10% 99%, 7% 100%, 4% 99%, 2% 97%, 1% 97%, 0% 94%, 1% 89%, 0% 84%, 1% 81%, 0 76%, 0 71%, 1% 66%, 0% 64%, 0% 61%, 0% 59%, 1% 54%, 0% 49%, 1% 45%, 0% 40%, 1% 37%, 0% 34%, 1% 29%, 0% 23%, 2% 20%, 1% 17%, 1% 13%, 0 10%, 1% 6%, 1% 3%);