2011/02/20

drop-shadows without images 圖文框陰影效果

[CSS drop-shadows without images – Nicolas Gallagher]一文教大家用很簡單的CSS樣式即可讓圖文框顯示陰影效果。

吳哥窟

全部的特效請看作者的範例:[Demo CSS drop-shadows without images – Nicolas Gallagher],瀏覽器的版本必須是[Firefox 3.5+, Chrome 5+, Safari 5+, Opera 10.6+, IE 9+]。

以下簡單介紹如何將這個特效應用到blog裡。

首先,直接將[Demo CSS drop-shadows without images – Nicolas Gallagher]的CSS樣式稍作修改後,貼到 blog的CSS樣式表中。如下:

/*CSS drop-shadows without images – Nicolas Gallagher*/
        /* Shared styles */
        
        .drop-shadow {
            position:relative;
            float:left;
            padding:1em; 
            margin:2em 10px 4em; 
            background:#fff;
            -webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 60px rgba(0, 0, 0, 0.1) inset;
               -moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
                    box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
        }
 
        .drop-shadow:before,
        .drop-shadow:after {
            content:"";
            position:absolute; 
            z-index:-2
        }
        
        .drop-shadow p {
            font-size:16px;
            font-weight:bold;
        }
        
        /* Lifted corners */
 
        .lifted {
            -moz-border-radius:4px; 
                 border-radius:4px;
        }
        
        .lifted:before,
        .lifted:after { 
            bottom:15px;
            left:10px;
            -webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);   
               -moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
                    box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
            -webkit-transform:rotate(-3deg);    
               -moz-transform:rotate(-3deg);   
                -ms-transform:rotate(-3deg);   
                 -o-transform:rotate(-3deg);
                    transform:rotate(-3deg);
        }
        
        .lifted:after {
            right:10px; 
            left:auto;
            -webkit-transform:rotate(3deg);   
               -moz-transform:rotate(3deg);  
                -ms-transform:rotate(3deg);  
                 -o-transform:rotate(3deg);
                    transform:rotate(3deg);
        }
        
        /* Curled corners */
 
        .curled {
            border:1px solid #efefef; 
            -moz-border-radius:0 0 120px 120px / 0 0 6px 6px;    
                 border-radius:0 0 120px 120px / 0 0 6px 6px;
        }
      
        .curled:before,
        .curled:after {
            bottom:12px;
            left:10px;
            -webkit-box-shadow:0 8px 12px rgba(0, 0, 0, 0.5); 
               -moz-box-shadow:0 8px 12px rgba(0, 0, 0, 0.5); 
                    box-shadow:0 8px 12px rgba(0, 0, 0, 0.5); 
            -webkit-transform:skew(-8deg) rotate(-3deg);
               -moz-transform:skew(-8deg) rotate(-3deg);
                -ms-transform:skew(-8deg) rotate(-3deg);
                 -o-transform:skew(-8deg) rotate(-3deg);
                    transform:skew(-8deg) rotate(-3deg);
        } 
      
        .curled:after { 
            right:10px; 
            left:auto;
            -webkit-transform:skew(8deg) rotate(3deg); 
               -moz-transform:skew(8deg) rotate(3deg);     
                -ms-transform:skew(8deg) rotate(3deg);     
                 -o-transform:skew(8deg) rotate(3deg); 
                    transform:skew(8deg) rotate(3deg);
        }
        
        /* Perspective */
 
        .perspective:before {
            left:80px;
            bottom:5px;
            -webkit-box-shadow:-80px 0 8px rgba(0, 0, 0, 0.4);
               -moz-box-shadow:-80px 0 8px rgba(0, 0, 0, 0.4);
                    box-shadow:-80px 0 8px rgba(0, 0, 0, 0.4);
            -webkit-transform:skew(50deg);
               -moz-transform:skew(50deg);
                -ms-transform:skew(50deg);
                 -o-transform:skew(50deg);
                    transform:skew(50deg);
            -webkit-transform-origin:0 100%;
               -moz-transform-origin:0 100%;
                -ms-transform-origin:0 100%;
                 -o-transform-origin:0 100%;
                    transform-origin:0 100%;
        }
        
        .perspective:after {
            display:none;
        }
        
        /* Raised shadow - no pseudo-elements needed */
        
        .raised {
            -webkit-box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
               -moz-box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
                    box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
        }
        
        /* Curved shadows */
 
        .curved:before {
            top:10px;
            bottom:10px;
            left:0;
            right:50%;
            -webkit-box-shadow:0 0 15px rgba(0,0,0,0.6);
            -moz-box-shadow:0 0 15px rgba(0,0,0,0.6);
            box-shadow:0 0 15px rgba(0,0,0,0.6);
            -moz-border-radius:10px / 100px;
            border-radius:10px / 100px;
        }
        
        .curved-vt-2:before {
            right:0;
        }
        
        .curved-hz-1:before {
            top:50%;
            bottom:0;
            left:10px;
            right:10px;
            -moz-border-radius:100px / 10px;
            border-radius:100px / 10px;
        }
 
        .curved-hz-2:before {
            top:0;
            bottom:0;
            left:10px;
            right:10px;
            -moz-border-radius:100px / 10px;
            border-radius:100px / 10px;
        }
        
        /* Rotated box */
        
        .rotated {
            -webkit-box-shadow:none;
               -moz-box-shadow:none;
                    box-shadow:none;
            -webkit-transform:rotate(-3deg);    
               -moz-transform:rotate(-3deg);   
                -ms-transform:rotate(-3deg);
                 -o-transform:rotate(-3deg);
                    transform:rotate(-3deg);
        }
        
        .rotated :first-child:before {
            content:"";
            position:absolute;
            z-index:-1;
            top:0;
            bottom:0;
            left:0;
            right:0;
            background:#fff;
            -webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 60px rgba(0, 0, 0, 0.1) inset;
               -moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
                    box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset
        }
 
/*CSS drop-shadows without images – Nicolas Gallagher*/

以[drop-shadow raised]為例,如本文試作的照片外框效果,在blog的寫法如下:

<div style="margin-left: 120px" class="drop-shadow raised">
  <p style="margin: 5px" align="center"><a title="Flickr 上 gabriel wang 的 吳哥窟" href="http://www.flickr.com/photos/gabriel_tw/5375261899/"><img alt="吳哥窟" src="http://farm6.static.flickr.com/5004/5375261899_a3e3baf4a3_z.jpg" width="640" height="428" /></a></p>
</div>

❏在<div class="drop-shadow raised"></div>裡加上 style="margin-left: 120px",以使圖文框的左邊縮排120px。

❏在<div>段裡插入圖片,使用<p style="margin: 5px" align="center"></p>,以使圖片居中,其中style="margin: 5px"可使圖文框的邊界產生5px的間距。

在blog裡並非所有的特效都能正常顯示,有待高人賜解。

Lifted corners

Curled corners

Perspective

Raised box

Single vertical curve

Vertical curves

Single horizontal curve

Horizontal curves

Rotated box

沒有留言:

張貼留言