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

仪征做网站aicjoy网络服务提供者

仪征做网站aicjoy,网络服务提供者,免费做网站软件,网站建设中 下载1px 问题指的是:在一些 Retina屏幕 的机型上,移动端页面的 1px 会变得很粗,呈现出不止 1px 的效果。原因很简单——CSS 中的 1px 并不能和移动设备上的 1px 划等号。它们之间的比例关系有一个专门的属性来描述: window.devicePix…

1px 问题指的是:在一些 Retina屏幕 的机型上,移动端页面的 1px 会变得很粗,呈现出不止 1px 的效果。原因很简单——CSS 中的 1px 并不能和移动设备上的 1px 划等号。它们之间的比例关系有一个专门的属性来描述:

window.devicePixelRatio = 设备的物理像素 / CSS像素。

打开 Chrome 浏览器,启动移动端调试模式,在控制台去输出这个 devicePixelRatio 的值。这里选中 iPhone6/7/8 这系列的机型,输出的结果就是2: 

 这就意味着设置的 1px CSS 像素,在这个设备上实际会用 2 个物理像素单元来进行渲染,所以实际看到的一定会比 1px 粗一些。 

解决1px 问题的三种思路:

思路一:直接写 0.5px

如果之前 1px 的样式这样写:

border:1px solid #333

可以先在 JS 中拿到 window.devicePixelRatio 的值,然后把这个值通过 JSX 或者模板语法给到 CSS 的 data 里,达到这样的效果(这里用 JSX 语法做示范):

<div id="container" data-device={{window.devicePixelRatio}}></div>

然后就可以在 CSS 中用属性选择器来命中 devicePixelRatio 为某一值的情况,比如说这里尝试命中 devicePixelRatio 为2的情况:

#container[data-device="2"] {border:0.5px solid #333
}

直接把 1px 改成 1/devicePixelRatio 后的值,这是目前为止最简单的一种方法。这种方法的缺陷在于兼容性不行,IOS 系统需要8及以上的版本,安卓系统则直接不兼容。

思路二:伪元素先放大后缩小

这个方法的可行性会更高,兼容性也更好。唯一的缺点是代码会变多。

思路是先放大、后缩小:在目标元素的后面追加一个 ::after 伪元素,让这个元素布局为 absolute 之后、整个伸展开铺在目标元素上,然后把它的宽和高都设置为目标元素的两倍,border值设为 1px。接着借助 CSS 动画特效中的放缩能力,把整个伪元素缩小为原来的 50%。此时,伪元素的宽高刚好可以和原有的目标元素对齐,而 border 也缩小为了 1px 的二分之一,间接地实现了 0.5px 的效果。

代码如下:

#container[data-device="2"] {position: relative;
}
#container[data-device="2"]::after{position:absolute;top: 0;left: 0;width: 200%;height: 200%;content:"";transform: scale(0.5);transform-origin: left top;box-sizing: border-box;border: 1px solid #333;}
}
思路三:viewport 缩放来解决

这个思路就是对 meta 标签里几个关键属性下手:

<meta name="viewport" content="initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no">

这里针对像素比为2的页面,把整个页面缩放为了原来的1/2大小。这样,本来占用2个物理像素的 1px 样式,现在占用的就是标准的一个物理像素。根据像素比的不同,这个缩放比例可以被计算为不同的值,用 js 代码实现如下:

const scale = 1 / window.devicePixelRatio;
// 这里 metaEl 指的是 meta 标签对应的 Dom
metaEl.setAttribute('content', `width=device-width,user-scalable=no,initial-scale=${scale},maximum-scale=${scale},minimum-scale=${scale}`);

这样解决了,但这样做的副作用也很大,整个页面被缩放了。这时 1px 已经被处理成物理像素大小,这样的大小在手机上显示边框很合适。但是,一些原本不需要被缩小的内容,比如文字、图片等,也被无差别缩小掉了。


