2011年12月1日 星期四

手機版網頁為何會放大呢?因為網頁檔頭宣告設定問題!



網 頁自動切換合適的網頁後,接下來就是要開始來製作手機版的網頁囉!手機或是電腦的網頁看起來是相同,只要電腦版能正常運作,在手機上應該都可正常預覽,如 果要專門讓手機來瀏覽時,這時就有點不太相同了,除了版面要另外設計外,還有一個相當重要的東西,那就是HTML檔頭的宣告,一般在設計網頁時,上面所宣 告的是給電腦版使用,目前大多使用XHTML的設定,若用此宣告放到手機版時,則會發現到怎網頁的版面都縮小,這是由於手機內建的瀏覽器,當網頁為電腦版 就會把版面撐到980像素,所以當要開始製作手機版網頁時,首先要做就是檔頭的宣告,這樣網頁在手機下,才能正常顯示手機版的尺寸大小。

宣告的部分有二種方式,一種是加在html上,另一種是加在~之間,二者取其一就行了,若要二邊都加的話也可以。

第一種方法、加在上方:
程序代碼 程序代碼


第二種方法、加在~之間:
程序代碼 程序代碼


完成這些動作後,再用手機瀏覽看看,這時版面就不會縮起來,就會依照手機的顯示尺寸,只要一個小動作卻有180度的大不同!要不然忌諱做出怪怪的手機專屬網頁喔!
文章提供:: BAYSTARS DESIGN網頁設計公司

2011年11月29日 星期二

馴服CSS選擇器 - 健壯我們的樣式表

PPT:Taming CSS Selectors
作者:Nicole Sullivan

CSS 文件的大小和所引起的 HTTP 的請求數

是 CSS 性能的最關鍵因素

回流(reflow)和渲染時間

(非常!)沒那麼重要

副本(duplication)比陳舊的規則(stale rules)更糟糕

因為我們有工具處理後者

定義缺省值

不要在每處都重複編碼

不好的:
程序代碼 程序代碼
#weatherModule h3{color:red;}
#tabs h3{color:blue;}

推薦:
程序代碼 程序代碼
h1, .h1{...}
h2, .h2{...}
h3, .h3{...}
h4, .h4{...}
h5, .h5{...}
h6, .h6{...}


用單獨的 class 來定義結構

不要在每處都重複編碼



使用 class

而不是元素選擇器

不好的:
程序代碼 程序代碼
div.error{...}

推薦:
程序代碼 程序代碼
.error{絕大多數代碼寫在這裡}
div.error{單獨定義}
p.error{單獨定義}
em.error{單獨定義}


避免使用元素選擇器

初始化除外

不好的:
程序代碼 程序代碼
div{...}
ul{...}
p{...}

推薦:
程序代碼 程序代碼
.error{...}
.section{...}
.products{...}


給規則同樣的權重

使用級聯去重寫先前的規則

不好的:
程序代碼 程序代碼
.myModule .inner b{...}
.myModule2 b{...}

推薦:
程序代碼 程序代碼
.myModule b{...}
.myModule2 b{...}


保守的使用 hack

不好的:
程序代碼 程序代碼
.mod .hd{...}
.ie .mod .hd{...}
.weatherMod .hd{...}

推薦:
程序代碼 程序代碼
.mod .hd{color:red;_zoom:1;}
.weatherMod .hd{...}

註: 此點來自 The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax Experience 2009 第96P,為作者在 Ajax Experience 2009 上所做的補充。

避免指定位置

應用 class 在你想要改變的對象上

不好的:
程序代碼 程序代碼
.sidebar ul{...}
.header ul{...}

推薦:
程序代碼 程序代碼
.mainNav{...}
.subNav{...}


避免太過特別的 class

它們是都有語義的,而且有限制

不好的:
程序代碼 程序代碼
.ducatiMonster620{...}
.nicolesDucatiMonster620{...}

推薦:
程序代碼 程序代碼
.vehicle{...}
.motorcycle{...}


