亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > HTML > 正文

使用css3 屬性如何豐富圖片樣式(圓角 陰影 漸變)

2024-08-26 00:15:13
字體:
來源:轉載
供稿:網友

在css3中,直接在圖片上使用box-shadow 和 border-radius,瀏覽器并不能很好的渲染。但是如果把圖片作為background-image,添加的樣式瀏覽器可以很好的渲染。我將會介紹如何使用box-shadow, border-radius 和 transition創建不同圖片樣式效果。
問題
通過查看demo能注意到,我們為第一行圖片設置了border-radius 和 內嵌box-shadow。firefox渲染了圖片的border-radius,但是沒有渲染內嵌box-shadow。chrome和Safari兩種效果都沒有渲染。

復制代碼 代碼如下:www.CuoXIn.com

.normal img {
border: solid 5px #000;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
-webkit-box-shadow: inset 0 1px 5px rgba(0,0,0,.5);
-moz-box-shadow: inset 0 1px 5px rgba(0,0,0,.5);
box-shadow: inset 0 1px 5px rgba(0,0,0,.5);
}

firefox效果
 
chrome/safari
 

變通方案
為了使border-radius 和 內嵌box-shadow能夠正常工作,我們需要把圖片轉換成background-image的方式。
 
動態方式
為了動態完成這一工作,我們需要借助jquery為每一個圖片添加背景圖片的包裝。下面的js代碼為每一個圖片添加了一個span的包裝,span的背景圖片路徑就是圖片的路徑。
代碼比較簡單,我想就沒有講解的必要了。不清楚了可以直接去查jquery的api。

復制代碼 代碼如下:www.CuoXIn.com

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("img").load(function() {
$(this).wrap(function(){
return '<span class="image-wrap ' + $(this).attr('class') + '" style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
});
$(this).css("opacity","0");
});
});
</script>

輸出
上面的代碼會輸出如下結果:

復制代碼 代碼如下:www.CuoXIn.com

<span class="image-wrap " style="position:relative; display:inline-block; background:url(image.jpg) no-repeat center center; width: 150px; height: 150px;">
<img src="image.jpg" style="opacity: 0;">
</span>

圓形圖片
添加我們使用border-radius來實現圓形圖片的效果,效果如下:
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.circle .image-wrap {
-webkit-border-radius: 50em;
-moz-border-radius: 50em;
border-radius: 50em;
}

卡片風格
下面是卡片風格的圖片,使用了多個內嵌box-shadow。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.card .image-wrap {
-webkit-box-shadow: inset 0 0 1px rgba(0,0,0,.8), inset 0 2px 0 rgba(255,255,255,.5), inset 0 -1px 0 rgba(0,0,0,.4);
-moz-box-shadow: inset 0 0 1px rgba(0,0,0,.8), inset 0 2px 0 rgba(255,255,255,.5), inset 0 -1px 0 rgba(0,0,0,.4);
box-shadow: inset 0 0 1px rgba(0,0,0,.8), inset 0 2px 0 rgba(255,255,255,.5), inset 0 -1px 0 rgba(0,0,0,.4);
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}

浮雕風格
下面是浮雕效果。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.embossed .image-wrap {
-webkit-box-shadow: inset 0 0 2px rgba(0,0,0,.8), inset 0 2px 0 rgba(255,255,255,.5), inset 0 -7px 0 rgba(0,0,0,.6), inset 0 -9px 0 rgba(255,255,255,.3);
-moz-box-shadow: inset 0 0 2px rgba(0,0,0,.8), inset 0 2px 0 rgba(255,255,255,.5), inset 0 -7px 0 rgba(0,0,0,.6), inset 0 -9px 0 rgba(255,255,255,.3);
box-shadow: inset 0 0 2px rgba(0,0,0,.8), inset 0 2px 0 rgba(255,255,255,.5), inset 0 -7px 0 rgba(0,0,0,.6), inset 0 -9px 0 rgba(255,255,255,.3);
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}

柔性浮雕風格
相對于浮雕樣式,新樣式添加了1px blur屬性。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.soft-embossed .image-wrap {
-webkit-box-shadow: inset 0 0 4px rgba(0,0,0,1), inset 0 2px 1px rgba(255,255,255,.5), inset 0 -9px 2px rgba(0,0,0,.6), inset 0 -12px 2px rgba(255,255,255,.3);
-moz-box-shadow: inset 0 0 4px rgba(0,0,0,1), inset 0 2px 1px rgba(255,255,255,.5), inset 0 -9px 2px rgba(0,0,0,.6), inset 0 -12px 2px rgba(255,255,255,.3);
box-shadow: inset 0 0 4px rgba(0,0,0,1), inset 0 2px 1px rgba(255,255,255,.5), inset 0 -9px 2px rgba(0,0,0,.6), inset 0 -12px 2px rgba(255,255,255,.3);
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}

