CSS初始化

一、通用CSS初始化代码(基础重置)

通用初始化用于消除不同浏览器的默认样式差异,保证页面在多浏览器下的一致性:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box; /* 统一盒模型 */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  line-height: 1.6; /* 合理行高 */
  color: #333; /* 基础文本色 */
  background-color: #fff; /* 基础背景色 */
}

ul, ol {
  list-style: none; /* 清除列表默认样式 */
}

a {
  text-decoration: none; /* 清除链接下划线 */
  color: inherit; /* 继承父级文本色 */
}

img {
  max-width: 100%; /* 图片响应式 */
  height: auto; /* 保持宽高比 */
  vertical-align: middle; /* 解决图片底部间隙 */
}

input, button, textarea, select {
  font-family: inherit; /* 继承父级字体 */
  font-size: inherit; /* 继承父级字号 */
  outline: none; /* 清除默认焦点轮廓(可根据需求保留) */
}

二、各公司CSS初始化代码示例

以下为腾讯、阿里云、网易三家公司常用的定制化初始化代码(基于公开资料整理):

1. 腾讯(腾讯文档/QQ 体系)

腾讯系产品倾向于使用「PingFang SC」作为基础字体,强调交互的轻量感:

/* 腾讯通用CSS初始化 */
* { 
  margin: 0; 
  padding: 0; 
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0); /* 清除移动端点击高亮 */
}

html { 
  font-size: 62.5%; /* 1rem = 10px(适配移动端) */
}

body { 
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; 
  font-size: 1.4rem; /* 14px */
  line-height: 1.8; 
  color: #333; 
  background-color: #fff; 
}

ul, ol { list-style: none; }

a { 
  text-decoration: none; 
  color: #0066cc; /* 腾讯蓝 */
}

a:hover { text-decoration: underline; }

img { 
  border: 0; 
  vertical-align: middle; 
}

table { border-collapse: collapse; border-spacing: 0; }

2. 阿里云(阿里云官网/控制台)

阿里云强调「科技感」,使用定制字体「Alibaba Sans」,颜色以「阿里云蓝」为主:

/* 阿里云CSS初始化 */
html { 
  font-size: 10px; /* 基础字号 */
  -webkit-text-size-adjust: 100%; /* 禁止移动端字体缩放 */
}

body { 
  margin: 0; 
  font-family: "Alibaba Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; 
  font-size: 1.4rem; /* 14px */
  line-height: 1.5; 
  color: #333; 
  background-color: #fff; 
}

ul, ol { 
  list-style: none; 
  margin: 0; 
  padding: 0; 
}

a { 
  color: #007fff; /* 阿里云蓝 */
  text-decoration: none; 
}

a:hover { text-decoration: underline; }

img { 
  max-width: 100%; 
  height: auto; 
  vertical-align: middle; 
}

button { 
  cursor: pointer; 
  border: 0; 
  background: transparent; /* 透明背景(适配按钮定制) */
}

3. 网易(网易云音乐/网易官网)

网易系产品常用「NetEase You Yuan」(网易邮箱体),颜色偏深且强调「年轻化」:

/* 网易CSS初始化 */
* { 
  margin: 0; 
  padding: 0; 
  box-sizing: border-box; 
}

html { font-size: 62.5%; /* 1rem = 10px */ }

body { 
  font-family: "NetEase You Yuan", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; 
  font-size: 1.4rem; /* 14px */
  line-height: 1.7; 
  color: #222; /* 深灰色文本(更醒目) */
  background-color: #fff; 
}

ul, ol { list-style: none; }

a { 
  text-decoration: none; 
  color: #0081ff; /* 网易红/蓝(因产品而异,此处为网易云音乐蓝) */
}

a:hover { text-decoration: underline; }

img { 
  border: 0; 
  vertical-align: middle; 
}

input, textarea, button { 
  font-family: inherit; 
  font-size: inherit; 
}

button { cursor: pointer; }