避免單獨的定義

id 在每個頁面只能使用一次

不好的:
程序代碼 程序代碼
#myUniqueIdentifier{...}
#myUniqueIdentifier2{...}


混合使用

避免重複編碼





封裝

不要直接訪問對象的子節點



不好的:
程序代碼 程序代碼
.inner{...}
.tr{...}
.bl{...}

推薦:
程序代碼 程序代碼
.weatherMod .inner{...}
.weatherMod .tr{...}
.weatherMod .bl{...}


譯文原文:點這裡...
文章提供:: BAYSTARS DESIGN網頁設計公司

2011年11月28日 星期一

網頁設計應急小技巧

工作中,網頁設計師經常會遇見這些狀況:時間這麼短又要出彩、又是要大氣要有氣氛、風格不明確很難把握、欄目這麼多頁面又這麼長……

突然覺得束手無策,腦袋裡一片空白,沒想法了,怎麼辦?
下面簡淺的歸納了幾個快速讓頁面出彩的小技巧:

1.旋轉法 – 將頁面的主體或局部進行旋轉



我們一般的頁面版式都是方方正正,四平八穩,有點呆板。如果將局部或整體適當的旋轉,打破穩定的構圖,畫面就會動感有趣一些。
對於上圖,這種基調輕鬆活潑又恰好內容比較少的頁面來說,主體整個旋轉後,畫面馬上輕鬆活潑起來,看過現在這個畫面,真是無法想像未旋轉前的平淡。同時,相比大塊的方形空白,不規則的余白也不會顯得空洞。



上圖,將背景旋轉後,大面積的斜面產生了很強的速度感,賽車急速飛馳著,好像下一秒就要從電腦中衝出來一樣,傾斜的大標題和旋轉後的背景交叉配合,使畫面整個都運動起來。這種方法可以應用到很多運動的主題上。

2.黃金分割法 – 靈活運用黃金比例分割的辦法將頁面「切」開



黃金比率被認為是最理想的矩形比例,在過去的文化遺產中也有很多這樣的遺存。將這個比率應用到版式設計中,也能夠設計出容易為用戶所喜歡的構圖。但不要被這些比例所束縛,很多是靠自己的感覺去應用。
上圖,除去背景無非就是一個排版清晰的頁面,將背景分割後,對比的色塊使畫面產生縱深感,頁面的豐富性和視覺衝擊力迅速增強。人物也好像著陸了一樣,平穩的站在畫面中。



上圖,用反差強烈的色塊進行分割,強調了版塊的劃分,即使有很多地方需要強調,也能讓用戶迅速清楚各版塊的重點,不用像以往一樣1、2、3…… 將內容依次豎排下來,鼠標都已經拖到第三屏了還沒完沒了,又沒什麼新鮮感。

3.曲線法 – 將曲線用於背景或版塊分割,消除矩形分割的生硬感。



與直線相比,曲線具有圓潤的特點,讓人感覺輕鬆、愉悅。增強視覺感的同時也能夠營造活躍的氣氛。
上圖中,大眾的logo和焦點圖中的機器人產品,全部由曲線組成,這種情況下,用曲線來分割背景和焦點就顯得理所當然了,畫面中曲線合理的運用也提高了層次感,機器人和紅色標題都更突出。



仿照球的運動軌跡,貫穿著整個頁面的曲線,將用戶直觀的帶入了正在激烈進行的棒球比賽現場。看似隨意,其實用曲線精當的將標題、焦點圖和新聞等版塊按重點進行了不同比例的分割。


4.借用法 – 借用現實中的東西,將實物抽像化,提煉出大形輪廓用於背景



現實中的東西也可以應用到網頁設計中?當然可以,只要想的到。
如圖,信封是我們生活中常用的東西,如此生活化的東西借用到網頁上,展開在用戶面前,好像郵寄給您的信一樣,立馬讓人眼前一亮,親切感油然而生。作為遊戲活動的通告頁,用白色的信紙來盛放主體內容也再合適不過。



