当前位置: 首页 > news >正文

传销公司做网站运营东莞seo优化排名推广

传销公司做网站运营,东莞seo优化排名推广,网站开发前的准备工作,做视频链接网站移动端适配 方案 1:rem html font-size 方案 2:vw rem html font-size rem 是相对于 html 元素的 font-size 来设置的单位,通过在不同屏幕尺寸下动态修改 html 元素的 font-size 可达到适配效果 在开发中,我们只需要考虑两个…

移动端适配

方案 1:rem + html font-size

方案 2:vw



rem + html font-size

rem 是相对于 html 元素的 font-size 来设置的单位,通过在不同屏幕尺寸下动态修改 html 元素的 font-size 可达到适配效果

在开发中,我们只需要考虑两个问题:

  1. 针对不同的屏幕尺寸设置不同的 html font-size

  2. 将元素尺寸单位转为 rem


动态设置 html font-size


方法一:通过媒体查询设置 html font-size

思路:通过媒体查询根据不同屏幕尺寸设置不同的 html font-size

缺点:① 如果动态改变屏幕尺寸,不能实时更新、 ② 只能针对某个尺寸范围设置 html font-size

@media screen and (min-width: 320px) {html {font-size: 20px;}
}@media screen and (min-width: 375px) {html {font-size: 24px;}
}@media screen and (min-width: 414px) {html {font-size: 28px;}
}@media screen and (min-width: 480px) {html {font-size: 32px;}
}.box {width: 5rem;height: 5rem;background-color: blue;
}

方法二:通过 JS 设置 html font-size

思路:通过监听屏幕尺寸的变化动态修改 html font-size

一般会将 html font-size 设置为屏幕宽度的 1/10,方便计算

function setRemUnit() {const htmlEl = document.documentElement;const htmlFontSize = htmlEl.clientWidth / 10;htmlEl.style.fontSize = htmlFontSize + 'px';
}
setRemUnit();
window.addEventListener('resize', setRemUnit);

px 与 rem 的单位换算

假设原型图中屏幕宽度为 375px,现有一宽度为 100px 的 div。我们想将 100px 转成对应的 rem 值:

  1. 根元素 html 的 font-size = 375px / 10 = 37.5px (37.5px 即为 “基准字体大小”)

  2. 元素的 rem 值 = 100px / 37.5px


手动计算

编写 scss 函数:

$baseFontSize: 37.5px; // 基准字体大小
@function pxToRem($pxValue) {@return $pxValue / $baseFontSize * 1rem;
}

使用 scss 函数编写样式:

.example {font-size: pxToRem(24px); // 将 24px 转换为对应的 rem 值margin: pxToRem(16px) pxToRem(8px); // 将 16px 和 8px 转换为对应的 rem 值
}

工程化自动计算

安装 postcss-pxtorem 依赖包、配置 webpack.config.js 文件:

npm install postcss-pxtorem -D
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssPxToRem = require('postcss-pxtorem');const stylesHandler = MiniCssExtractPlugin.loader;
const postcssLoader = {loader: 'postcss-loader',options: {postcssOptions: {plugins: [postcssPxToRem({rootValue: 37.5, // 基准字体大小, 默认 16propList: ['*'], // 转换的属性, 默认 ['font', 'font-size', 'line-height', 'letter-spacing']}),],},},
};const config = {// ...module: {// ...rules: [// ...{test: /\.css$/i,use: [stylesHandler, 'css-loader', postcssLoader],},],},
};

正常编写样式,px 会自动转换为 rem:

.example {font-size: 24px; /* 将转换为 0.64rem */margin: 16px 8px; /* 将转换为 0.43rem 0.21rem */
}



vw 单位

100vw 相当于整个视口的宽度 innerWidth,1vw 相当于视口宽度的 1%,将 px 转换为 vw 即可完成适配

vw 相对于 rem 的优势:不需要考虑 html font-size 的问题

事实上,rem 作为一种过渡的方案,它利用的也是 vw 的思想


px 与 vw 的单位转换

假设原型图中屏幕宽度为 375px,有一宽度为 100px 的 div。我们需要将 100px 转成对应的 vw 值:

  1. 1vw = 375px / 100 = 3.75px
  2. 元素的 vw 值 = 100px / 3.75px

手动计算

编写 scss 函数:

$baseWidth: 375px; // 设计稿宽度
@function pxToVw($pxValue) {@return $pxValue / $baseWidth * 100vw;
}

使用 scss 函数编写样式:

.example {width: pxToVw(100px); // 将 100px 转换为对应的 vw 值margin: pxToVw(16px) pxToVw(8px); // 将 16px 和 8px 转换为对应的 vw 值
}

工程化自动计算

安装 postcss-px-to-viewport-8-plugin 依赖包、配置 webpack.config.js 文件:

npm install postcss-px-to-viewport-8-plugin -D
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssPxToViewport = require('postcss-px-to-viewport-8-plugin');const stylesHandler = MiniCssExtractPlugin.loader;
const postcssLoader = {loader: 'postcss-loader',options: {postcssOptions: {plugins: [postcssPxToViewport({viewportWidth: 375, // 设计稿宽度, 默认 320}),],},},
};const config = {// ...module: {// ...rules: [// ...{test: /\.css$/i,use: [stylesHandler, 'css-loader', postcssLoader],},],},
};

正常编写样式,px 会自动转换为 vw:

.example {width: 100px; /* 将转换为 26.67vw */margin: 16px 8px; /* 将转换为 4.27vw 2.13vw */
}

http://www.dinnco.com/news/12768.html

相关文章:

  • 建一个收费网站 怎么收费吉林黄页电话查询
  • 网站开发外包业务怎么接站长综合查询工具
  • 建网站要学什么新手怎么做网页
  • 网站开发哪里可做私活深圳百度快照优化
  • 长沙河东做网站百度推广怎么登录
  • 深圳网站建设托管免费seo视频教学
  • 城乡与住房建设部网站西藏自治区seo 标题 关键词优化
  • 专门做字体设计的网站广州网络推广seo
  • 北京建商城网站百度网盘搜索
  • 建美食网站有哪些原因站长推荐入口自动跳转
  • 南通专业做网站网页版
  • 新建网站做优化恩城seo的网站
  • php网站开发心得3500字友情链接方面
  • 做网站需要的程序优化手机性能的软件
  • 公众平台微信公众号登陆系统优化软件有哪些
  • title 镇江网站建设seo优化包括哪些
  • 网站建设 .北京蓝纤注册网站流程和费用
  • 甘肃肃第八建设集团网站1搜索引擎优化网站排名
  • wordpress做商城网站国外网站排名 top100
  • 管廊建设网站长沙官网seo服务
  • 网站中flash怎么做的什么是seo教程
  • wordpress 归档 文章分类北京网络优化
  • 做网站的公司叫什么名字单页网站制作
  • 个人网站怎么做微信支付常州seo收费
  • 政府网站建设策划武汉seo全网营销
  • 房地产市场低迷上海自动seo
  • wordpress使用html界面网站为什么要seo
  • wordpress页面中添加小工具江门关键词优化公司
  • wordpress个性首页网站快照优化公司
  • 怎么做飞机票的图片网站查询网站