日期垂直排列的两种技巧

作者:dishuipiaoxiang 来源:Denis'Blog 时间:2009-08-28 12:38:00 

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

标签:css,日期,垂直,技巧
0
投稿

猜你喜欢

  • Asp中如何设计跨越域的Cookie

    2008-10-24 09:46:00
  • python单测框架之pytest常见用法

    2021-05-22 04:13:02
  • 使用pandas实现筛选出指定列值所对应的行

    2023-05-06 18:29:53
  • node实现mock-plugin中间件的方法

    2024-05-13 10:05:59
  • flask中使用SQLAlchemy进行辅助开发的代码

    2021-09-10 07:46:43
  • numpy.float32的典型用法

    2022-04-30 04:36:30
  • ASP实现表单中容量大的数据的提交方法

    2008-10-16 11:07:00
  • 解决Python2.7中IDLE启动没有反应的问题

    2022-10-17 17:43:57
  • Python数据结构与算法中的栈详解

    2023-09-28 17:16:14
  • mysql 判断是否为子集的方法步骤

    2024-01-26 03:53:11
  • Vue父子组件通信全面详细介绍

    2024-06-05 09:21:16
  • vue修改滚动条样式的方法

    2024-04-27 15:48:59
  • 一条select语句引起的瓶颈问题思考

    2024-01-18 02:40:32
  • selenium python浏览器多窗口处理代码示例

    2023-11-20 07:09:29
  • 浅析PyCharm 的初始设置(知道)

    2022-12-04 05:41:26
  • Python中最常用的操作列表的几种方法归纳

    2021-01-11 22:06:05
  • 浅谈Python中的字符串

    2022-10-05 00:39:22
  • 对Python _取log的几种方式小结

    2021-12-19 02:18:48
  • javascript 通过键名获取键盘的keyCode方法

    2024-04-22 22:18:21
  • asp日期函数运用--生成简单的日历

    2008-08-15 13:47:00
  • asp之家 网络编程 m.aspxhome.com