Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我该使用 px 还是 % 开发?能使用 vh/rem 等相对单位吗? #54

Open
hakiu opened this issue Jan 14, 2024 · 7 comments
Open
Labels
good first issue Good for newcomers question Further information is requested

Comments

@hakiu
Copy link

hakiu commented Jan 14, 2024

根据readme中描述,使用autofit.js,能够自动的拉伸或者缩小,对于大屏开发来讲,的确解决了好多问题,这里有两个基础的地方不太明白:
根据设计稿进行页面开发,最外层容器的宽与高是用设计稿的像素还是百分比?还是两者兼可?
容器内部各个元素的宽高,以及padding,margin的值用像素还是百分比?css可定义的值太多了,px, rem ,vh/vw,em,这些在引用autofit.js的项目中,是可以混用,还是单纯便用px来统一开发?

@LarryZhu-dev LarryZhu-dev added good first issue Good for newcomers question Further information is requested labels Jan 15, 2024
@LarryZhu-dev
Copy link
Collaborator

很多人有这个疑惑,我这里统一说明一下:autofit.js只干了一件事,就是对最外层容器(默认是body)设置了宽高(px)和缩放(scale),你可以先新建一个空白项目来尝试理解。
在拖动浏览器窗口大小时,autofit.js 也会同时设置合适的宽高和缩放值,使body始终充满屏幕,至于body内部的元素该使用什么单位编写,完全取决于实际情况,但是 不可以使用 rem/vh/vw 等相对单位 。autofit.js 推荐使用 px 和 % ,当你需要一个固定宽高的元素,比如一个天气图标 image ,你就应该使用 px。当你需要一个需要跟随屏幕大小变化而变化的元素,比如常见大屏左右两侧的盒子,你就需要使用 %。

@LarryZhu-dev LarryZhu-dev changed the title 请教下作者两个基础的问题 我该使用 px 还是 % 开发?能使用 vh/rem 等相对单位吗? Jan 17, 2024
@ezewu
Copy link

ezewu commented Jul 12, 2024

tailwindcss 这些也是用不了?

@LarryZhu-dev
Copy link
Collaborator

tailwindcss 这些也是用不了?

可以用的

@ezewu
Copy link

ezewu commented Jul 12, 2024

我刚试了下,不行tailwindcss 是rem

@edk24
Copy link

edk24 commented Nov 4, 2024

我刚试了下,不行tailwindcss 是rem

tailwindcss 可以配置单位的, 也可以临时用 w-[200px] 的写法

@dashlab-pro
Copy link

rem也可以固定,vh,vw固定不了

@LarryZhu-dev
Copy link
Collaborator

rem也可以固定,vh,vw固定不了

rem 、 vh\vw 和 scale 一起使用 理论上会 造成双倍适配,不建议使用相对单位哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants