国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

CSS 日期垂直排列的兩種技巧

2024-07-11 08:45:16
字體:
來源:轉載
供稿:網友

LearningjQuery.com 博客帖子列表的左邊有一個很酷的日期,如圖:

從圖中我們看到,“2009”垂直排列在右側。用Firebug查看元素,文本“2009”出現在html結構之中,本文介紹實現這種效果的兩種方法。

一、利用Sprite技術來實現

其實現過程已有Chris Coyier 在《Date Display Technique with Sprites》一文中作了詳細介紹,這里把其實現過程作一個簡單的描述。很顯然,我們不希望每一個日期用一張單獨的圖片,因此,將其整合到一張圖片之上,安排年、月、日在圖片的不同區域,如圖:

1、Html

頁面中html結構如下:

<div class="postdate">
        <div class="month m-06">Jun</div>
        <div class="day d-30">30</div>
        <div class="year y-2009">2009</div>
</div>

.postdate容器包含三個區域,分別對應年月日,這樣很好的保證了語義上的完整性。

在類似wordpress這樣的CMS系統中,其后端代碼是這樣的:

<div class="postdate">
        <div class="month m-<?php the_time('m') ?>"><?php the_time('M') ?></div>
        <div class="day d-<?php the_time('d') ?>"><?php the_time('d') ?></div>
        <div class="year y-<?php the_time('Y') ?>"><?php the_time('Y') ?></div>
</div>

2、Css

css是sprite真正發揮作用的地方,利用html中的定義的class屬性,讓對應的圖片得以顯示。

首先,讓class屬性為.postdate的容器相對定位,這樣包含其中的三個區域就會絕對定位,并使用同一張背景圖片。設置各自的寬度和高度,并將文字移出以顯示背景圖片。

然后,定義每個月(12)、每天(31)、每年(按10年計)具體的背景位置,以顯示與其相對應的圖片。

.postdate {
  position: relative;
  width: 50px;
  height: 50px;
  float: left;
}
.month, .day, .year {
  position: absolute;
  text-indent: -1000em;
  background-image: url(/wp-content/themes/ljq/images/dates.png);
  background-repeat: no-repeat;
}
.month { top: 2px; left: 0; width: 32px; height: 24px;}
.day { top: 25px; left: 0; width: 32px; height: 25px;}
.year { bottom: 0; right: 0; width: 17px; height: 48px;}
 
.m-01 { background-position: 0 4px;}
.m-02 { background-position: 0 -28px;}
.m-03 { background-position: 0 -57px;}
... more like this ...
 
.d-01 { background-position: -50px 0;}
.d-02 { background-position: -50px -31px;}
.d-03 { background-position: -50px -62px;}
... more like this ...
 
.y-2006 { background-position: -150px 0;}
.y-2007 { background-position: -150px -50px;}
.y-2008 { background-position: -150px -100px;}
... more like this ...


上一頁12 下一頁 閱讀全文
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 翁牛特旗| 曲靖市| 余干县| 涿州市| 聂拉木县| 广宁县| 娱乐| 汉沽区| 阿克| 博客| 马山县| 志丹县| 托克逊县| 黄大仙区| 大荔县| 库伦旗| 遵义市| 隆安县| 金乡县| 伽师县| 固原市| 汽车| 突泉县| 宁津县| 化德县| 望江县| 镇远县| 余江县| 贞丰县| 渝北区| 兴文县| 泸州市| 綦江县| 伊宁市| 彭山县| 黔西县| 高阳县| 阜新市| 阿巴嘎旗| 乡宁县| 双辽市|