2012-01-15 16 views
47

एक डीआईवी बनाना जो बाईं ओर त्रिकोण को आकर्षित करने के लिए सीएसएस का उपयोग करता है। माता-पिता और छद्म तत्व (छवियों को देखें) और कोड दोनों के लिए एक समान बॉक्स-छाया लागू करने का प्रयास कर रहे हैं।बॉक्स छाया के साथ सीएसएस स्पीच बबल

क्या यह संभव है? या मैं इसके लिए सीमा-छवि का उपयोग कर बेहतर हूं?

(शीर्ष: सीएसएस बॉक्स छाया, नीचे:: छाया, मध्य से पहले वांछित परिणाम)

Elements Before Box-Shadow is added

Elements with box-shadow added

The desired result

.bubble{ 
    height: 200px; 
    width: 275px; 

    opacity: 0; 

    margin-top: 41px; 

    float: right; 

    background-color: #F2F2F2; 

    -webkit-border-radius: 5px; 
    -webkit-box-shadow: 0px 0px 6px #B2B2B2; 
} 

.bubble::after { 
     height: 0px; 
     width: 0px; 

     content: "\00a0"; 

     display: block; 

     margin-left: -10px; 
     margin-top: 28px; 

     border-width: 10px 10px 10px 0; 
     border-style: solid; 
     border-color: transparent #F2F2F2 transparent transparent; 

     -webkit-box-shadow: 0px 0px 6px #B2B2B2; 
    } 

उत्तर

98

त्रिकोण हैक का उपयोग करने के बजाय, आप transform का उपयोग करके एक div को घुमा सकते हैं और वास्तविक box-shadow प्राप्त कर सकते हैं। चूंकि आप केवल div (दृश्यमान त्रिभुज पक्ष) के एक तरफ छाया चाहते हैं, तो आपको blur छोटे और opacity को कम करना होगा।

डेमो: http://jsfiddle.net/ThinkingStiff/mek5Z/

HTML:

<div class="bubble"></div> 

सीएसएस:

.bubble{ 
    background-color: #F2F2F2; 
    border-radius: 5px; 
    box-shadow: 0px 0px 6px #B2B2B2; 
    height: 200px; 
    margin: 20px; 
    width: 275px; 
} 

.bubble::after { 
    background-color: #F2F2F2; 
    box-shadow: -2px 2px 2px 0 rgba(178, 178, 178, .4); 
    content: "\00a0"; 
    display: block; 
    height: 20px; 
    left: -10px; 
    position: relative; 
    top: 20px; 
    transform:    rotate(45deg); 
     -moz-transform: rotate(45deg); 
     -ms-transform:  rotate(45deg); 
     -o-transform:  rotate(45deg); 
     -webkit-transform: rotate(45deg); 
    width: 20px; 
} 

आउटपुट:

enter image description here

+3

@ लॉर्डवर्लिन मैंने हाल ही में इसे एक आईफोन बैक बटन के लिए उपयोग किया था इसलिए मुझे एक छवि का उपयोग करने की आवश्यकता नहीं थी। और भी मज़ेदार के लिए आप त्रिकोण के कोण को बदलने के लिए 'ट्रांसफॉर्म: skew();' का उपयोग कर सकते हैं। – ThinkingStiff

+1

मैंने फ़ायरफ़ॉक्स 14 के साथ फ़िल्ड को चेक किया और यह एक त्रिकोण के बजाय आयताकार प्रदर्शित किया। ऐसा क्यों है? परिवर्तन सीएसएस एफएफ 14 में समर्थित है, है ना? – thomthom

+0

यह पता चला कि यह स्काई परिवर्तन था जिसे फ़ायरफ़ॉक्स पसंद नहीं आया ... – thomthom

4

मैं जानता हूँ कि यह एक छोटा सा है मुश्किल लेकिन, मुझे अच्छा लगता है। यहाँ बेला http://jsfiddle.net/dzfj6/

एचटीएमएल

<div class="bubble"> 
    <div class="triangle"></div> 
    <div class="border"></div> 
    <div class="content">some content</div> 