上圖,將賽車在賽道上疾馳的場面置放到頁面上作為背景,虛化的大城市,放大的賽道,飛奔的賽車……就像此刻坐在電腦前玩賽車,左手正緊緊按著W、A、S、D鍵一樣。讓用戶身臨其境,完全抓住了對方眼球。
以此類推,生活中很多東西都可以借用,例如:寫滿粉筆字的黑板、電腦的屏幕、寫日記的本子、老古董的地圖,空曠的足球場……


5.三角拼貼法 – 像做手工一樣,將裁剪好的三角形打亂,重新拼貼



不同的幾何形狀有不同的性格,圓形是活潑可愛的,方形是平穩整齊的,三角形就是尖銳動感的。
三角形的不平衡性及其尖銳性能夠增強視覺上的刺激,快速吸引用戶,可以用於科技和時尚這種風格同樣比較「鋒利」的網頁。
上圖,將同色系小三角形均勻的拼貼起來,馬上就營造出一種鑽石璀璨般的時尚感。但實踐的時候要注意加減法,不能亂堆一通,點到為止即可。



上圖,用艷麗的三角形對頁面進行劃分、拼貼。大小的組合,色塊的對比,能夠帶給用戶強烈的視覺衝擊力。在搭配的時候,注意主次,以一個大的形狀為主,給內容擺放留下足夠空間,與其他輔助的小形狀相區別。

6.色塊分割法 – 將各版塊用不同顏色來區別



經常面對需求方這裡是重點、那也是重點、那那那也挺重要,統統需要突出的要求,對於主題比較明快的頁面 可以考慮將版塊用不同顏色來區別,通過色塊來強化頁面版式和佈局,難度較大的是在色彩搭配上要取得平衡。

上圖,版式在頁面都以塊來體現,沒有什麼效果,為了突出重點,在重要區域選擇了飽和度較高的紅黃綠三個顏色,產生明確的視覺中心,讓用戶能夠按照我們希望的那樣閱讀下去。但對比色調容易造成不和諧,紅黃綠之間加上灰底的中性色來調和一下就顯得不會突兀了。



當使用四到五種純色進行搭配的時候,注意只要色相、純度、明度三個屬性中有一個屬性是基本相同或者接近,搭配起來基本上都不會覺得太牽強。

以上幾個小技巧可以在情況緊急時參考,大家也可以用類似的方法總結出更多的小技巧自用。

原文:看這裡...


文章來自:: ued163

文章提供:: BAYSTARS DESIGN網頁設計公司

2011年11月23日 星期三

非常有用的CSS模板

下面是CSS模板清單,將幫助您減少手酸,煩惱,節省您在寫CSS的時間了,希望你會發現它很有用。無論你是一個有經驗的Web開發者,或剛開始使用CSS的初學者,都值得一試。



CSS Reset (CSS固定樣板)
程序代碼 程序代碼
/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}


Browser-Specific CSS Hacks (瀏覽器特定CSSHacks)
程序代碼 程序代碼
/* IE6 and below */
* html #uno  { color: red }

/* IE7 */
*:first-child+html #dos { color: red }

/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }

/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }

/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#diez  { color: red  }
}

/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
#veintiseis { color: red  }
}

/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* Everything but IE6-8 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }

/* FF 3.5+ */
body:not(:-moz-handler-blocked) #cuarenta { color: red; }

/* IE6 */
#once { _color: blue }

/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }

/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }

/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */

/* IE8, IE9 */
#anotherone  {color: blue\0/;} /* must go at the END of all rules */


A New Micro Clearfix Hack (清除浮動的CSS)
程序代碼 程序代碼
/* For modern browsers */
.cf:before,
.cf:after {
    content:"";
    display:table;
}

.cf:after {
    clear:both;
}

/* For IE 6/7 (trigger hasLayout) */
.cf {
    zoom:1;
}


