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

首頁 > 開發 > CSS > 正文

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

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

武林網(www.survivalescaperooms.com)文章簡介:CSS實例:日期垂直排列的兩種技巧.

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

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

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

一、利用Sprite技術來實現

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

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

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 ...

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韶关市| 北京市| 准格尔旗| 竹溪县| 东台市| 泸水县| 蓬溪县| 扶沟县| 易门县| 台安县| 紫金县| 华坪县| 榆林市| 金塔县| 板桥市| 吉木乃县| 太保市| 兴和县| 如皋市| 德钦县| 宁乡县| 铁岭县| 绵竹市| 陈巴尔虎旗| 安康市| 大名县| 永清县| 莲花县| 兴文县| 那曲县| 江安县| 白朗县| 紫云| 合作市| 青川县| 铜陵市| 东兴市| 社会| 万州区| 乡城县| 琼中|