dmz社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 365|回复: 0

[其他] 漂亮的无序列表样式

[复制链接]
  • TA的每日心情

    2024-2-20 11:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    878

    主题

    4343

    帖子

    3987

    积分

    终身会员[A]

    Rank: 7Rank: 7Rank: 7

    积分
    3987

    发表于 2020-4-5 07:00:05 | 显示全部楼层 |阅读模式

    本站资源全部免费,回复即可查看下载地址!

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    阅读导航:
    • 一、先看效果
    • 二、本文背景
    • 三、代码实现
    • 四、文章参考
    • 五、代码下载
    一、先看效果 0list.gif

    二、本文背景
    最近在学B/S,前端使用Angular,今天学到Angular中文官网的一个例子,其中的无序列表样式设置出来挺好看的,所以在这记录一下。
    三、代码实现
    只记录其中关键的代码。
    模拟数据 mock-heroes.ts

    [AppleScript] 纯文本查看 复制代码
    import { Hero } from "./hero";
    
    export const HEROES: Hero[] = [
      { id: 11, name: 'Dr Nice' },
      { id: 12, name: 'Narco' },
      { id: 13, name: 'Bombasto' },
      { id: 14, name: 'Celeritas' },
      { id: 15, name: 'Magneta' },
      { id: 16, name: 'RubberMan' },
      { id: 17, name: 'Dynama' },
      { id: 18, name: 'Dr IQ' },
      { id: 19, name: 'Magma' },
      { id: 20, name: 'Tornado' }
    ];

    Angular模板,展示列表的html文件:heroes.component.html

    <h2>My Heroes</h2>
    <ul class="heroes">
        <li *ngFor="let hero of heroes"
        [class.selected]="hero === selectedHero"
        (click)="onSelect(hero)">
            <span class="badge">{{hero.id}}</span>{{hero.name}}
        </li>
    </ul>

    <div *ngIf="selectedHero">
       
        <h2>{{selectedHero.name | uppercase}} Details</h2>
        <div><span>id: </span>{{selectedHero.id}}</div>
        <div>
            <label>name:
                <input [(ngModel)]="selectedHero.name" placeholder="name"/>
            </label>
        </div>
    </div>

    最主要的是这个样式文件,以后可以作为参考:heroes.component.css

    [AppleScript] 纯文本查看 复制代码
    .selected {
        background-color: #CFD8DC !important;
        color: white;
    }
    .heroes {
        margin: 0 0 2em 0;
        list-style-type: none;
        padding: 0;
        width: 15em;
    }
    .heroes li {
        cursor: pointer;
        position: relative;
        left: 0;
        background-color: #EEE;
        margin: .5em;
        padding: .3em 0;
        height: 1.6em;
        border-radius: 4px;
    }
    .heroes li.selected:hover {
        background-color: #BBD8DC !important;
        color: white;
    }
    .heroes li:hover {
        color: #607D8B;
        background-color: #DDD;
        left: .1em;
    }
    .heroes .text {
        position: relative;
        top: -3px;
    }
    .heroes .badge {
        display: inline-block;
        font-size: small;
        color: white;
        padding: 0.8em 0.7em 0 0.7em;
        background-color: #405061;
        line-height: 1em;
        position: relative;
        left: -1px;
        top: -4px;
        height: 1.8em;
        margin-right: .8em;
        border-radius: 4px 0 0 4px;
    }

    四、文章参考
    五、代码下载
    文章中贴出了部分代码,上面参考的网址有全部代码,跟着教程一步一步走就可以实现。





    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|小黑屋|本站代理|dmz社区

    GMT+8, 2024-4-25 20:32 , Processed in 0.121885 second(s), 36 queries .

    Powered by Discuz! X3.4 Licensed

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表