黑松山资源网 Design By www.paidiu.com
问题
css固定定位position:fixed很容易使用,就是相对浏览器的viewport进行定位,top:0;left:0就是在左上角。
<body> <div class="container"> </div> </body> <style> .container{ width: 100px; height: 100px; background: #888; position: fixed; top: 100px; left: 100px; } </style>
当父级元素设置transform之后
<body> <div class="BFC-box"> <div class="container"></div> </div> </body> <style> .BFC-box{ margin:200px; height: 200px; width: 200px; border:2px solid red; transform: scale(1); } .container{ width: 100px; height: 100px; background: #888; position: fixed; top: 100px; left: 100px; } </style>
fixed元素变成了相对父元素进行定位。
真是令人蛋疼,原因在于transform提升了元素的地位,在W3C规范中有如下说明:
For elements whose layout is governed by the CSS box model, any value other than none for the transform also causes the element to become a containing block, and the object acts as a containing block for fixed positioned descendants
在transform不为none的元素中,定位是会受到影响的。
解决方案
在不影响布局的情况下,可以直接把要定位的元素移动到body下:
<body> <div class="BFC-box"></div> <div class="container"> </div> </body>
如果是在组件中不方便对元素进行操作,可以使用js,以vue为例:
<div ref="container" class="container"></div> mounted(){ document.body.append(this.$refs['contaier']) }
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《粤语超白金 百听不厌的经典金曲 2CD》[WAV/分轨][1.3GB]
- 群星.1994-全世界精丫华星】【WAV+CUE】
- 杜德伟.1997-知.解2CD【滚石】【WAV+CUE】
- 群星.2022-一不小心喵上你原声大碟【TME影音】【FLAC分轨】
- 《战锤40K星际战士2》卡在正在加入服务器解决方法
- 《勇者斗恶龙怪物仙境3》玩法内容介绍
- 《幸福工厂》无限报错解决方法
- 交错战线原始交易所推荐角色一览
- 战锤40K星际战士2战术职业介绍|战术职业技能效果一览
- 战锤40K星际战士2突击职业介绍|突击职业技能效果一览
- [妙音金曲]群星《悲情咖啡屋》(黑胶)2CD[DTS-WAV]
- 阿兰·达瓦卓玛《A-Lan阿兰唯美歌姬》2CD[DTS-WAV]
- 【小提琴】陈立新《思乡曲》2004[FLAC+CUE]
- 《战地》新作明年初大规模测试!EA已内部测试一年
- 《GTAOL》PC版时隔多年更新反作弊!小助手宣布跑路