Font Sizing (字體設置)
程序代碼 程序代碼
html { font-size: 62.5%; }
body { font-size: 14px; font-size: 1.4rem; } /* =14px */
h1   { font-size: 24px; font-size: 2.4rem; } /* =24px */


The New @Font-Face Syntax (自設字體樣式)
程序代碼 程序代碼
@font-face {
    font-family: 'MyFontFamily';
    src: url('myfont-webfont.eot?#iefix') format('embedded-opentype'),
         url('myfont-webfont.woff') format('woff'),
         url('myfont-webfont.ttf')  format('truetype'),
         url('myfont-webfont.svg#svgFontName') format('svg');
}


Target IE set (針對IE的設置)
程序代碼 程序代碼
body {
color: red; /* all browsers, of course */
color : green\9; /* IE8 and below */
*color : yellow; /* IE7 and below */
_color : orange; /* IE6 */
}


Cross-Browser Min Height (跨瀏覽器的最小高度)
程序代碼 程序代碼
#div {
   min-height: 500px;
   height:auto !important;
   height: 500px;
}


Font Shorthand (字體設置速寫)
程序代碼 程序代碼
/*font: font-style font-variant font-weight font-size/line-height font-family;*/
font: italic small-caps bold 15px/30px Helvetica, sans-serif;


IE6/7 Double Margin/Padding Bug (IE6/7雙重邊距錯誤)
程序代碼 程序代碼
ul li {
  float: left;
  margin-left: 5px;
  *display: inline; /*IE7 and below*/
  _display: inline; /*IE6 and below*/
}
/* this example fixes double left margin bug 左邊距Bug*/


Web Fonts With Google Font API(Google網頁字體)
程序代碼 程序代碼
/* */


要使用谷歌API的字體,首先引用樣式表在之間
程序代碼 程序代碼
/*CSS selector {
  font-family: 'Font Name', serif;
}*/
font-family: 'Tangerine', serif;


Drop Cap (首字下沉)
程序代碼 程序代碼
p:first-letter {
    display:block;
    margin:5px 0 0 5px;
    float:left;
    color:#FF3366;
    font-size:60px;
    font-family:Georgia;
}
 
文章來自:: WOW

文章提供:: BAYSTARS DESIGN網頁設計公司

2011年11月22日 星期二

IE10增強對HTML5和CSS3的支持

Windows 8 終於發佈了,雖然現在可用的只是開發者預覽版,好消息是,IE 10 也隨著發了,雖然現在還只有Windows 8可用。我們來看下IE10都有哪些新特性吧。

IE開發者中心給到了一份詳細的針對前端開發者的文檔,列出了IE10支持的HTML5和CSS3新特性。嗯,它終於跟上了:

CSS3


  • css region
  • css3多列
  • Flexbox
  • grid
  • 定位浮動(positioned float)
  • 3D變換(3D transfrom)
  • 動畫(animation)
  • 漸變(gradient)
  • text-shadow
  • 去掉樣式表限制——在IE9之前的版本中,每個頁面最多只能加載31個樣式表文件,@import也只能最多嵌套4層,IE10中去掉了這些限制。


HTML5

  • 腳本同步——script標籤的async屬性,用來定義腳本是否異步執行
  • File API
  • History
  • Parsing
  • 表單驗證(form validation)
  • progress和range控制——其實也可以看作HTML5表單中的功能
  • web workers
  • web sockets
  • 拖拽(drag and drop)
  • 應用緩存——application cache,也就是離線存儲,不過需要注意的是W3C更新了離線存儲配置文件的擴展名,之前是ooxx.manifest,以後要用appcache擴展。
  • spellcheck
  • 頻道通信(channel messaging)


其它

  • Indexed Database
  • Web performance API
  • SVG 濾鏡效果


嗯,新東西很多,看起來還是很給力的。

需要注意的是,IE10對CSS3新特性的支持,大部分還是需要-ms-前綴的。

文章來自:: WOW

文章提供:: BAYSTARS DESIGN網頁設計公司