摳圖風格
使用內嵌box-shadow就可以實現摳圖效果。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.cut-out .image-wrap {
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 4px 5px rgba(0,0,0,.6), inset 0 1px 0 rgba(0,0,0,.6);
-moz-box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 4px 5px rgba(0,0,0,.6), inset 0 1px 0 rgba(0,0,0,.6);
box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 4px 5px rgba(0,0,0,.6), inset 0 1px 0 rgba(0,0,0,.6);
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}

變形和發光
在這個例子中我們為圖片包裝添加transition屬性,鼠標滑過的時候,他會從圓角變為圓形。然后我們使用多個box-shadow實現發光效果。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.morphing-glowing .image-wrap {
-webkit-transition: 1s;
-moz-transition: 1s;
transition: 1s;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
.morphing-glowing .image-wrap:hover {
-webkit-box-shadow: 0 0 20px rgba(255,255,255,.6), inset 0 0 20px rgba(255,255,255,1);
-moz-box-shadow: 0 0 20px rgba(255,255,255,.6), inset 0 0 20px rgba(255,255,255,1);
box-shadow: 0 0 20px rgba(255,255,255,.6), inset 0 0 20px rgba(255,255,255,1);
-webkit-border-radius: 60em;
-moz-border-radius: 60em;
border-radius: 60em;
}

高光效果
高光的效果是通過為元素添加 :after 偽類實現的。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.glossy .image-wrap {
-webkit-box-shadow: inset 0 -1px 0 rgba(0,0,0,.5);
-moz-box-shadow: inset 0 -1px 0 rgba(0,0,0,.5);
box-shadow: inset 0 -1px 0 rgba(0,0,0,.5);
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
.glossy .image-wrap:after {
position: absolute;
content: ' ';
width: 100%;
height: 50%;
top: 0;
left: 0;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
background: -moz-linear-gradient(top, rgba(255,255,255,0.7) 0%, rgba(255,255,255,.1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0.7)), color-stop(100%,rgba(255,255,255,.1)));
background: linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,.1) 100%);
}

倒影效果
在這個例子中,我們將高光效果移到底部就實現倒影效果。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.reflection .image-wrap:after {
position: absolute;
content: ' ';
width: 100%;
height: 30px;
bottom: -31px;
left: 0;
-webkit-border-top-left-radius: 20px;
-webkit-border-top-right-radius: 20px;
-moz-border-radius-topleft: 20px;
-moz-border-radius-topright: 20px;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
background: -moz-linear-gradient(top, rgba(0,0,0,.3) 0%, rgba(255,255,255,0) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,.3)), color-stop(100%,rgba(255,255,255,0)));
background: linear-gradient(top, rgba(0,0,0,.3) 0%,rgba(255,255,255,0) 100%);
}
.reflection .image-wrap:hover {
position: relative;
top: -8px;
}

高光和倒影
本例我們使用:before 和 :after 將高光和倒影效果組合起來。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.glossy-reflection .image-wrap {
-webkit-box-shadow: inset 0 -1px 0 rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.6);
-moz-box-shadow: inset 0 -1px 0 rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.6);
box-shadow: inset 0 -1px 0 rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.6);
-webkit-transition: 1s;
-moz-transition: 1s;
transition: 1s;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
.glossy-reflection .image-wrap:before {
position: absolute;
content: ' ';
width: 100%;
height: 50%;
top: 0;
left: 0;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
background: -moz-linear-gradient(top, rgba(255,255,255,0.7) 0%, rgba(255,255,255,.1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0.7)), color-stop(100%,rgba(255,255,255,.1)));
background: linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,.1) 100%);
}
.glossy-reflection .image-wrap:after {
position: absolute;
content: ' ';
width: 100%;
height: 30px;
bottom: -31px;
left: 0;
-webkit-border-top-left-radius: 20px;
-webkit-border-top-right-radius: 20px;
-moz-border-radius-topleft: 20px;
-moz-border-radius-topright: 20px;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
background: -moz-linear-gradient(top, rgba(230,230,230,.3) 0%, rgba(230,230,230,0) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(230,230,230,.3)), color-stop(100%,rgba(230,230,230,0)));
background: linear-gradient(top, rgba(230,230,230,.3) 0%,rgba(230,230,230,0) 100%);
}

膠帶風格
在這個例子中,我們使用:after來實現膠帶的效果。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.tape .image-wrap {
-webkit-box-shadow: inset 0 0 2px rgba(0,0,0,.7), inset 0 2px 0 rgba(255,255,255,.3), inset 0 -1px 0 rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
-moz-box-shadow: inset 0 0 2px rgba(0,0,0,.7), inset 0 2px 0 rgba(255,255,255,.3), inset 0 -1px 0 rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
box-shadow: inset 0 0 2px rgba(0,0,0,.7), inset 0 2px 0 rgba(255,255,255,.3), inset 0 -1px 0 rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
}
.tape .image-wrap:after {
position: absolute;
content: ' ';
width: 60px;
height: 25px;
top: -10px;
left: 50%;
margin-left: -30px;
border: solid 1px rgba(137,130,48,.2);
background: -moz-linear-gradient(top, rgba(254,243,127,.6) 0%, rgba(240,224,54,.6) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(254,243,127,.6)), color-stop(100%,rgba(240,224,54,.6)));
background: linear-gradient(top, rgba(254,243,127,.6) 0%,rgba(240,224,54,.6) 100%);
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 1px 0 rgba(0,0,0,.2);
}

變形和著色
在這個例子中,我們在元素上使用:after,當鼠標進過的時候實現徑向漸變的效果。

css:

復制代碼 代碼如下:www.CuoXIn.com

