分辨率兼容学习笔记

一种简单的自适应布局:

缺点:在断点处,页面跳变的很突兀。属于自适应布局吧。要用@media区分三种分辨率情况。
当窗口大于1024px 时,只会被压缩,并不会发生其他变化
@media screen and (max-width:1024px) {
body {
background-color: red;
}
}
* {
margin: 0;
padding: 0;
text-align: center;
color: yellow;
}
.header {
width: 100%;
height: 100px;
background: #ccc;
line-height: 100px;
}
.main {
background: green;
width: 100%;
}
.clearfix:after {
display: block;
height: 0;
content: “”;
visibility: hidden;
clear: both;
}
.left,
.center,
.right {
float: left;
}
.left {
width: 20%;
background: #112993;
height: 300px;
font-size: 50px;
line-height: 300px;
}
.center {
width: 60%;
background: #ff0;
height: 400px;
color: #fff;
font-size: 50px;
line-height: 400px;
}
.right {
width: 20%;
background: #f0f;
height: 300px;
font-size: 50px;
line-height: 300px;
}
.footer {
width: 100%;
height: 50px;
background: #000;
line-height: 50px;
}
当窗口小于1024px,大于720px的时候,右侧栏取消浮动,在下边显示:

.right {
float: none;
width: 100%;
background: #f0f;
clear: both;
}
.left {
width: 30%;
background: red;
}
.center {
width: 70%;
background: yellow;
}
.main {
height: 800px;
/* background: blue; */
}
当窗口小于720px的时候,左中右三栏,全都取消浮动,宽度100%:
.left,
.center,
.right {
float: none;
width: 100%;
}

// 1.使用 @media 实现
@media 类型 and (条件1) and (条件二) {
css样式
}

// 2.使用@import导入
@import url(“css/moxie.css”) all and (max-width:980px);

// https://blog.csdn.net/u014490083/article/details/79164235

rem实现自适应布局

这个是最简单,但其他项目用的不多,具体有什么坑待踩todo

参考:http://caibaojian.com/web-app-rem.html

rem能等比例适配所有屏幕???

rem是如何工作的?
rem是通过根元素进行适配的,网页中的根元素指的是html我们通过设置html的字体大小就可以控制rem的大小

方法1:通过JS去动态计算根元素的font-size,这样的好处是所有设备分辨率都能兼容适配。
淘宝首页目前就是用的JS计算
怎么计算不同宽度下font-site的值?
举个例子:384/640 = 0.6,384是640的0.6倍,所以384页面宽度下的font-size也等于它的0.6倍,这时384的font-size就等于12px。

方法2:

一般我们在做web app都会先统计自己网站有哪些主流的屏幕设备,然后去针对那些设备去做media query设置也可以实现适配,例如下面这样:

html {
font-size : 20px;
}

@media only screen and (min-width: 401px){
html {
font-size: 25px !important;
}
}
@media only screen and (min-width: 428px){
html {
font-size: 26.75px !important;
}
}
@media only screen and (min-width: 481px){
html {
font-size: 30px !important;
}
}
@media only screen and (min-width: 569px){
html {
font-size: 35px !important;
}
}
@media only screen and (min-width: 641px){
html {
font-size: 40px !important;
}
}

viewport实现???

#layout{
display: block;
flex-direction: column;
width: 80%;
margin: 0 auto;
height: 2rem;
}

#top{
width: 100%;
flex: 0 0 50px;
margin: 0 auto;
background-color:yellow ;
height: 2rem;
}

#main{
flex: 0 0 100%;
}

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="widthdevice-width, initial-scale=1.0, user-scable=0">
    <title>分辨率兼容</title>
    <link href="./big.css" rel="stylesheet" media="(min-device-width:100px)">
    <!-- <link href=".small.css" rel="stylesheet" media="(min-device-width:400px) and (max-device-width:600px)"> -->
</head>

<body>
    <div id="layout"></div>
    <div id="top"></div>
    <div id="main">
        <div>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
        </div>
        <div>
            <li>图片1</li>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
            <li>分类1</li>
        </div>
    </div>
</body>

</html>

左右两列自适应布局

代码如下

html{
font-size: 20px;
/* font-size: 40px; */
}
/2列固定宽度/
#left {
background-color: #cccccc;
border: 2px solid #333333;
width: 300px;
height: 300px;
float: left;
}

#right {
background-color: #cccccc;
border: 2px solid #333333;
width: 300px;
height: 300px;
float: left;
}

/2列自适应宽度/
#left-self-adaption {
background-color: red;
border: 2px solid #333333;
width: 20%;
height: 300px;
float: left;
/* font-size: 3rem; /
/
vh 会随浏览器高度,字体大小变化 /
/
font-size: 5vh; */
font-size: 1.2rem;
}

#right-self-adaption {
background-color: blue;
border: 2px solid #333333;
width: 70%;
height: 300px;
float: left;
/* font-size: 3rem; /
/
font-size: 5vh; */
font-size: 1.2rem;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue中实现PC端分辨率适配笔记本可以通过以下步骤完成: 1. 使用Vue CLI创建一个新的项目,并安装相关的依赖包。确保已经安装了vue-router和vuex等常用的插件。 2. 创建一个全局的样式文件,命名为global.css,并将其引入到主入口文件(main.js)中。在global.css中可以设置一些全局的样式,例如body的字体大小、页面的最小宽度等。 3. 在main.js中,监听浏览器窗口的resize事件,通过document.documentElement.clientWidth获取窗口的宽度,并将其存储到Vuex中。同时,在钩子函数中也要初始化一次,以适配刷新页面等情况。 4. 在需要适配的组件中,引入Vuex,并从Vuex中获取窗口宽度的数据。根据窗口的宽度,设置组件内部元素的样式,例如设置容器的宽度为窗口宽度的80%,居中显示等。可以使用计算属性来动态调整样式。 5. 使用@media媒体查询,在全局样式文件global.css中根据窗口的宽度设置一些响应式的样式。例如,当窗口宽度小于768px时,可以将某个容器的宽度设置为100%等。 6. 在开发过程中,可以使用Chrome浏览器的开发者工具进行调试,通过模拟不同的设备和分辨率,实时查看适配效果。 总之,通过监听窗口宽度的变化,动态设置组件样式和使用@media媒体查询,可以实现Vue PC端分辨率的适配。这种方法能够根据不同设备的分辨率来自适应地调整样式,提高应用的兼容性和用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值