此篇会介绍 Bootstrap 使用的 css reset 档案
_reboot.scss
。
还不懂 css reset 的朋友,建议先阅读事前准备的文章,再继续阅读会更好消化呦。
Normalize.css
基础之上。优点
body
padding
、h1~h6
)缺点
使用到一只档案:
_reboot.scss:主要清除 css 样式。
介绍几个有趣的样式设置。
计算元素尺寸时不受 padding
、border
影响。
*,
*::before,
*::after {
box-sizing: border-box;
}
使用锚点达到网页滚动到某个指定地方,smooth
让网页能平滑滚动到指定地方。(预设 auto
,立即滚动)
@if $enable-smooth-scroll {
@media (prefers-reduced-motion: no-preference) {
scroll-behavior: smooth;
}
}
常用於网页全站(全域)样式设置。
<body>
标签包住所有网页元素,通常会在 body 样式中设置预设样式。
编译後的 css
body {
margin: 0;
font-family: var(--bs-font-family-noto-sans);
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #494846;
background-color: white;
}
依照上方范例介绍
font-size
,则预设大小就会是 1rem
。// 保留预设样式 font-size 为 1rem。
.title {
color: #000;
}
// 覆盖 font-size 样式为 0.85rem。
.title {
font-size: 0.85rem;
color: #000;
}
举例 h1~h6 标签
预设变数
$headings-margin-bottom: $spacer / 2 !default;
$headings-font-family: null !default;
$headings-font-style: null !default;
$headings-font-weight: 500 !default;
$headings-line-height: 1.2 !default;
$headings-color: null !default;
预设样式 %heading
%heading {
margin-top: 0; // 1
margin-bottom: $headings-margin-bottom;
font-family: $headings-font-family;
font-style: $headings-font-style;
font-weight: $headings-font-weight;
line-height: $headings-line-height;
color: $headings-color;
}
// h1~h6 都是使用 %heading 样式,指差别在於 font-size 值不同
h1 {
@extend %heading;
@include font-size($h1-font-size);
}
编译後的 css
// 由下样式可以得知 %heading 样式设置结果
h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 {
margin-top: 0;
margin-bottom: 0.5rem;
font-weight: 500;
line-height: 1.2;
}
// 透过 @include font-size() 函式,来设置彼此的 font-size 样式
h1, .h1 {
font-size: calc(1.375rem + 1.5vw);
}
@media (min-width: 1200px) {
h1, .h1 {
font-size: 2.5rem;
}
}
上述介绍了几个 _reboot.scss
的样式,大家想了解更多欢迎从原始码下手,复制样式出来编译,并查看编译後的 css 样式为何,透过这种方式可以加速了解 _reboot.scss
的结果以及作用。
_reboot.scss
原始码。_reboot.scss
样式。(我会命名为 _base.scss
)_reboot.scss
,那就不需要引入 _reboot.scss
。
>>: D27 - 彭彭的课程# Python 实体物件的建立与使用 - 下篇 - 实体方法 - Instance Method(1)
伪类和伪元素皆是从 DOM tree 抽象出来的概念, 用以修饰实际上不在 DOM tree 上的部...
首先登入到 LINE Notify 并进入到个人页面 接着选择要接收通知的聊天室,也可以透过一对一接...
Mock What's mock? 先想像一个画面,当我们要隔离我们的元件时,一个component...
x-on x-on 可以简单的用从 DOM 中来触发事件,像是最常用的按钮: <button ...
基本上,JSX 单纯只是 React.createElement(component, props...