想為圖片或區塊做出圓角,除了 border-radius,早期還流行用背景圖偏移定位的方式來拼出四個圓角。本文示範這套做法的關鍵程式碼。
透過改變背景圖的定位,讓每個小區塊只露出對應的圓角部分:
/* 圖片偏移定位——上面部分 */
.sharp b.b2{ background-position:-4px top; }
.sharp b.b3{ background-position:-2px -1px; }
.sharp b.b4{ background-position:-1px -2px; }
下面部分與上面互相對應:
/* 圖片偏移定位——下面部分 */
.sharp b.b7{ background-position:-4px bottom; }
.sharp b.b6{ background-position:-2px bottom; }
.sharp b.b5{ background-position:-1px bottom; }
換色時只要改動邊框色與背景圖路徑即可,三行就能搞定一種配色:
/* 邊框色 */
.color1 .b2,.color1 .b3,.color1 .b4,.color1 .b5,.color1 .b6,
.color1 .b7,.color1 .content{ border-color:#262626; }
.color1 .b1,.color1 .b8{ background:#262626; }
/* 圖片路徑 */
.color1 .b2,.color1 .b3,.color1 .b4,.color1 h3,.color1 .b5,.color1 .b6,.color1 .b7,.color1 .content{ background:url(image/1.jpg) no-repeat; }