zoukankan      html  css  js  c++  java
  • 多用组合,少用继承

    要做出上图的效果,有多种方法,但我们要用的方法是多用组合少用继承。多用组合少用继承:把相对稳定的部分拆成一个类,把不稳定的部分分拆成几个类。观察上图可知稳定部分是边框样式,区块间隙和行距,不稳定的部分就是字体大小和颜色。现在可以根据规律得出如下代码:

    .f18{font-size:18px;}
    .f20{font-size:20px;}
    .f22{font-size:22px;}
    .red{color:#F00;}
    .common-list{border:solid 1px #CCC;padding:10px;margin-top:20px;400px;}
    .common-list li{height:20px;line-height:20px;list-style:none;}

    完整的代码块如下:

    <html>
    <head>
    <style type="text/css">
    .f18{font-size:18px;}
    .f20{font-size:20px;}    <!--这是不稳定部分-->
    .f22{font-size:22px;}
    .red{color:#F00;}
    .common-list{border:solid 1px #CCC;padding:10px;margin-top:20px;width:400px;}   <!--这是三者都具有的稳定的部分-->
    .common-list li{height:20px;line-height:20px;list-style:none;}                  <!--这是三者都具有的稳定的部分-->
    </style>
    </head>
    
    <body>
    <ul class="common-list f18">
        <li>1111111111111111111111111111</li>
        <li>1111111111111111111111111111</li>
        <li>1111111111111111111111111111</li>
    </ul>
    
    <ul class="common-list f20">
        <li>1111111111111111111111111111</li>
        <li>1111111111111111111111111111</li>
        <li>1111111111111111111111111111</li>
    </ul>
    
    <ul class="common-list f22 red">
        <li>1111111111111111111111111111</li>
        <li>1111111111111111111111111111</li>
        <li>1111111111111111111111111111</li>
    </ul>
    </body>
    </html>
  • 相关阅读:
    svn使用
    navicat 15 安装破解
    thinkpad交换Fn和Ctrl
    emqx_mqtt安装+mqtt管理工具
    Adobe XD使用
    FolderPainter:windows系统为文件夹设置不同颜色
    rest client 代替postman
    使用bfg快速清理git历史大文件
    Adobe Acrobat XI Pro v11.0.10中文版
    Excel 2016打开文档时提示“操作系统当前的配置不能运行此应用程序”
  • 原文地址:https://www.cnblogs.com/52css/p/2540436.html
Copyright © 2011-2022 走看看