HTML文件必须加上 DOCTYPE 声明,并统一使用 HTML5 的文档声明:javascript
<!DOCTYPE html>
页面语言LANG,考虑浏览器和操做系统的兼容性,目前仍然使用 zh-CN 属性值css
<html lang="zh-CN">
CHARSET,HTML-5 中默认的字符编码是 UTF-8,请尽可能统一写成标准的 “UTF-8”html
<meta charset="UTF-8">
类型属性java
//不须要为 CSS、JS 指定类型属性,HTML5 中默认已包含 //推荐 <link rel="stylesheet" href="" > <script src=""></script> //不推荐 <link rel="stylesheet" type="text/css" href="" > <script type="text/javascript" src="" ></script>
元素属性web
//元素属性值使用双引号语法 //元素属性值能够写上的都写上 <input type="text"> <input type="radio" name="name" checked="checked" >
特殊字符引用chrome
//在 HTML 中不能使用小于号 “<” 和大于号 “>”特殊字符,浏览器会将它们做为标签解析,使用字符实体 //推荐 <a href="#">more >></a>
纯数字输入框,使用 type="tel"而不是type="number"canvas
<input type="tel">
HTML5标准模版浏览器
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>HTML5标准模版</title> </head> <body> </body> </html>
移动端app
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no" > <meta name="format-detection" content="telephone=no" > <title>移动端HTML模版</title> <link rel="stylesheet" href="css/index.css" > </head> <body> </body> </html>
PC端webapp
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="keywords" content="your keywords"> <meta name="description" content="your description"> <meta name="author" content="author,email address"> <meta name="robots" content="index,follow"> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <meta name="renderer" content="ie-stand"> <title>PC端HTML模版</title> <!-- S 本地调试,根据开发模式选择调试方式,请开发删除 --> <link rel="stylesheet" href="css/index.css" > </head> <body> </body> </html>
Viewport Meta Tag
<!-- width – viewport的宽度 height – viewport的高度 initial-scale – 初始的缩放比例 minimum-scale – 容许用户缩放到的最小比例 maximum-scale – 容许用户缩放到的最大比例 user-scalable – 是否容许用户缩放 默认值是 yes,★设置 no 还能够在文本框输入文本的时候阻止页面滚动★ --> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
apple-mobile-web-app-capable 设置 WebApp 是否进入全屏模式,该设置须要添加到主屏幕才生效
<!-- content设置 yes 进入全屏模式 默认会启动 Safari 应用,使用 Safari 应用浏览 经过检测 window.navigator.standalone 的 Boolean 值能够判断 web 应用是否处于全屏模式 --> <meta name="apple-mobile-web-app-capable" content="yes">
apple-mobile-web-app-status-bar-style 为 webapp 设置状态栏样式
<!-- 此 meta 设置只在全屏模式生效 默认值是 default content=”black”,状态栏背景黑色,网页内容在状态栏下面 content=”black-translucent”,状态栏半透明,背景黑色,网页内容占满全屏 --> <meta name="apple-mobile-web-app-status-bar-style" content="black">
format-detection 自动识别页面中有多是电话格式的数字
<!-- iOS中的 Safari 会默认识别与电话格式类似的数字并生成一个能够拉起电话应用并将该数字做为电话号码拨打的连接。定义 telephone=no 能够屏蔽该功能 --> <meta name="format-detection" content="telephone=no">
<img src="" alt="" > <!-- 注意事项: 1.图片引入不需添加 width、height 属性,alt 属性应该写上 2.demo { background-image: url(icon.png); //图片引入不须要引号 } 3.CSS Sprites 使用建议 - 适合使用频率高更新频率低的小图标 - 尽可能不留太多的空白 - 体积较大的图片不合并 - 确保要合并的小图坐标数值和合并后的 Sprites 图尺寸均为偶数 -->
css 设置
样式文件必须写上 @charset 规则,而且必定要在样式文件的第一行首个字符位置开始写,编码名用 “UTF-8”
样式文件编码声明 @charset 语句下面注明页面名称、做者、建立日期等信息
字符 @charset “”; 都用小写字母,不能出现转义符,编码名容许大小混写
考虑到在使用“UTF-8”编码状况下 BOM 对代码的污染和编码显示的问题,在可控范围下,坚定不使用 BOM。
@charset "UTF-8"; /** * @desc File Info * @author Author Name * @date 2017-7-10 */ .demo{}
css 代码风格
//统一使用展开格式书写样式,避免紧凑格式 //不使用 ID 选择器 //左括号与类名之间一个空格,冒号与属性值之间一个空格 //取值不要带有没必要要的 0 .demo { display: block; width: 50px; color: rgba(255,255,255,.5); }
css 属性书写顺序
布局定位属性:display / position / float / clear / visibility / overflow
自身属性:width / height / margin / padding / border / background
文本属性:color / font / text-decoration / text-align / vertical-align /
white- space / break-word
其余属性(CSS3):content / cursor / border-radius / box-shadow /
text-shadow / background:linear-gradient …
//示例 .demo { display: block; position: relative; float: left; width: 100px; height: 100px; margin: 0 10px; padding: 20px 0; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; color: #333; background: rgba(0,0,0,.5); -webkit-border-radius: 10px; -moz-border-radius: 10px; -o-border-radius: 10px; -ms-border-radius: 10px; border-radius: 10px; }
CSS3 浏览器私有前缀写法
.demo { -webkit-border-radius: 10px; -moz-border-radius: 10px; -o-border-radius: 10px; -ms-border-radius: 10px; border-radius: 10px; }
移动端
* { -webkit-tap-highlight-color: transparent; outline: 0; margin: 0; padding: 0; vertical-align: baseline; } body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td { margin: 0; padding: 0; vertical-align: baseline; } img { border: 0 none; vertical-align: top; } i, em { font-style: normal; } ol, ul { list-style: none; } input, select, button, h1, h2, h3, h4, h5, h6 { font-size: 100%; font-family: inherit; } table { border-collapse: collapse; border-spacing: 0; } a { text-decoration: none; color: #666; } body { margin: 0 auto; min-width: 320px; max-width: 640px; height: 100%; font-size: 14px; fon-family: -apple-system,Helvetica,sans-serif; line-height: 1.5; color: #666; -webkit-text-size-adjust: 100% !important; text-size-adjust: 100% !important; } input[type="text"], textarea { -webkit-appearance: none; -moz-appearance: none; appearance: none; }
PC端
html, body, div, h1, h2, h3, h4, h5, h6, p, dl, dt, dd, ol, ul, li, fieldset, form, label, input, legend, table, caption, tbody, tfoot, thead, tr, th, td, textarea, article, aside, audio, canvas, figure, footer, header, mark, menu, nav, section, time, video { margin: 0; padding: 0; } h1, h2, h3, h4, h5, h6 { font-size: 100%; font-weight: normal } article, aside, dialog, figure, footer, header, hgroup, nav, section, blockquote { display: block; } ul, ol { list-style: none; } img { border: 0 none; vertical-align: top; } blockquote, q { quotes: none; } blockquote:before, blockquote:after, q:before, q:after { content: none; } table { border-collapse: collapse; border-spacing: 0; } strong, em, i { font-style: normal; font-weight: normal; } ins { text-decoration: underline; } del { text-decoration: line-through; } mark { background: none; } input::-ms-clear { display: none !important; } body { font: 12px/1.5 \5FAE\8F6F\96C5\9ED1, \5B8B\4F53, "Microsoft Yahei","微软雅黑",Arial,sans-self; background: #fff; } a { text-decoration: none; color: #333; } a:hover { text-decoration: underline; }
经常使用查询语句
body { background-color: pink; } @media screen and (max-width: 960px) { body { background-color: darkgoldenrod; } } @media screen and (max-width: 480px) { body { background-color: lightgreen; } } /* 横屏 */ @media all and (orientation :landscape) { } /* 竖屏 */ @media all and (orientation :portrait) { } /* 设备宽度大于 320px 小于 640px */ @media all and (min-width:320px) and (max-width:640px) { } /* 设备像素比为 2 */ @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) { }
-webkit-scrollbar 用于对拥有overflow属性的区域 自定义滚动条的样式
//隐藏滚动条 .scroll::-webkit-scrollbar { width: 0; height: 0; }
-webkit-touch-callout
- none:系统默认菜单被禁用 - inherit:系统默认菜单不被禁用 当你触摸并按住触摸目标时候,禁止或显示系统默认菜单。 在iOS上,当你触摸并按住触摸的目标,好比一个连接,Safari浏览器将显示连接有关的系统默认菜单, 这个属性可让你禁用系统默认菜单。
-webkit-user-select 定义用户是否能选中元素内容
确保文件命名老是以字母开头而不是数字,且字母一概小写,以下划线链接且不带其余标点符号
<!-- HTML --> demo.html demo_list.html demo_detail.html <!-- CSS --> demo.css demo_list.css demo_detail.css
ClassName的命名应该尽可能精短、明确,必须以字母开头命名,且所有字母为小写,单词之间统一使用下划线 “_” 链接
ClassName 含义 about 关于 account 帐户 arrow 箭头图标 article 文章 aside 边栏 audio 音频 avatar 头像 bg,background 背景 bar 栏(工具类) branding 品牌化 crumb,breadcrumbs 面包屑 btn,button 按钮 caption 标题,说明 category 分类 chart 图表 clearfix 清除浮动 close 关闭 col,column 列 comment 评论 community 社区 container 容器 content 内容 copyright 版权 current 当前态,选中态 default 默认 description 描述 details 细节 disabled 不可用 entry 文章,博文 error 错误 even 偶数,经常使用于多行列表或表格中 fail 失败(提示) feature 专题 fewer 收起 field 用于表单的输入区域 figure 图 filter 筛选 first 第一个,经常使用于列表中 footer 页脚 forum 论坛 gallery 画廊 group 模块,清除浮动 header 页头 help 帮助 hide 隐藏 hightlight 高亮 home 主页 icon 图标 info,information 信息 last 最后一个,经常使用于列表中 links 连接 login 登陆 logout 退出 logo 标志 main 主体 menu 菜单 meta 做者、更新时间等信息栏,通常位于标题之下 module 模块 more 更多(展开) msg,message 消息 nav,navigation 导航 next 下一页 nub 小块 odd 奇数,经常使用于多行列表或表格中 off 鼠标离开 on 鼠标移过 output 输出 pagination 分页 pop,popup 弹窗 preview 预览 previous 上一页 primary 主要 progress 进度条 promotion 促销 rcommd,recommendations 推荐 reg,register 注册 save 保存 search 搜索 secondary 次要 section 区块 selected 已选 share 分享 show 显示 sidebar 边栏,侧栏 slide 幻灯片,图片切换 sort 排序 sub 次级的,子级的 submit 提交 subscribe 订阅 subtitle 副标题 success 成功(提示) summary 摘要 tab 标签页 table 表格 txt,text 文本 thumbnail 缩略图 time 时间 tips 提示 title 标题 video 视频 wrap 容器,包,通常用于最外层 wrapper 容器,包,通常用于最外层
ad、banner、gg、guanggao 等有机会和广告挂勾的字眠不建议直接用来作ClassName,由于有些浏览器插件(Chrome的广告拦截插件等)会直接过滤这些类名