使用rem適配移動端

使用rem適配移動端

在main.js設置字體大小

//以屏幕寬度爲375爲例
const winWidth = window.innerWidth;//獲取屏幕寬度
const fontSize = winWidth / 375 * 20;
document.getElementsByTagName('html')[0].style.fontSize = fontSize + 'px';//設置根元素字體
<div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
</div>
  • 使用less
/*    *.less    */
@r:40rem; /*設計稿寬度以750爲例*/
.home{
	width: 750/@r;
}  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章