vue中引入初始化样式reset.css和自适应rem.js

2019-01-15  本文已影响0人  无疆wj

1.在相关目录中创建好文件
2.在main.js中引入

import ‘./common/rem’
import ‘./style/reset.css’
// 即完成,设置已生效

附录:
a. 常用rem设置

<script>
onload = function () {
  setHTML()
  onresize = function () {
    setHTML()
  }

  function setHTML() {
    let baseVal = 100
    let pageWidth = 375
    let maxFontSize = 200
    let screenWidth = document.querySelector('html').offsetWidth
    let fontsize = screenWidth * baseVal / pageWidth
    if (fontsize > maxFontSize) {
      fontsize = maxFontSize
    }
    document.querySelector('html').style.fontSize = fontsize + 'px'
  }
}
</script>

b. 常用reset.css设置

html {
    overflow-x: auto;
    overflow-y: scroll;
}

body,
dl,
dt,
dd,
ul,
ol,
li,
pre,
form,
fieldset,
input,
p,
blockquote,
th,
td {
    font-weight: 400;
    margin: 0;
    padding: 0;
}

h1,
h2,
h3,
h4,
h4,
h5 {
    margin: 0;
    padding: 0;
}

body {
    background-color: #FFFFFF;
    color: #666666;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 12px;
    text-align: left;
}

select {
    font-size: 12px;
}

table {
    border-collapse: collapse;
}

fieldset,
img {
    border: 0 none;
}

fieldset {
    margin: 0;
    padding: 0;
}

fieldset p {
    margin: 0;
    padding: 0 0 0 8px;
}

legend {
    display: none;
}

address,
caption,
em,
strong,
th,
i {
    font-style: normal;
    font-weight: 400;
}

table caption {
    margin-left: -1px;
}

hr {
    border-bottom: 1px solid #FFFFFF;
    border-top: 1px solid #E4E4E4;
    border-width: 1px 0;
    clear: both;
    height: 2px;
    margin: 5px 0;
    overflow: hidden;
}

ol,
ul {
    list-style-image: none;
    list-style-position: outside;
    list-style-type: none;
}

caption,
th {
    text-align: left;
}

q:before,
q:after,
blockquote:before,
blockquote:after {
    content: "";
}
上一篇下一篇

猜你喜欢

热点阅读