flex 兼容性问题
来源:8-14 实战项目:设置模块切换按钮交互

慕村8337265
2021-09-25
老师你好,我用Flex做布局时,发现PC端与移动端效果不一样,比如flex中的column-gap就没有效果。网上查询是说移动端对于Flex兼容性不是太好,假如想兼容多个浏览器,可以采用优雅降级的方式来使用,推荐一个scss的sass-flex-mixin,目前不知道这个如何使用,想请老师帮忙。或有什么好的解决方案呢?
1回答
-
你好,根据这个网站查询了一下兼容性,兼容性还是很好的,基本移动端都是支持的。
https://caniuse.com/?search=column-gap
你说的sass-flex-mixin这个很古老了,是为了兼容flex刚出来时候做的兼容处理,5年前的东西了,现代浏览器已经99%支持flex相关布局了。
你试试我的代码,看看在你说的移动端是否支持?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 400px;
height: 400px;
border: 1px black solid;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
column-gap: 10px;
row-gap: 10px;
}
.box div {
width: 100px;
height: 100px;
background: pink;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>
如果以上代码还是不支持的话,请告诉我是移动端哪个设备下的哪个浏览器。
可以了解一下 autoprefixer 插件,可以尝试把浏览器前缀添加上看是否支持。
042021-10-19
相似问题