CSS 综合

1.平时写代码遵守的编码规范

  1. tab 用两个空格表示
  2. css的 :后加个空格, {前加个空格
  3. 每条声明后都加上分号
  4. 换行,而不是放到一行
  5. 颜色用小写,用缩写, #fff
  6. 小数不用写前缀, 0.5s -> .5s;0不用加单位
  7. 尽量缩写, margin: 5px 10px 5px 10px -> margin: 5px 10px
    参考代码规范连接:http://codeguide.bootcss.com/
    https://google.github.io/styleguide/htmlcssguide.xml

2.垂直居中有几种实现方式,给出代码范例

  1. 绝对定位实现居中
<head>
    <title></title>
    <style type="text/css">
        .ct {
            width:400px;
            height: 300px;
            position: relative;
            margin: 0 auto;
            background-color: #eee;
        }

        .box {
            width: 100px;
            height: 100px;
            position: absolute;
            background-color: red;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
 <div class="ct">
    <div class="box"></div>
 </div>
</body>
  1. vertical-align实现居中
<head>
    <title></title>
    <style type="text/css">
        .ct {
            width:400px;
            height: 300px;
            margin: 0 auto;
            background-color: #eee;
            text-align: center;
        }
        
        .ct::before {
            content: '';
            display: inline-block;
            height: 100%;
            vertical-align: middle;
        }

        .box {
            display: inline-block;
            width: 100px;
            height: 100px;
            background-color: red;
            vertical-align: middle;
        }

    </style>
</head>
<body>
 <div class="ct">
    <div class="box"></div>
 </div>
</body>
  1. table-cell实现居中
<head>
    <title></title>
    <style type="text/css">
        .ct {
            width:400px;
            height: 300px;
            background-color: #eee;
            display: table-cell;
            vertical-align: middle;
            text-align: center;
        }

        .box {
            display: inline-block;
            width: 100px;
            height: 100px;
            background-color: red;
        }

    </style>
</head>
<body>
 <div class="ct">
    <div class="box"></div>
 </div>
</body>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.说一说你平时写代码遵守的编码规范 使用语义化标签使用有意义的命名方式使用小写命名,用中横线连接tab 用两个空...
    Sunset125阅读 164评论 0 0
  • 浅谈编码规范 命名技巧 语义化标签优先 基于功能命名、基于内容命名、基于表现命名 简略、明了(翻译成英文) 所有命...
    饥人谷_秦勤阅读 370评论 0 0
  • 1. 说一说你平时写代码遵守的编码规范 HTML书写规范 用两个空格来代替制表符(tab) -- 这是唯一能保证在...
    饥人谷_流水阅读 167评论 0 0
  • 说一说你平时写代码遵守的编码规范常见的编码规范语义化:1.语义化标签优先2.基于功能命名、基于内容命名、基于表现命...
    24_Magic阅读 240评论 0 0
  • 说一说你平时写代码遵守的编码规范 语义化 语义化标签优先基于功能命名、基于内容命名、基于表现命名简略、明了、无后患...
    荣_Rong阅读 250评论 0 0