.morphing-tinting .image-wrap {
position: relative;
-webkit-transition: 1s;
-moz-transition: 1s;
transition: 1s;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
.morphing-tinting .image-wrap:hover {
-webkit-border-radius: 30em;
-moz-border-radius: 30em;
border-radius: 30em;
}
.morphing-tinting .image-wrap:after {
position: absolute;
content: ' ';
width: 100%;
height: 100%;
top: 0;
left: 0;
-webkit-transition: 1s;
-moz-transition: 1s;
transition: 1s;
-webkit-border-radius: 30em;
-moz-border-radius: 30em;
border-radius: 30em;
}
.morphing-tinting .image-wrap:hover:after {
background: -webkit-gradient(radial, 50% 50%, 40, 50% 50%, 80, from(rgba(0,0,0,0)), to(rgba(0,0,0,1)));
background: -moz-radial-gradient(50% 50%, circle, rgba(0,0,0,0) 40px, rgba(0,0,0,1) 80px);
}

羽化邊緣圓形
我們同樣可以使用徑向漸變產生遮罩,實現羽化的效果。
 
css:

復制代碼 代碼如下:www.CuoXIn.com

.feather .image-wrap {
position: relative;
-webkit-border-radius: 30em;
-moz-border-radius: 30em;
border-radius: 30em;
}
.feather .image-wrap:after {
position: absolute;
content: ' ';
width: 100%;
height: 100%;
top: 0;
left: 0;
background: -webkit-gradient(radial, 50% 50%, 50, 50% 50%, 70, from(rgba(255,255,255,0)), to(rgba(255,255,255,1)));
background: -moz-radial-gradient(50% 50%, circle, rgba(255,255,255,0) 50px, rgba(255,255,255,1) 70px);
}

瀏覽器兼容性
這種實現方式在大多數支持border-radius, box-shadow, :before and :after特性的瀏覽器中(例如Chrome, Firefox 和 Safari),都能很好的工作。在不支持新特性的瀏覽器中,只會顯示原始圖片。
創造你自己的實現
借助:before 和:after偽類能為圖片創造很多種樣式,你可以自己嘗試創建出新的效果。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美激情第6页| 亚洲区中文字幕| 久久久免费精品视频| 亚洲一区二区三区成人在线视频精品| 91精品国产91久久久| 欧美激情亚洲一区| 欧美亚洲在线播放| 亚洲xxxxx电影| 91免费人成网站在线观看18| 97久久久免费福利网址| 欧美成人中文字幕| 欧美高清在线视频观看不卡| 日韩精品视频在线播放| 国产精品男女猛烈高潮激情| 中文字幕在线观看亚洲| 日韩欧美在线免费观看| 成人信息集中地欧美| 伊人亚洲福利一区二区三区| 亚洲精品suv精品一区二区| 在线看欧美日韩| 日本国产欧美一区二区三区| 日韩在线视频二区| 亚洲自拍偷拍色片视频| 国产丝袜精品视频| 亚洲最大av网站| 国产精品国产亚洲伊人久久| 欧美性生交xxxxx久久久| 中文字幕在线看视频国产欧美在线看完整| 日韩精品极品视频| 第一福利永久视频精品| 欧美亚洲日本黄色| 青青a在线精品免费观看| 欧美国产日本高清在线| 亚洲xxx大片| 中文字幕精品—区二区| 国产日韩在线精品av| 黄色91在线观看| 欧美激情2020午夜免费观看| 777精品视频| 国产精品看片资源| 欧美性色视频在线| 91视频8mav| 久久久久久久999| 欧美亚洲一区在线| 亚洲电影免费观看高清完整版在线| 国产免费一区二区三区在线观看| 亚洲美女av在线播放| 日韩免费在线看| 午夜精品久久久久久久99热浪潮| 久久久精品久久久| 国产黑人绿帽在线第一区| 国产欧美精品日韩| 久久精品欧美视频| 日韩av免费在线观看| 日韩精品在线播放| 欧美一级大片在线观看| 色在人av网站天堂精品| 国产成人亚洲综合青青| 国产偷国产偷亚洲清高网站| …久久精品99久久香蕉国产| 日韩av最新在线观看| 日韩欧美国产网站| 成人国产精品av| 欧美成人一区二区三区电影| 国产精品看片资源| 2023亚洲男人天堂| 夜夜嗨av一区二区三区四区| 91精品国产91久久久久久不卡| 2019日本中文字幕| 亚洲精品自拍视频| 日本午夜在线亚洲.国产| 97国产真实伦对白精彩视频8| 精品福利在线看| 国产日本欧美一区| 成人免费大片黄在线播放| 中文字幕日韩欧美在线视频| 日韩成人av网| 日韩hd视频在线观看| 日韩精品一区二区视频| 91人人爽人人爽人人精88v| 欧美激情网站在线观看| 国产精品爽爽爽| 51久久精品夜色国产麻豆| 国产免费亚洲高清| 国产精品mp4| 亚洲天堂成人在线| 欧美成人在线影院| 国产精品久久久一区| 亚洲美女www午夜| 国产91精品久久久久久久| 欧美高清不卡在线| 精品偷拍一区二区三区在线看| 国产精品第10页| 欧美激情视频网址| 久99九色视频在线观看| 欧美一区二区三区……| 亚洲精品国精品久久99热| 国产mv免费观看入口亚洲| 亚洲欧美成人精品| 国模精品视频一区二区| 成人av电影天堂| 亚洲人线精品午夜| 粗暴蹂躏中文一区二区三区| 日本a级片电影一区二区| 国产精品日韩久久久久| 日韩美女在线观看一区| 91免费高清视频| 在线观看亚洲区| 欧美成人在线免费视频| 亚洲国产成人久久| 欧美极品少妇xxxxⅹ免费视频| 国产亚洲精品成人av久久ww| 欧美日韩激情网| 欧美精品成人91久久久久久久| 国产精品久久91| 亚洲人成电影网站色| 久久久精品一区| 国产成人精品视频在线观看| 成人午夜激情免费视频| 在线日韩日本国产亚洲| 91中文字幕在线观看| 美女国内精品自产拍在线播放| 亚洲欧美在线第一页| 色琪琪综合男人的天堂aⅴ视频| 2019中文字幕在线观看| 97免费视频在线播放| 成人激情黄色网| 热久久免费视频精品| 亚洲图片在区色| 亚洲精品一区二区在线| 国产不卡一区二区在线播放| 91久久精品美女| 国产精品爽爽ⅴa在线观看| 中文字幕精品在线视频| 成人精品一区二区三区电影黑人| 国产成人中文字幕| 国产成人综合av| 国产精品亚洲激情| 日韩电影中文字幕av| 一区二区福利视频| 国产精品成人观看视频国产奇米| 久久免费视频在线观看| 国产一区二区av| 日本电影亚洲天堂| 庆余年2免费日韩剧观看大牛| 91免费看片网站| 欧美一区二区三区四区在线| 国产精品极品美女粉嫩高清在线| 亚洲欧洲在线免费| 日本中文字幕久久看| 亚洲久久久久久久久久久| 久久精品色欧美aⅴ一区二区| 国产人妖伪娘一区91| 亚洲精品一区二区三区不| 欧美日韩一区二区三区在线免费观看| 亚洲乱码一区av黑人高潮| 国产精品电影久久久久电影网| 国产精品视频999| 欧美成人免费在线观看| 亚洲va欧美va在线观看| 国产欧美一区二区三区久久人妖| 成人激情综合网| 668精品在线视频| 日韩精品在线观看视频|