模板设计:修饰列表

Blogbus的列表,如最新文章、最新评论、归档等都是分别用脚本生成的。但由于在生成这些列表时只是简单的使用链接加换行的方式而没有采用列表应有的<ul><li>标签,这些列表其实名不符实,同时也给我们对其控制和修饰带来了一定的困难。

在Blogbus对其脚本进行改进之前,我想到了一个暂时的解决方案,也基本是通过CSS上的设置,对列表添加自定义的Bullet(就是列表前的小图标,我不清楚中文叫什么)。具体做法如下:

  • 以我的Blog为例,我右边的最新文章、归档、Blogroll和链接的ID分别是r_post, archives, blogroll和links。“最新评论”情况特殊,我们要在后面单独处理。对以上四个列表的格式化其实很简单,只要在CSS中加上:

    #r_post a, #archives a, #blogroll a, #links a{
    display: block;
    padding-left: 15px;
    background: url(http://web.163.sh.cn/~ease/bullet_raquo.gif) 0 3px no-repeat;
    }
    #archives br, #r_post br, #blogroll br, #links br {display: none;}

    这样,使每一个链接display属性为block,并设置padding-left为一定值为添加小图标留出空间,然后通过背景方式加入小图标(图标的精确位置需要根据图片的具体情况修改,这里是距左0象素,距上3象素),最后要把<br>的显示属性设为none,否则的话……你可以自己试试看。

  • 对于“最近评论”,这么干是不行的,因为它在一行里有两个链接。于是我写了一个小脚本initCmtlist插入到网页中最近评论结束的地方。这个脚本的作用是把第一个链接(评论者)加上一个class叫“commenter”,内容如下:

    initCmtList = function() {
    if (document.getElementById) {
    listRoot = document.getElementById("r_comment");
    for (i=0; i<listRoot.childNodes.length; i++) {
    node = listRoot.childNodes[i];
    if (node.nodeName=="BR"){
    node = listRoot.childNodes[i-3];
    node.className+=" commenter"
    }
    }
    }
    }

    initCmtList();

    再在CSS中对.commenter做一个简单的定义,

    .commenter {padding-left: 15px;background: url(http://web.163.sh.cn/~ease/bullet_raquo.gif) 0 2px no-repeat;}

OK,搞定!

Technorati Tags: , , ,





8 条评论

  1. 2008-03-28 18:47:00
    hello everybody! <a href=" http://pussycat.free-site-host.com/fuck-video/fuck-my-sife.html ">fuck my sife
    </a> 8583 <a href=" http://pussycat.free-site-host.com/fuck-video/wifey-fuck.html ">wifey fuck
    </a> %-D
  2. 2008-03-28 07:39:48
    i say one thing <a href=" http://pussycat.free-site-host.com/fuck-video/carmen-bling-and-gianna-and-principal-and-fuck-and-trailer-and-video.html ">carmen bling and gianna and principal and fuck and trailer and video
    </a> sbyfdj <a href=" http://pussycat.free-site-host.com/fuck-video/fuck-you-right-back-lyrics.html ">fuck you right back lyrics
    </a> %-O
  3. 2008-03-28 05:51:51
    i say one thing <a href=" http://pussycat.free-site-host.com/fuck-video/very-old-fuck.html ">very old fuck
    </a> =))) <a href=" http://pussycat.free-site-host.com/fuck-video/cheating-wives-fuck-in-front.html ">cheating wives fuck in front
    </a> 749228
  4. 2008-03-28 05:51:17
    i say one thing <a href=" http://pussycat.free-site-host.com/fuck-video/very-old-fuck.html ">very old fuck
    </a> =))) <a href=" http://pussycat.free-site-host.com/fuck-video/cheating-wives-fuck-in-front.html ">cheating wives fuck in front
    </a> 749228
  5. 2008-03-27 23:43:25
    hay <a href=" http://pussycat.free-site-host.com/fuck-video/fuck-holes.html ">fuck holes
    </a> 56667 <a href=" http://pussycat.free-site-host.com/fuck-video/fuck-slut-ffmride-round-suck-tits-ass.html ">fuck slut ffmride round suck tits ass
    </a> owkuh
  6. 2008-03-25 05:50:54
    KiAVab great work thx http://peace.com
  7. 2008-03-21 23:33:21
    1v1waU http://get-adult.we.bs/map.html anal fuck
  8. 2008-03-21 23:32:46
    1v1waU http://get-adult.we.bs/map.html anal fuck

添加评论