重置CSS模块是Next.CSS框架的一部分。该模块为您的下一个项目重置默认的CSS样式。您可以在所有带有模块串件的现代网站中使用,例如WebPack,lollup,carcel。
Next.css在github上
您可以使用NPM或纱线软件包管理器安装。
npm i @nextcss/reset
yarn add @nextcss/reset简单导入您的项目,此模块仅包含元素选择器规则。
import '@nextcss/reset' ; 某些HTML元素在浏览器中具有默认样式,并且每个浏览器中都有不同样式的HTML元素。该模块将重置此样式。
14px字体大小和1.4线高度的系统字体堆栈在每个HTML元素上:将border-box设置为默认的box-sizing ,禁用Drag and Drop功能和重置outline 。
* ,
: before ,
: after {
box-sizing : border-box;
-webkit-user-drag : none;
outline : none;
}将默认font-size设置为14px ,禁用移动设备的Tap highlighting ,启用Smooth font rendering ,禁用Apple设备的Text size increase algorithm 。
html {
font-size : 14 px ;
-webkit-tap-highlight-color : transparent;
-webkit-font-smoothing : antialiased;
-webkit-text-size-adjust : 100 % ;
}禁用pinch zoom和其他touch gestures ,禁用pull to refresh , rubber banding和scroll chaining功能,将body上的max-width设置为100 viewport width ,重置默认margin ,设置默认line-height和Systen Font Stack
body {
touch-action : pan-x pan-y;
overscroll-behavior : none;
max-width : 100 vw ;
margin : 0 ;
line-height : 1.4 ;
font-family : ui-sans-serif , system-ui , -apple-system , BlinkMacSystemFont , 'Segoe UI' , Roboto , 'Helvetica Neue' ,
Arial , 'Noto Sans' , sans-serif , 'Apple Color Emoji' , 'Segoe UI Emoji' , 'Segoe UI Symbol' , 'Noto Color Emoji' ;
}重置标题和段落上的默认margin和font属性。
h1 ,
h2 ,
h3 ,
h4 ,
h5 ,
h6 ,
p {
margin : 0 ;
font : inherit;
}修复动态small标签
small {
font-size : 85 % ;
}重置链接上的color和text-decoration 。
a {
color : inherit;
text-decoration : none;
}重置button标签
button {
background-color : inherit;
border : 0 ;
color : inherit;
padding : 0 ;
}限制图像width和重置border 。
img {
max-width : 100 % ;
height : auto;
border : none;
}在通用输入元素上重置border , shadow , font ,将font-size设置为16px 。 16px字体尺寸避免在Apple设备上调整viewport大大大小。
input ,
textarea ,
select {
font : inherit;
font-size : 16 px ;
border : 1 px solid;
border-radius : 0 ;
background-clip : padding-box;
}
fieldset {
border : 1 px solid;
}列表上的重置margin , padding和list-style 。
ul ,
ol {
margin : 0 ;
padding : 0 ;
list-style-type : none;
}地平线重置border
hr {
border : none;
border-bottom : 1 px solid;
}重置table边框和桌头font-weight
table {
border-spacing : 0 ;
border-collapse : collapse;
}
th {
font-weight : inherit;
}重置iframe border
iframe {
border : 0 ;
}在常见的HTML元素上重置margin和padding
menu {
margin : 0 ;
padding : 0 ;
}
form ,
figure ,
pre ,
blockquote ,
dl ,
dd {
margin : 0 ;
}重置adrress标签上的font
address {
font : inherit;
}我们强烈建议将postcss与autoprefixer和postcss-purgecss一起使用。该堆栈将使用浏览器特定前缀(例如-webkit扩展CSS规则,并将删除生产构建中未使用的样式。
npm i -D postcss autoprefixer @fullhuman/postcss-purgecss我们的postcss.config.js config。您需要为项目配置content参数。
module . exports = {
plugins :
process . env . NODE_ENV === 'production'
? [
'autoprefixer' ,
[
'@fullhuman/postcss-purgecss' ,
{
content : [ './{pages,components}/**/*.{js,jsx}' ] ,
safelist : [ 'html' , 'body' ] ,
defaultExtractor : ( content ) => content . match ( / [w-/:]+(?<!:) / g ) || [ ] ,
} ,
] ,
]
: [ 'autoprefixer' ] ,
} ; 麻省理工学院许可证。版权(C)2021 ZSOLT TOVIS