Git Product home page Git Product logo

basecss's Introduction

baseCss

意义

统一不同浏览器差异、团队开发起始标准;弥补浏览器的「缺点」

友情提示

前端开发中如果不是 UI 特别要求,颜色值采用 web 安全色最佳,像素以偶数最佳
移动端开发,量度可以尝试 rem 为单位「什么是 rem,请自行 Google」
使用 rem 为量度单位时,浏览器会是基于 html 节点而不是 body 节点计算大小

代码解释

/**
 * base.css - 航洋无声
 * mail -  [email protected]
 * weibo - http://weibo.com/512jj
 */

html {
  /*标准字体大小设置 14 像素「rem 参照对象」*/
  font-size: 14px;
  /*滚动事件发生在 html 元素上;JS 中可以监听 html 的滚动*/
  overflow-y: auto;
  /*让 html 和浏览器窗口高度一致*/
  height: 100%;
  /*少数浏览器默认背景色为浅灰色,所以设置默认背景颜色为纯白*/
  background-color: #fff;
}

html,
body {
  /*body 宽度大 html 度时,某些浏览器会出现内部滚动条;所以设置「html、body」宽度相同且「overflow-x: hidden」*/
  overflow-x: hidden;
  width: 100%;
  /*取消部分浏览器点击有阴影*/
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  /*优化移动端滚动事件*/
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
}

body {
  /*设置基本字体配置*/
  font: 1rem 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft Yahei', Arial, sans-serif;
  /*让绝对定位元素,根据 body 定位*/
  position: relative;
  /*设置网页基本字体颜色为浅灰色*/
  color: #666;
  /*使字体渲染更顺滑*/
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}


/**
 * 移除常用标签的浏览器默认的「margin、padding」
 * pre、code、legend、fieldset、blockquote … 等标签不是很常用,所以就不一一列举,如果项目中使用到,可以自己单独写
 */

body,
p,
h1,
h2,
h3,
h4,
h5,
h6,
dl,
dd,
ul,
ol,
th,
td,
button,
figure,
input,
textarea,
form {
  margin: 0;
  padding: 0;
}


/**
 * 不同浏览器的 input、select、textarea 的盒子模型宽度计算方式不同,统一为最常见的 content-box
 */

input,
select,
textarea {
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
}

table {
  /*table 相邻单元格的边框间的距离设置为 0*/
  border-spacing: 0;
  /*默认情况下给 tr 设置 border 没有效果,如果 table 设置了边框为合并模式:「border-collapse: collapse;」就可以了*/
  border-collapse: collapse;
}


/**
 * 移除浏览器部分元素的默认边框
 * acronym、fieldset … 等其他标签不是很常用,就不会一一列举;如果项目中用到,可以自己单独写
 */

img,
input,
button,
textarea {
  border: none;
  -webkit-appearance: none;
}

input {
  /*由于 input 默认不继承父元素的居中样式,所以设置:「text-align: inherit」*/
  text-align: inherit;
}

textarea {
  /*textarea 默认不可以放缩*/
  resize: none;
}


/**
 * 由于以下元素的部分属性没有继承父节点样式,所以声明这些元素的这些属性为父元素的属性
 * 取消这些元素 `outline` 样式
 */

a,
h1,
h2,
h3,
h4,
h5,
h6,
input,
select,
button,
option,
textarea,
optgroup {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  font-style: inherit;
  line-height: inherit;
  color: inherit;
  outline: none;
}


/**
 * 取消超链接元素的默认文字装饰
 * 另外 del、ins 标签的中划线、下划线还是挺好的,就不去掉
 */

a {
  text-decoration: none;
}

ol,
ul {
  /*开发中 UI 设计的列表都是和原生的样式差太多,所以直接给取消 ol,ul 默认列表样式*/
  list-style: none;
}

button,
input[type='submit'],
input[type='button'] {
  /*鼠标经过是「小手」形状表示可点击*/
  cursor: pointer;
}

input::-moz-focus-inner {
  /*取消火狐浏览器部分版本 input 聚焦时默认的「padding、border」*/
  padding: 0;
  border: 0;
}


/*取消部分浏览器数字输入控件的操作按钮*/

input[type='number'] {
  -moz-appearance: textfield;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}


/*输入控件 placeholder 色设置 #999*/

input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: #999;
}

input:-moz-placeholder,
textarea:-moz-placeholder {
  color: #999;
}

input::-moz-placeholder,
textarea::-moz-placeholder {
  color: #999;
}

input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
  color: #999;
}

template {
  /*由于部分浏览 template 会显示出来,所以要隐*/
  display: none;
}

另外附上 常用原子类

感谢阅读

basecss's People

Contributors

hangyangws avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.