分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

CSS书写顺序提高可读性

发布时间:2023-09-06 01:52责任编辑:彭小芳关键词:CSS

属性书写顺序

[建议] 同一 rule set 下的属性在书写时,应按功能进行分组,并以 Formatting Model(布局方式、位置) > Box Model(尺寸) > Typographic(文本相关) > Visual(视觉效果) 的顺序书写,以提高代码的可读性。

解释:

  • Formatting Model 相关属性包括:position / top / right / bottom / left / float / display / overflow 等
  • Box Model 相关属性包括:border / margin / padding / width / height 等
  • Typographic 相关属性包括:font / line-height / text-align / word-wrap 等
  • Visual 相关属性包括:background / color / transition / list-style 等

另外,如果包含 content 属性,应放在最前面。

示例:

.sidebar { ???/* formatting model: positioning schemes / offsets / z-indexes / display / ... ?*/ ???position: absolute; ???top: 50px; ???left: 0; ???overflow-x: hidden; ???/* box model: sizes / margins / paddings / borders / ... ?*/ ???width: 200px; ???padding: 5px; ???border: 1px solid #ddd; ???/* typographic: font / aligns / text styles / ... */ ???font-size: 14px; ???line-height: 20px; ???/* visual: colors / shadows / gradients / ... */ ???background: #f5f5f5; ???color: #333; ???-webkit-transition: color 1s; ??????-moz-transition: color 1s; ???????????transition: color 1s;}

CSS书写顺序提高可读性

原文地址:https://www.cnblogs.com/qjuly/p/8985215.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved