bootstrap源码学习:normalize(1)

经历了上次的打印篇,我们就到了重置初始化样式的部分,废话少说,咱继续观察

html {
  box-sizing: border-box;
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -ms-overflow-style: scrollbar;
  -webkit-tap-highlight-color: transparent;
}

box-sizing设为了border-box,在添加边框的时候可以避免宽度溢出。行高默认是1.15~text-size-adjust是100%。

为了防止iPhone 和 Android 的浏览器纵向 (Portrate mode) 和橫向 (Landscape mode) 模式皆有自动调整字体大小的功能。

tap-highlight-color属性也是移动端的属性,当用户轻按一个链接或者JavaScript可点击元素时给元素覆盖一个高亮色,具体可以看:http://www.css88.com/book/css/properties/only-webkit/tap-highlight-color.htm,用手机体验一下例子就更好啦。

*,
*::before,
*::after {
  box-sizing: inherit;
}

box-sizing不会自动继承自父类,在这里就写了一个继承。

@-ms-viewport {
  width: device-width;
}

Internet Explorer 10并没有将屏幕的宽度和视口(viewport)的宽度区别开,这就导致Bootstrap中的媒体查询并不能很好的发挥作用。为了解决这个问题,引入以上内容。这样做会导致Windows Phone 8 设备按照桌面浏览器的方式呈现页面,而不是较窄的“手机”呈现方式。为了解决这个问题,还需要加入其他CSS和JavaScript代码,直到微软修复此问题,我们留个疑问现在这里吧。(详情:http://www.cnblogs.com/rubylouvre/p/3360986.html)

接下来慢慢有了bootstrap自己的样式风格

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  font-weight: normal;
  line-height: 1.5;
  color: #212529;
  background-color: #fff;
}

去除body的margin值,网上一般都是把margin和padding一起去除,每个浏览器预设定的可能标准都不一样,但是实验发现~大部分主流的浏览器其实没有预设padding值。比如谷歌是:margin:8px;Opera也和谷歌一样~IE又不一样了。

[tabindex="-1"]:focus {
  outline: none !important;
}
hr {
  box-sizing: content-box;
  height: 0;
  overflow: visible;
}
h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: .5rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

字上都设置下下部距离,没有设置上部距离。

abbr[title],
abbr[data-original-title] {
  text-decoration: underline;
  -webkit-text-decoration: underline dotted;
          text-decoration: underline dotted;
  cursor: help;
  border-bottom: 0;
}

这里的缩写,在一般情况下,是需要给一个点形下划线,并且鼠标经过还会给出?的标识,让用户有更好的体验。(codepen里的abbr默认也是这个样式)

address {
  margin-bottom: 1rem;
  font-style: normal;
  line-height: inherit;
}

浏览器默认会把address斜体化,这里重置为和大家一样了~

ol,
ul,
dl {
  margin-top: 0;
  margin-bottom: 1rem;
}

默认情况下,ol,ul,dl都有上下对称大小的margin边距,这里把列表的margin-top都去除~给了一个bottom值。没有去除padding是因为有时候要用到这个padding值,在一些比如你本身就想要圆点/数字标记。

 

转载于:https://www.cnblogs.com/rimochiko/p/7624568.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值