2011年11月21日 星期一

一些上流的CSS3圖片樣式

直接在圖片元素上直接應用CSS3 inset box-shadow border-radius時,流覽器並不能完美的渲染它們。不過,如果把這個圖片用作背景圖,你就可以可以給它添加任何樣式了,流覽器也會很好地渲染。Darcy Clarke和我做了一個簡單的教程,講解如何使用jQuery來動態地製作完美的圓角圖片。今天我將重溫這個主題然後向你展示使用background-image的方法可以實現多少效果。我將向你展示如何使用box-shadowborder-radius transition 來創作不同的圖片風格。
先看下demo

問題 ( demo)

看一下demo,請注意在第一行的圖片中使用了border-radiusinset box-shadowFirefox會直接在圖片元素上渲染border-radius,但不會渲染inset box-shadowchrome/safari則兩者都不渲染。

解決方案

要讓 border-radius inset box-shadow 正常工作,解決方案就是將實際圖片變作background-image.

動態方法

要想動態實現,可以簡單的使用jQuery為每個圖片元素外麵包一個背景圖片。下面的jQuery代碼會將所有圖片外麵包一個span標籤然後將圖片用作其背景圖片(jQuery代碼由Darcy Clarke編寫)
1
2
3
4
5
6
7
8
9
10
11
12
13
<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>

輸出

上面的腳本將會輸出下面的HTML代碼:
1
2
3
<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>

圓形圖片( demo)

現在,圖片被用作背景圖了,你可以給它添加任意你想要的樣式上去。下面是一個簡單的使用border-radius實現的圓形圖片。如果你對CSS3不太瞭解,可以閱讀下Basics of CSS3,也可以搜索一下前端觀察

CSS

1
2
3
4
5
.circle .image-wrap {
      -webkit-border-radius: 50em;
      -moz-border-radius: 50em;
      border-radius: 50em;
}

卡片風格( demo)

下面是一個像卡片的圖片風格,用了多個inset box-shadow

CSS

1
2
3
4
5
6
7
8
9
.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;
}

浮雕風格 ( demo)

通過一點兒改變,我可以將卡片風格轉換為浮雕。。。

CSS

1
2
3
4
5
6
7
8
9
.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;
}

軟浮雕風格 ( demo)

和浮雕風格真的很像,我只是加了1px的虛化~~

CSS

1
2
3
4
5
6
7
8
9
.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;
}

剪貼畫風格( demo)

同樣只是inset box-shadow,我可以讓它看起來像剪貼畫。

CSS

1
2
3
4
5
6
7
8
9
.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;
}

變形和發光 ( demo)

這個例子中,我為圖片外容器增加了變形。mouseover的時候,它將從圓角形狀變為圓形,然後增加了發光效果。發光效果通過多重box-shadow實現。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
.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;
}

發光遮罩 ( demo)

發光漸變遮罩是通過:after偽元素實現的。。。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
.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%);
}

倒影 ( demo)

這個例子中,我將遮罩漸變移動到底部,於是它就成了倒影。。。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.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;
}

光澤和倒影( demo)

這個例子中,我同時使用了:before:after偽元素來實現帶倒影的光澤效果。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
.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%);
}

膠帶風格( demo)

這裡使用了:after偽元素來在圖片頂部實現了膠帶風格的漸變。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.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);
}

變形和著色 ( demo)

在下面的這個例子中,我用了 :after元素來在mouseover的時候添加發光漸變。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
.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);
}

羽化邊緣的圓形(demo)

發散漸變也可以用作遮罩層來實現圓形羽化效果。

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
.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-radiusbox-shadow:before:after偽元素的流覽器上,比如 Chrome/Safari/Firefox等,而在一些落後的瀏覽器比如IE9(包括IE9)則不能完全支持——IE6/7/8沒有任何表現,IE9會 有普通的圓角。
文章來自:: 前端觀察
文章提供:: BAYSTARS DESIGN網頁設計公司