ホームページ  >  記事  >  ウェブフロントエンド  >  css3を使って記事ニュース一覧ランキング(件数)を実装_html/css_WEB-ITnose

css3を使って記事ニュース一覧ランキング(件数)を実装_html/css_WEB-ITnose

WBOY
WBOYオリジナル
2016-06-24 11:15:291674ブラウズ

記事ランキングのための簡単な数値効果をいくつかリストします

1: リストスタイルを使用して数字、ドット、文字、または画像を表示します

<style>    li{width:300px; border-bottom: 1px dotted #ccc; line-height: 30px; height: 30px; overflow:hidden }    li{list-style: decimal inside; }</style><ul>    <li>文章1</li>    <li>文章2</li></ul>

2: 疑似要素を使用します: 前

このメソッドを使用します。親タグに counter-reset:section を設定する;

<style>    ul{counter-reset:section;}    li{width:300px; border-bottom: 1px dotted #ccc; line-height: 30px; height: 30px; overflow:hidden }    li:before{counter-increment:section;content:counter(section);display:inline-block;padding:0 6px;margin-right:10px;height:18px;line-height:18px;background:#717070;color:#fff;border-radius:3px;font-size:9px}    li:nth-child(1):before{background:#ff6a00}    li:nth-child(2):before{background:#107db4}    li:nth-child(3):before{background:#56ae11}</style><ul>    <li>文章1</li>    <li>文章2</li>    <li>文章3</li>    <li>文章4</li></ul>

3: js を使用して実装し、最初に jquery を導入する

<style>    ul{counter-reset:section;}    li{width:300px; border-bottom: 1px dotted #ccc; line-height: 30px; height: 30px; overflow:hidden }    li i{display:inline-block;font-style:initial;padding:0 6px;margin-right:10px;height:18px;line-height:18px;background:#717070;color:#fff;border-radius:3px;font-size:9px}    .red1{background:#ff6a00}    .red2{background:#107db4}    .red3{background:#56ae11}</style><ul>    <li>文章1</li>    <li>文章2</li>    <li>文章3</li>    <li>文章4</li></ul><script>    listsort()    //显示排行    function listsort() {        var index = 0;        $("li").each(function () {            index++;            var num = $("<i>" + index + "</i>");            if (index <= 3)                num.addClass("red" +index);            $(this).prepend(num);        });    }</script>

コード サイズや特殊効果の観点から 3 つの方法を比較すると、2 番目の方法が推奨されます。メンテナンスする方が便利です

アドレス: http://cssteach.com/html/show-12-88.html

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。