</div> 

सीएसएस

.bubble 
{ 
    height: 200px; 
    width: 275px; 
    float:right; 
    margin-top: 41px; 
    margin-left:11px; 
    background-color: #f2f2f2; 
    -webkit-border-radius: 5px; 
    -webkit-box-shadow: 0px 0px 5px #b2b2b2; 
    position:relative; 
    z-index:1; 
} 

.triangle 
{ 
    position:absolute; 
    top:12px; 
    width: 0; 
    height: 0; 
    border-top: 15px solid transparent; 
    border-bottom: 15px solid transparent; 
    border-right: 10px solid #f2f2f2; 
    margin-left:-9px; 
    z-index:3; 
} 
.border 
{   
    position:absolute; 
    top:12px; 
    width: 0; 
    height: 0; 
    border-top: 15px solid transparent; 
    border-bottom: 15px solid transparent; 
    border-right: 10px solid #e0e0e0; 
    margin-left:-10px; 
    z-index:2; 
} 

.content{ 
    padding:10px; 
} 

के बजाय box-shadow, तो आप बस buble के लिए border का उपयोग कर सकते है।

-4

0 का प्रयोग न करें।

height: 200px; 
    width: 275px; 
    float:right; 
    margin-top: 41px; 
    margin-left:11px; 
    background-color: #f2f2f2; 
    -webkit-border-radius: 5px; 
    -webkit-box-shadow: 0px 0px 5px #b2b2b2; 
    position:relative; 
    z-index:1; 
7

यहाँ नाक आकार छाया की चौड़ाई के लिए चर और एक वैकल्पिक सीमा के साथ पूर्ण (एस) सीएसएस में एक complete working example है।

चाल है कि ऑफसेट प्राप्त करें और पिक्सेल-पूर्णता प्राप्त करने के लिए सही रूप से परिवर्तित करें, और overflow:hidden का उपयोग अपने बबल की नाक को काटने के लिए आवश्यक है (विशेष रूप से यदि आपको सीमाओं की आवश्यकता है)।

उपर्युक्त उत्तर में उदाहरण हमारे लिए काम नहीं करता है क्योंकि छाया फसल हो जाती है और मुख्य बबल क्षेत्र में रखी जाती है।

आईई 7/8 में शानदार ढंग से गिरावट आई है।

HTML:

<div class="chat"> 
    <div class="bubble"> 
     <span class='tail'>&nbsp;</span> 
     <p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.</p><p>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p> 
    </div> 
</div> 

एससीएसएस:

$shadow_radius = 6px; 
$nose_size = 12px; 
$shadow = 0 1px $shadow_radius #B2B2B2; 
$border = 1px solid #bbb 

.chat { 
    font-family:  sans-serif; 
    font-size:  small; 
} 

.bubble { 
    background-color: #F2F2F2; 
    border-radius: 5px; 
    border:   $border; 
    box-shadow:  $shadow; 
    display:   inline-block; 
    padding:   10px 18px; 
    margin-left:  ($shadow_radius + $nose_size); 
    margin-right: ($shadow_radius + $nose_size); 
    position:   relative; 
    vertical-align: top; 
} 

.tail { 
    position: absolute; 
    top:  $nose_size; 
    left: -($shadow_radius + $nose_size); 
    height: ($shadow_radius + $nose_size); 
    width: ($shadow_radius + $nose_size); 
    overflow: hidden; 
} 
.tail:before { 
    border:   $border; 
    background-color: #F2F2F2; 
    box-shadow:  $shadow; 
    content:   "\00a0"; 

    display:   block; 
    position:   absolute; 
    top:    0px; 
    left:    $nose_size; 
    height:   $nose_size; 
    width:    $nose_size; 
    -webkit-transform: skew(-45deg); 
    -moz-transform: skew(-45deg); 
} 
2

एक अन्य समाधान filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); उपयोग करने के लिए यह केवल वस्तुओं आकार के चारों ओर छाया देता है।

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