2016-08-09 10 views
10

Wie erstellen mehrfarbige Rahmen in css3 wie Bild unten?So erstellen Sie mehrfarbige Rahmen in css3

enter image description here

+1

http://jsfiddle.net/yH59y/ – Roysh

+1

Sie ein Randbild verwenden können: http: //www.w3schools. com/cssref/css3_pr_border-image.asp – Andrew

+1

versuchen Sie dies: http://www.hongkiat.com/blog/css-gradient-border/ –

Antwort

16

Sie können es mit :after oder :before psuedo Element und CSS linear-gradient wie unten dargestellt:

body { 
 
    background: #ccc; 
 
} 
 

 
.box { 
 
    text-align: center; 
 
    position: relative; 
 
    line-height: 100px; 
 
    background: #fff; 
 
    height: 100px; 
 
    width: 300px; 
 
} 
 

 
.box:after { 
 
    background: linear-gradient(to right, #bcbcbc 25%,#ffcd02 25%, #ffcd02 50%, #e84f47 50%, #e84f47 75%, #65c1ac 75%); 
 
    position: absolute; 
 
    content: ''; 
 
    height: 4px; 
 
    right: 0; 
 
    left: 0; 
 
    top: 0; 
 
}
<div class="box">Div</div>

+0

es funktioniert! danke – Radian

+0

@Radian du bist willkommen) –

2

es versuchen.

<div class="test"></div> 

    .test { 
     width: 500px; 
     height: 100px; 
     background-color: #ccc; 
     position: relative; 
    } 

    .test:before, .test:after { 
     content: ""; 
     position: absolute; 
     left: 0px; 
     right: 0px; 
     height: 10px; 
     background-image: -webkit-linear-gradient(0deg, red 20px, blue 20px, blue 40px, yellow 40px, yellow 60px, green 60px, green 80px); 
     background-image: -ms-linear-gradient(0deg, red 20px, blue 20px, blue 40px, yellow 40px, yellow 60px, green 60px, green 80px); 
     background-size: 80px; 
    } 

    .test:before { 
     top: 0px; 
    } 
    .test:after { 
     bottom: 0px; 
    } 

Siehe Demo

http://jsfiddle.net/yH59y/

+0

dies wird nicht funktionieren in Firefox, nur in Chrom –

+0

Es ist nur der Link aus dem Kommentar ? –

+0

für firefox: -webkit-border-image: -webkit-gradient (linear, links oben, links unten, von (# 00abeb) bis (#fff), color-stop (0.5, #fff), color- Stop (0,5, # 66cc00)) 21 30 30 21 Wiederholungswiederholung; –

13

Sie können es ohne pseudo-elements tun, nur mit border-image: linear-gradient

.fancy-border { 
 
    width: 150px; 
 
    height: 150px; 
 
    text-align:center; 
 
    border-top: 5px solid; 
 
    border-image: linear-gradient(to right, grey 25%, yellow 25%, yellow 50%,red 50%, red 75%, teal 75%) 5; 
 
}
<div class="fancy-border"> 
 
    my content 
 
</div>

+4

Dies sollte die beste Antwort sein, es ist viel weniger hacky als die derzeit akzeptierte. – Erick

+0

Wie macht man das mit nur 3 Farben? –

Verwandte Themen