简体   繁体   English

从 figma 中的像素到 css 中的 rem 的工作流程是什么?

[英]what is the workflow from pixel in figma to rem in css?

I am new to web developement and would like to understand the following workflow:我是 web 开发的新手,想了解以下工作流程:

  1. I design a website in figma along with font styles in PIXELS (can't use em or rem in figma)我在 figma 中设计了一个网站以及 PIXELS 中的字体 styles(在 figma 中不能使用 em 或 rem)
  2. In order to have a responsive website i want to write the css code wit REM为了有一个响应式网站,我想用 REM 编写 css 代码

QUESTION: Do I now manually convert all the px units into rem units based on the base font size in the paragraph tag?问题:我现在是否根据段落标签中的基本字体大小手动将所有 px 单位转换为 rem 单位? how is the math done here?这里的数学是怎么做的?

best regards anna最好的问候安娜

If you are looking for a quick way to compute the conversion between px and rems given a base size, you can find lots of converters online, eg https://www.ninjaunits.com/converters/pixels/pixels-rem/如果您正在寻找一种在给定基本尺寸的情况下计算 px 和 rems 之间转换的快速方法,您可以在线找到很多转换器,例如https://www.ninjaunits.com/converters/pixels/pixels-rem/

In general, try to take advantage of a preprocessor such as sass, which allows you to declare variables making your stylesheets easier to change.通常,尝试利用诸如 sass 之类的预处理器,它允许您声明变量,使您的样式表更容易更改。 For example:例如:

$font-size-base:              1.125rem !default; // Assumes the browser default, typically `16px`
$font-size-lg:                $font-size-base * 2 !default;
$font-size-md:                $font-size-base * 1.5 !default;
$font-size-sm:                $font-size-base * 0.8 !default;

Hope this helps.希望这可以帮助。

I worked with rem and em and they function ok for simple websites, but once you get into complex UIs pixel is king.我与 rem 和 em 一起工作,他们 function 可以用于简单的网站,但是一旦你进入复杂的 UI,像素就是王道。

When working with responsive media queries, I find it very unreliable when text also expands because of rem/em.在使用响应式媒体查询时,我发现当文本也因 rem/em 扩展时,它非常不可靠。 With pixels you set your default 16px for standard text and then maybe drop it to 14px in some cases when on mobile.使用像素,您可以为标准文本设置默认的 16 像素,然后在某些情况下在移动设备上可能会将其降至 14 像素。 And this is done across website, not for each and every element.这是在整个网站上完成的,而不是针对每个元素。

So, yes, there are some adjustments here and there, but not that many.所以,是的,这里和那里有一些调整,但不是那么多。 It's a bit more work at first, but it will be a huge time saver later on, because you will get 10 bugs every week with some part of the website not behaving correctly on some tablet when the user clicks a link and the text is pushed further to the right.一开始需要做更多的工作,但稍后会节省大量时间,因为当用户单击链接并推送文本时,您每周都会遇到 10 个错误,并且网站的某些部分在某些平板电脑上无法正常运行进一步向右。

Staying on pixels across the board, you have the same measurement unit in Figma, in HTML/CSS and Javascript, and things are kept simple, without any calculations needed.保持全面的像素,您在 Figma、HTML/CSS 和 Javascript 中拥有相同的测量单位,并且事情保持简单,无需任何计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM