清除修改Vue自带的CSS样式

在Vue项目中写样式时发现总是出现一些奇怪的样式和字体颜色,后来发现是Vue自带了默认的CSS样式导致的,只要修改Vue自带的CSS样式即可

  • 首先创建一个resetVueCSS.css文件(其他名字也可以),然后复制下方代码并把该css文件放进Vue项目中,我个人是放在了public目录下

/**
 * 清除Vue自带的CSS样式
 */
 html, body, div, span, applet, object, iframe,
 h1, h2, h3, h4, h5, h6, p, blockquote, pre,
 a, abbr, acronym, address, big, cite, code,
 del, dfn, em, img, ins, kbd, q, s, samp,
 small, strike, strong, sub, sup, tt, var,
 b, u, i, center,
 dl, dt, dd, ol, ul, li,
 fieldset, form, label, legend,
 table, caption, tbody, tfoot, thead, tr, th, td,
 article, aside, canvas, details, embed,
 figure, figcaption, footer, header,
 menu, nav, output, ruby, section, summary,
 time, mark, audio, video, input {
     margin: 0;
     padding: 0;
     border: 0;
     font-size: 100%;
     font-weight: normal;
     vertical-align: baseline;
 }
 
 /* HTML5旧浏览器的显示role重置 */
 article, aside, details, figcaption, figure,
 footer, header, menu, nav, section {
     display: block;
 }
 
 body {
     line-height: 1;
 }
 
 blockquote, q {
     quotes: none;
 }
 
 blockquote:before, blockquote:after,
 q:before, q:after {
     content: none;
 }
 
 table {
     border-collapse: collapse;
     border-spacing: 0;
 }
 
 /* 链接和按钮默认样式 */
 a,button {
     color: #000000;
     text-decoration: none;
     cursor:pointer;
     -webkit-backface-visibility: hidden;
 }
 
 li {
     list-style: none;
 }
 
 /* 滚动条大小 */
 ::-webkit-scrollbar {
     width: 5px;
     height: 5px;
 }
 
 /* 滚动条颜色和圆角角度 */
 ::-webkit-scrollbar-track-piece {
     background-color: rgba(0, 0, 0, 0.2);
     -webkit-border-radius: 6px;
 }
 
 ::-webkit-scrollbar-thumb:vertical {
     height: 5px;
     background-color: rgba(125, 125, 125, 0.7);
     -webkit-border-radius: 6px;
 }
 
 ::-webkit-scrollbar-thumb:horizontal {
     width: 5px;
     background-color: rgba(125, 125, 125, 0.7);
     -webkit-border-radius: 6px;
 }
 
 html, body {
     width: 100%;
 }
 
 body {
     -webkit-text-size-adjust: none;
     -webkit-tap-highlight-color: rgba(255, 255, 255, 0);
 }
  • 然后将该样式导入Vue项目中的main.js文件中覆盖默认样式即可

import '../public/resetVueCSS.css'
//这个路径记得修改,因为我的resetVueCSS.css在public目录中才是这个路径,“..”代表上一级目录

猜你喜欢

转载自blog.csdn.net/Coin_Collecter/article/details/129628806
今日推荐