濮阳杆衣贸易有限公司

主頁 > 知識庫 > CSS 使用Sprites技術實現(xiàn)圓角效果

CSS 使用Sprites技術實現(xiàn)圓角效果

熱門標簽:南通電銷外呼系統(tǒng)軟件 申請400電話移動 常州電話外呼系統(tǒng)招商 智能語音電銷機器人客戶端 廣州防封電銷機器人廠家 山東電銷機器人軟件 洛陽防封卡外呼系統(tǒng)廠家 成都企業(yè)外呼系統(tǒng) 上海400電話辦理到易號網

首先來簡單說一下什么是Sprites,Sprites是一種網頁圖片應用處理方式。它允許你將一個頁面涉及到的所有零星圖片都包含到一張大圖中去,這樣一來,當訪問該頁面時,載入的圖片就不會像以前那樣一幅一幅地慢慢顯示出來了。對于當前網絡流行的速度而言,不高于200KB的單張圖片的所需載入時間基本是差不多的,所以無需顧忌這個問題。

第一步:創(chuàng)建我們的 Sprite

用PS等工具合成如圖所示的圖片(以一個像素的紅線來區(qū)分)

第二步:編寫HTML代碼

首先,我們會給容器 div 一個 .roundedBox類 :

復制代碼 代碼如下:

div class="roundedBox">/div>

現(xiàn)在,我們必須再增加四個div ,這會在將來創(chuàng)建圓角的時候用到。之后必須給每個加載一個類 .corner,同時也標識一個類來指定它們格子的位置。

復制代碼 代碼如下:

div class="roundedBox">
    strong>My content in roundedBox Type 1/strong>
    div class="corner topLeft">/div>
    div class="corner topRight">/div>
    div class="corner bottomLeft">/div>
    div class="corner bottomRight">/div>
/div>

第三步:編寫CSS樣式

絕對定位元素通常都依照相對定位的父元素進行定位。如果這個父元素無法界定,那么它會去最近作相對定位的那個父元素,直至 body 標簽。

讓我們先來定義下所有的圓角

所有的圓角都必須定義絕對定位,并且注明高度跟寬度。 我的圓角定義的寬度跟高度都是 17px.

復制代碼 代碼如下:

.corner{position:absolute;width:17px;height:17px;}

現(xiàn)在開始定義 div 容器樣式:

復制代碼 代碼如下:

.roundedBox {position:relative;}

任何定義有類 .roundedBox 的元素內,絕對定位元素都會相對于這個元素進行定位,而不是標簽 body。 我們也必須設置一些padding值,如果沒有設置,圓角將會覆蓋我們的文本,這肯定不是我們想要的效果。 重要提示: top 和 bottom padding 值必須 等價于圓角的 height。left 和 right padding 值必須等價于圓角的寬度。 正如您已經知道的,我的圓角寬度跟高度是相等的,因此,四個邊角的padding 值也是相等的:

復制代碼 代碼如下:

.roundedBox {position:relative; padding:17px; margin:10px 0;}

讓我們對沒有圓角作單獨定義

我們會對每個圓角作絕對定位設置,并且定位背景圖的位置 (根據(jù)我們的 sprite):

復制代碼 代碼如下:

.roundedBox {position:relative; padding:17px; margin:10px 0;}
.corner {position:absolute; width:17px; height:17px;}
.topLeft {top:0; left:0; background-position:-1px -1px;}
.topRight {top:0; right:0; background-position:-19px -1px;}
.bottomLeft {bottom:0; left:0; background-position:-1px -19px;}
.bottomRight {bottom:0; right:0; background-position:-19px -19px;}

最后,給 #type1 匹配一個背景色,使之融合于 sprite 中的圓角:

復制代碼 代碼如下:

#type1 {background-color:#CCDEDE;}
#type1 .corner {background-image:url(../image/corners.gif);}

全部的代碼:

復制代碼 代碼如下:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w3.org/1999/xhtml">
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
title>無標題文檔/title>
style type="text/css">
.roundedBox {position:relative; padding:17px; margin:10px 0;}
.corner {position:absolute; width:17px; height:17px;}
.topLeft {top:0; left:0; background-position:-1px -1px;}
.topRight {top:0; right:0; background-position:-19px -1px;}
.bottomLeft {bottom:0; left:0; background-position:-1px -19px;}
.bottomRight {bottom:0; right:0; background-position:-19px -19px;}
#type1 {background-color:#CCDEDE;}
#type1 .corner {background-image:url(../image/corners.gif);}
/style>
/head>
body>
div class="roundedBox" id="type1">
    strong>My content in roundedBox Type 1/strong>
    div class="corner topLeft">/div>
    div class="corner topRight">/div>
    div class="corner bottomLeft">/div>
    div class="corner bottomRight">/div>
/div>
/body>
/html>

您可能感興趣的文章:
  • CSS圓角區(qū)塊容器生成器
  • CSS實現(xiàn)光滑圓角效果
  • 用js實現(xiàn)CSS圓角生成更新
  • 用js實現(xiàn)的抽象CSS圓角效果!!
  • 純CSS生成抗鋸齒圓角的代碼
  • css Sprites小實例代碼
  • 提取自百度有啊的css圓角效果
  • CSS+Jquery實現(xiàn)頁面圓角框方法大全
  • JS+CSS實現(xiàn)可拖拽的漂亮圓角特效彈出層完整實例
  • jQuery+html5+css3實現(xiàn)圓角無刷新表單帶輸入驗證功能代碼
  • js+css實現(xiàn)的圓角邊框TAB選項卡滑動門代碼分享(2款)
  • JS+CSS實現(xiàn)自適應選項卡寬度的圓角滑動門效果
  • JS+CSS實現(xiàn)的經典圓角下拉菜單效果代碼

標簽:萊蕪 滄州 鶴壁 貴州 混顯 邵陽 賀州 廣安

巨人網絡通訊聲明:本文標題《CSS 使用Sprites技術實現(xiàn)圓角效果》,本文關鍵詞  CSS,使用,Sprites,技術,實現(xiàn),;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《CSS 使用Sprites技術實現(xiàn)圓角效果》相關的同類信息!
  • 本頁收集關于CSS 使用Sprites技術實現(xiàn)圓角效果的相關信息資訊供網民參考!
  • 推薦文章
    雅江县| 木里| 新宾| 库伦旗| 翼城县| 连江县| 巨野县| 卢氏县| 衡山县| 松滋市| 东宁县| 昔阳县| 龙陵县| 桃园县| 集贤县| 明星| 大同市| 星子县| 筠连县| 鞍山市| 武山县| 石城县| 盐城市| 从化市| 江达县| 巴马| 宝丰县| 襄城县| 萨迦县| 萨嘎县| 宜州市| 麻栗坡县| 西宁市| 屏东市| 遵义市| 通化县| 屏边| 汶上县| 沁源县| 宿州市| 盐亭县|