2016-05-30 87 views
1

我想爲使用CSS的框創建特定大綱。CSS - 具體概述

事情是這樣的形象: Specific Outline

請,任何幫助嗎? :(

+0

輪廓或邊界? –

+0

之前和之後或bg圖像PNG – vicodin

回答

3

你可以看一下漸變,背景夾和背景大小:

示例可能http://codepen.io/gc-nomade/pen/aZbrEQ

div { 
 
    margin: 1em auto; 
 
    width: 600px; 
 
    max-width: 70%; 
 
    padding: 40px; 
 
    /* set offset here for border corners */ 
 
    background: linear-gradient(white, white) top left no-repeat, linear-gradient(white, white) top left no-repeat, linear-gradient(white, white) top right no-repeat, linear-gradient(white, white) top right no-repeat, linear-gradient(white, white) bottom left no-repeat, linear-gradient(white, white) bottom left no-repeat, linear-gradient(white, white) bottom right no-repeat, linear-gradient(white, white) bottom right no-repeat, rgba(255, 255, 255, 0.15); 
 
    /* color receive 
 
    background-clip:content-box; 
 
    so it is not drawn on padding areas */ 
 
    background-clip: border-box, border-box, border-box, border-box, border-box, border-box, border-box, border-box, content-box; 
 
    background-size: 2px 60px, 80px 2px; 
 
    /* here give length and thickness of border corners */ 
 
    color: white; 
 
} 
 
p, 
 
h2 { 
 
    padding: 1em; 
 
    margin:0; 
 
} 
 
html { 
 
    height: 100%; 
 
    background: url(http://lorempixel.com/640/480/nature/6); 
 
    background-size: cover 
 
} 
 
body { 
 
    min-height: 100%; 
 
    background: rgba(0, 0, 0, 0.5); 
 
    margin: 0; 
 
    padding: 4em; 
 
}
<div> 
 
    <h2>title</h2> 
 
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. 
 
    Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus 
 
    lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, 
 
    facilisis luctus, metus</p> 
 
</div>

+0

非常感謝! – Eusthace

+0

你可以給你的例子添加一個h2和一個跨度嗎?謝謝! – Eusthace

+0

@Eusthace我更新了代碼段並將pss移到了div(包裝) –

1

只是爲了證明你的問題是多麼簡單。 ::before::after隱藏邊框的部分。 z-index的疊加。

.dirt { 
 
    position: relative; 
 
    width: 200px; 
 
    height: 100px; 
 
    line-height: 100px; 
 
    text-align: center; 
 
    background-color: rgba(251, 145, 156, 1); 
 
    border: 2px solid rgba(231, 0, 0, 1); 
 
    box-sizing: border-box; 
 
} 
 
.dirt > span { 
 
    position: relative; 
 
    z-index: 15; 
 
    background-color: rgba(255,255,255,0.5); 
 
    padding: 25px; 
 
} 
 
.dirt::after, 
 
.dirt::before { 
 
    content: ''; 
 
    position: absolute; 
 
    background-color: rgba(251, 145, 156, 1); 
 
    /*same color*/ 
 
} 
 
.dirt::before { 
 
    top: 20%; 
 
    bottom: 20%; 
 
    left: -2px; 
 
    /*border-width*/ 
 
    right: -2px; 
 
    /*border-width*/ 
 
} 
 
.dirt::after { 
 
    top: -2px; 
 
    /*border-width*/ 
 
    bottom: -2px; 
 
    /*border-width*/ 
 
    left: 20%; 
 
    right: 20%; 
 
}
<p>An example: (do not use)</p> 
 
<div class="dirt"> 
 
    <span>My little dirt text</span> 
 
</div>

+0

嗨,謝謝你的迴應。他們希望輪廓具有偏移量並且與框更加分離的情況。就像我之前展示的照片...... :(對此有何幫助? – Eusthace

+0

片刻請:-) –

+0

非常感謝您的幫助! – Eusthace