1. rem 就是頁面根元素的font-size

獲取頁面寬度,將根元素的字號設置為頁面寬度,從而動態(tài)的使一個rem為當前頁面寬度
2. 使用sass px2函數(shù)
npm config set registry?https://registry.npm.taobao.org/
touch ~/.bashrc
echo 'export SASS_BINARY_SITE="https://npm.taobao.org/mirrors/node-sass"' >> ~/.bashrc
source ~/.bashrc
npm i -g node-sass? ? //上面是設置使用淘寶的源
mkdir ~/Desktop/scss-demo
cd ~/Desktop/scss-demo
mkdir scss css
touch scss/style.scss
start scss/style.scss
node-sass -wr scss -o css
3. 在sass中使用px2函數(shù)
@function px( $px ){
@return $px/$designWidth*10 + rem;
}
$designWidth : 640; // 640 是設計稿的寬度
/*······上面是px2函數(shù)。下面就可以使用這個函數(shù),而不用一直計算rem了····*/
child{
width: px(320);
height: px(160);
}