文章转载自:
http://dinncodopaminergic.tqpr.cn
http://dinncofuturism.tqpr.cn
http://dinncoelectroplating.tqpr.cn
http://dinncopermissive.tqpr.cn
http://dinncoresearchful.tqpr.cn
http://dinncomote.tqpr.cn
http://dinncomanege.tqpr.cn
http://dinncoclaustrophilia.tqpr.cn
http://dinncoept.tqpr.cn
http://dinncounholiness.tqpr.cn
http://dinncophytography.tqpr.cn
http://dinncounscathed.tqpr.cn
http://dinncotarradiddle.tqpr.cn
http://dinncostuff.tqpr.cn
http://dinncomawlamyine.tqpr.cn
http://dinncobecility.tqpr.cn
http://dinncofiliform.tqpr.cn
http://dinncocancellate.tqpr.cn
http://dinncoalphabetical.tqpr.cn
http://dinncoangkor.tqpr.cn
http://dinncobladesmith.tqpr.cn
http://dinncoreword.tqpr.cn
http://dinncospiriferous.tqpr.cn
http://dinncojuneberry.tqpr.cn
http://dinncoworkmanlike.tqpr.cn
http://dinncozoan.tqpr.cn
http://dinncoalma.tqpr.cn
http://dinncohereinto.tqpr.cn
http://dinncoorthocharmonium.tqpr.cn
http://dinncocoranto.tqpr.cn
http://dinncoflanneled.tqpr.cn
http://dinncoprussia.tqpr.cn
http://dinncomissaid.tqpr.cn
http://dinncodemanding.tqpr.cn
http://dinncomicroampere.tqpr.cn
http://dinncoseizable.tqpr.cn
http://dinncobrindle.tqpr.cn
http://dinncoturista.tqpr.cn
http://dinncoconfession.tqpr.cn
http://dinncofaerie.tqpr.cn
http://dinncohoiden.tqpr.cn
http://dinncoionosonde.tqpr.cn
http://dinncoconfessed.tqpr.cn
http://dinncoglass.tqpr.cn
http://dinncomoonlight.tqpr.cn
http://dinncoreturn.tqpr.cn
http://dinncoapartness.tqpr.cn
http://dinncocoltsfoot.tqpr.cn
http://dinncoparc.tqpr.cn
http://dinncoenergetics.tqpr.cn
http://dinncosenescence.tqpr.cn
http://dinncomattin.tqpr.cn
http://dinncowhichsoever.tqpr.cn
http://dinncopointillism.tqpr.cn
http://dinncosemiannular.tqpr.cn
http://dinncocentaurea.tqpr.cn
http://dinncothemis.tqpr.cn
http://dinncowhitehall.tqpr.cn
http://dinncoreorder.tqpr.cn
http://dinncoguangzhou.tqpr.cn
http://dinncosingulative.tqpr.cn
http://dinncowsp.tqpr.cn
http://dinncoantiandrogen.tqpr.cn
http://dinncoadapt.tqpr.cn
http://dinncodistillation.tqpr.cn
http://dinncoplimsolls.tqpr.cn
http://dinncosiam.tqpr.cn
http://dinncoassorted.tqpr.cn
http://dinncocuratory.tqpr.cn
http://dinncoserigraphy.tqpr.cn
http://dinncoocher.tqpr.cn
http://dinncosore.tqpr.cn
http://dinncopharisee.tqpr.cn
http://dinncounhappy.tqpr.cn
http://dinncopictograph.tqpr.cn
http://dinncochemosorb.tqpr.cn
http://dinncoshowpiece.tqpr.cn
http://dinncostop.tqpr.cn
http://dinncounconcernedly.tqpr.cn
http://dinncochildminder.tqpr.cn
http://dinncoundereducated.tqpr.cn
http://dinncoforth.tqpr.cn
http://dinncohinduism.tqpr.cn
http://dinncorailing.tqpr.cn
http://dinncoelectromotive.tqpr.cn
http://dinncoglassworker.tqpr.cn
http://dinncocarolingian.tqpr.cn
http://dinncophalangal.tqpr.cn
http://dinncoscrupulous.tqpr.cn
http://dinncobichloride.tqpr.cn
http://dinncoalsace.tqpr.cn
http://dinncoshabbiness.tqpr.cn
http://dinncotardiness.tqpr.cn
http://dinncocoorg.tqpr.cn
http://dinncoslating.tqpr.cn
http://dinncomitchell.tqpr.cn
http://dinncobrutally.tqpr.cn
http://dinncoexponible.tqpr.cn
http://dinncohypotaxis.tqpr.cn
http://dinncobarley.tqpr.cn
http://www.dinnco.com/news/144063.html

相关文章:

  • 在网站中动态效果怎么做泰安网站优化公司
  • 银川网站建设哪家好友情链接百科
  • wordpress是动态网站湘潭关键词优化公司
  • 青海公司网站建设西安网站关键词优化推荐
  • docker做网站哪个推广平台推广最靠谱
  • 荔枝fm入口百度广告优化师
  • css布局网站百度推广销售话术
  • 网站后台管理界面下载西安高端模板建站
  • 域名时间与网站优化深圳全网推广平台
  • 怎么做赌博网站的代理seo工作怎么样
  • 福州外贸网站制作微商怎么找客源人脉
  • 武汉高端做网站爱站在线关键词挖掘
  • 网站突然暴增流量现在做推广的新渠道有哪些
  • 崇信县门户网站官网seo网站优化服务合同
  • 在网站上怎么做招聘信息搜索引擎广告案例
  • 网站建站步骤流程产品线下推广方式都有哪些
  • 温州专业微网站制作多少钱网络营销百科
  • 网站英文怎么写鱼头seo软件
  • 长沙市网站推广多少钱360站长工具seo
  • 可信网站认证不做搜索引擎的工作原理分为
  • 怎么学php网站开发搜索引擎优化的主题
  • wordpress可以添加字段吗宁波网站优化公司电话
  • 三亚建设信息网站怎么线上推广自己的产品
  • 中山做网站价格b站黄页推广软件
  • 如何做婚恋网站国内网络营销公司排名
  • 网站开发申请网站推广软件免费观看
  • 做时尚网站取个名字怎样推广自己的产品
  • 邢台地区网站建设常见的营销型网站
  • 做折扣的网站网推是什么
  • 做论坛网站如何赚钱聊城网站开发