2016-08-09 9 views
10

में बहु रंग सीमा कैसे बनाएं css3 में मल्टी-रंग सीमा कैसे बनाएं नीचे दी गई छवि की तरह?सीएसएस 3

enter image description here

+1

http://jsfiddle.net/yH59y/ आप एक सीमा छवि का उपयोग कर सकते हैं – Roysh

+1

: http: //www.w3schools। com/cssref/css3_pr_border-image.asp – Andrew

+1

इसे आज़माएं: http://www.hongkiat.com/blog/css-gradient-border/ –

उत्तर

16

आप :after या :before छद्म तत्व और सीएसएस linear-gradient साथ यह कर सकते हैं जैसा कि नीचे दिखाया:

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

यह काम करता है! धन्यवाद – Radian

+0

@ रैडियन आपका स्वागत है) –

2

यह कोशिश करो।

<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; 
    } 

देखें डेमो

http://jsfiddle.net/yH59y/

+0

यह फ़ायरफ़ॉक्स में काम नहीं करेगा, केवल क्रोम –

+0

में यह टिप्पणी से केवल लिंक है ? –

+0

फ़ायरफ़ॉक्स के लिए: -webkit-border-image: -webkit-gradient (रैखिक, बाएं शीर्ष, बाएं नीचे, (# 00abeb) से, (#fff), रंग-रोक (0.5, #fff), रंग- रोकें (0.5, # 66cc00)) 21 30 30 21 दोहराना दोहराना; –

13

आप pseudo-elements बिना यह कर सकते हैं, बस के साथ 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

यह शीर्ष उत्तर होना चाहिए, यह वर्तमान में स्वीकार किए गए एक से कम हैकी है। – Erick

+0

इसे केवल 3 रंगों के साथ कैसे करें? –

संबंधित मुद्दे