<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Caio Marcellus Cabral</title>
    <description>The latest articles on DEV Community by Caio Marcellus Cabral (@marcelluscaio).</description>
    <link>https://dev.to/marcelluscaio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1010792%2Fcb42c45f-5902-4b10-9c50-1d5ac9ba6b52.jpeg</url>
      <title>DEV Community: Caio Marcellus Cabral</title>
      <link>https://dev.to/marcelluscaio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcelluscaio"/>
    <language>en</language>
    <item>
      <title>Dynamic components – is it worth it?</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Tue, 06 Feb 2024 23:54:21 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/dynamic-components-is-it-worth-it-28m5</link>
      <guid>https://dev.to/marcelluscaio/dynamic-components-is-it-worth-it-28m5</guid>
      <description>&lt;h2&gt;
  
  
  A wild problem appears
&lt;/h2&gt;

&lt;p&gt;During a project I stumbled over a problem – like we always do, right?&lt;/p&gt;

&lt;p&gt;I had a component in Astro that returned an anchor tag. At one point, I needed that same UI inside of a form. That is, I needed a submit button. How could I create a component that could be two different tags?&lt;/p&gt;

&lt;p&gt;I obsessed over this, nerded-out over it, and managed to solve the problem.&lt;/p&gt;

&lt;p&gt;For that specific use case, I discovered – spoiler alert – that it was not the best approach. But I learned one or two things about TypeScript along the way, and here I am to share them with you. &lt;br&gt;
Follow me down this rabbit hole, and let’s explore the structure of components.&lt;/p&gt;

&lt;p&gt;I am going to use Astro in all of the examples, there could be some syntax differences when applying these techniques in other frameworks. But what is important here is the mental model over the syntax.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a component, anyway?
&lt;/h2&gt;

&lt;p&gt;When working with Astro, React or any other web development framework I know of, you will want to use components. Components are reusable structures that contain all the information for that specific element, like its logic and its styling.&lt;/p&gt;

&lt;p&gt;For example, without using a component structure we would need something like this to create a container:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;90%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;80rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="py"&gt;margin-inline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we have a class called container. A developer would need to add that class to every element they wanted to be a container. &lt;br&gt;
That is prone to mistakes, a.k.a. the human-factor. &lt;br&gt;
We don’t want that, right?&lt;/p&gt;

&lt;p&gt;One way of solving that is creating a component. This example would be inside of a Container.astro file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;div class="container"&amp;gt;&amp;lt;slot&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;style&amp;gt;
.container{
width: min(90%, 80rem);
margin-inline: auto;
}
&amp;lt;/style&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That is great, all we need is in the same place, and any developer would just grab that Container and wrap everything inside of it.&lt;/p&gt;

&lt;p&gt;But… what if we wanted the tag to be different? Now we don’t want a div, we actually need a section, for example.&lt;/p&gt;

&lt;p&gt;Well, of course you could always add the div within that other tag. But let’s try and make our container component more flexible.&lt;br&gt;
All we need to do is create a prop for the tag, and pass that to a variable. Notice that the variable must be capitalized.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
type Props = {
tag = “div” | “section” | “main”;
}
const {tag} = Astro.props;
const TagName = tag;
---
&amp;lt;TagName class="container"&amp;gt;&amp;lt;slot&amp;gt;&amp;lt;/ TagName &amp;gt;
&amp;lt;style&amp;gt;
.container{
width: min(90%, 80rem);
margin-inline: auto;
}
&amp;lt;/style&amp;gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that’s all! Our container now can be called as a div, as a section, or as the main tag. Now you can create projects with better HTML Semantics.&lt;/p&gt;

&lt;p&gt;Let’s dive into another example. We re going to create a title component. The challenge here is allowing the user to declare the heading level: h1, h2, h3, etc.&lt;/p&gt;

&lt;p&gt;In our Title.astro file we have:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
type Props = {
tag: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
};
const {tag} = Astro.props;
const TagName = tag;
---
&amp;lt;TagName class="title"&amp;gt;&amp;lt;slot&amp;gt;&amp;lt;/TagName &amp;gt;

&amp;lt;style&amp;gt;
.title {
margin-block-end: 0.75em;
}
&amp;lt;/style&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that’s all! We have a Title component that can be of any heading level. But right now it is not very flexible style-wise. It can only have one class, and it doesn’t change, it doesn’t matter if it is an h1 or an h4.&lt;/p&gt;

&lt;p&gt;One approach for that would be passing props that would broaden our styling possibilities.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
type Props = {
tag: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
size?: “big” | “small”;
align?: “center” | “left”; 
};
const {tag, size="small", align="center"} = Astro.props;
const TagName = tag;
---
&amp;lt;TagName class:list={[
"title",
size,
align
]} &amp;gt;
&amp;lt;slot&amp;gt; 
&amp;lt;/TagName&amp;gt;

&amp;lt;style&amp;gt;
.title {
margin-block-end: 0.75em;
}

.small{
font-size: 1.25rem
}

.big{
font-size: 2rem
}

.center{
text-align: center
}

.left{
text-align: left
}

&amp;lt;/style&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is awesome and gives us many possibilities, but what if we want to add extra flexibility to that component? What if we want to allow classes to be passed to it, that can extend the core styling of the component? Let’s say one specific heading needs to be red, and another one needs to be underlined. We don’t want to add props for all those possibilities, right?&lt;/p&gt;

&lt;p&gt;Well, we can allow that by adding a classList prop, that will add external classes to that instance of our component.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
type Props = {
tag: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
size?: "big" | "small";
align?: "center" | "left"; 
classList?: string[];
};
const {tag, size="small", align="center", classList=[]} = Astro.props;
const TagName = tag;
---
&amp;lt;TagName class:list={[
"title",
size,
align,
…classList
]} &amp;gt;
&amp;lt;slot&amp;gt; 
&amp;lt;/TagName &amp;gt;

&amp;lt;style&amp;gt;
(...)
&amp;lt;/style&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That solves our problems style-wise, but what if we needed to add an id, or an ARIA attribute? We would get an error. &lt;/p&gt;

&lt;p&gt;To deal with that we can use rest parameters in our props, and an index signature in our type.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
type Props = {
    tag: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
    size?: "big" | "small";
    align?: "center" | "left";
    classList?: string[];
    [index: string]: string | string[];
};

const {
    tag,
    size = "small",
    align = "center",
    classList = [],
    ...rest
} = Astro.props;
const TagName = tag;
---

&amp;lt;TagName
    class:list={["title", size, align, ...classList]}
    {...rest}
&amp;gt;
    &amp;lt;slot /&amp;gt;
&amp;lt;/TagName&amp;gt;

&amp;lt;style&amp;gt;
    (...)
&amp;lt;/style&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note that we need to pass &lt;code&gt;[index: string]: string | string[]&lt;/code&gt; in our type. That allows us to use any string as a prop. We have to add all the types we have to it, otherwise it will make that key invalid. Here in this example, if we had &lt;code&gt;[index: string]: string&lt;/code&gt; our &lt;code&gt;classList&lt;/code&gt; would be invalid, because it is an array of strings, not a single string.  &lt;/p&gt;

&lt;p&gt;We must also use the rest parameter in the props destructuring, as seen in &lt;code&gt;...rest&lt;/code&gt; in our example. What that is doing is grabbing all of the elements in the destructuring assignment that were not declared before. &lt;/p&gt;

&lt;p&gt;After doing that we need to spread our rest parameters in our attributes, as seen in &lt;code&gt;...rest&lt;/code&gt; inside of the TagName element.&lt;/p&gt;

&lt;p&gt;This will allow us to pass any attribute down to the component. &lt;/p&gt;

&lt;p&gt;That is great, right? &lt;/p&gt;

&lt;p&gt;Right????&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m4f1qmnvn14bdwgmlf8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m4f1qmnvn14bdwgmlf8.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not really. That way we can pass literally any value to the component, even invalid ones, like passing an inexistent value. &lt;br&gt;
Luckily, Astro has some types that can helps us achieve flexibility while maintaining code safety: HTMLTag and Polymorphic.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
import type { HTMLTag, Polymorphic } from "astro/types";

type TagType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";

type Props&amp;lt;TagName extends HTMLTag&amp;gt; = {
    size?: "big" | "small";
    align?: "center" | "left";
    classList?: string[];
} &amp;amp; Polymorphic&amp;lt;{ as: TagName &amp;amp; TagType }&amp;gt;;

const {
    as: Tag,
    size = "small",
    align = "center",
    classList = [],
    ...rest
} = Astro.props;
---

&amp;lt;Tag
    class:list={["title", size, align, ...classList]}
    {...rest}
&amp;gt;
    &amp;lt;slot /&amp;gt;
&amp;lt;/Tag&amp;gt;

&amp;lt;style&amp;gt;
    (...)
&amp;lt;/style&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we are taking advantage of Astro’s Polymorphic type, that has the "as" key. "as" gets the Generic type we defined in our Props type (&lt;code&gt;TagName&lt;/code&gt;), which extends HTMLTag, that is, it needs to be an existing HTMLTag. I then added the TagType using the intersection operator (&lt;code&gt;{ as: TagName &amp;amp; TagType }&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhlj3xkdsbcxs45amr44v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhlj3xkdsbcxs45amr44v.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The truth is, we didn’t need the HTMLTag type, since our TagType is already a group of HTML Tags. But it didn't hurt using it. &lt;/p&gt;

&lt;p&gt;Notice the syntax for declaring a variable while destructuring: declaring &lt;code&gt;{a: Tag} = Astro.props&lt;/code&gt; is the same as declaring &lt;code&gt;{a} = Astro.props&lt;/code&gt;, and then setting &lt;code&gt;const Tag = a&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With this code structure, we are not allowed to pass an invalid attribute to our component anymore. Hooray!&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it all began
&lt;/h2&gt;

&lt;p&gt;Now we finally get to the problem I originally had. When dealing with our Title component, our problems were easier. All heading levels share the same attributes, while an anchor tag and a button tag don’t!&lt;/p&gt;

&lt;p&gt;I needed to create a component that could be an anchor or a button, and when the anchor option was chosen, the type attribute should not be available, as well as the href attribute shouldn’t be available to a button.&lt;/p&gt;

&lt;p&gt;This is what I came up with before getting to know the Polymorphic type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
type Tag = "a" | "button";

type AnchorProps = {
    href: string;
};

type ButtonProps = {
    type?: "submit" | "button" | "reset";
};

type Props&amp;lt;TagGeneric extends Tag&amp;gt; = {
    tag: TagGeneric;
    variant?: "primary" | "secondary";
    classList?: string[];
    [index: string]: string | string[];
} &amp;amp; (TagGeneric extends "a" ? AnchorProps : ButtonProps);

const {
    tag,
    variant = "primary",
    classList = [],
    href,
    type = "button",
    ...rest
} = Astro.props;

const Tag = tag;

const baseAttributes = {
    classes: ["title", variant, ...classList],
    ...rest,
};

const anchorAttributes = {
    href: href,
};

const buttonAttributes = {
    type: type,
};

const attributeBasedOnTag = tag === "a" ? anchorAttributes : buttonAttributes;

const allAttributes = { ...baseAttributes, ...attributeBasedOnTag };

const { classes, ...attributes } = allAttributes;---

&amp;lt;Tag
    class:list={[classes]}
    {...attributes}
&amp;gt;
    &amp;lt;slot /&amp;gt;
&amp;lt;/Tag&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What is happening here?&lt;/p&gt;

&lt;p&gt;I define the type Tag, the AnchorProps and the ButtonProps. Then we have the type for the SharedProps. This structure is already familiar to you based on what we’ve seen up to this point. &lt;/p&gt;

&lt;p&gt;What is new here is the conditional structure for types. We are comparing our generic (&lt;code&gt;TagGeneric&lt;/code&gt;), which is defined when the prop tag is passed to the component, and we are extending our props based on that. If it equals “a” - in TypeScript: if it extends “a” - we apply our AnchorProps. Otherwise we apply our ButtonProps.&lt;/p&gt;

&lt;p&gt;This is great, but with this structure we still can have inexistent attributes being passed, because of our wildcard &lt;code&gt;[index: string]: string&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Using the Polymorphic type, we can avoid that kind of problem:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

---
import type { Polymorphic } from "astro/types";

type Tag = "a" | "button";

type Props&amp;lt;TagGeneric extends Tag&amp;gt; = {
    tag: TagGeneric;
    variant?: "primary" | "secondary";
    classList?: string[];
} &amp;amp; Polymorphic&amp;lt;{ as: TagGeneric }&amp;gt;;

const {
    tag: Tag,
    variant = "primary",
    classList = [],
    href,
    type = "button",
    ...rest
} = Astro.props;

const baseAttributes = {
    classes: ["title", variant, ...classList],
    ...rest,
};

const anchorAttributes = {
    href: href,
};

const buttonAttributes = {
    type: type,
};

const attributeBasedOnTag = Tag === "a" ? anchorAttributes : buttonAttributes;

const allAttributes = { ...baseAttributes, ...attributeBasedOnTag };

const { classes, ...attributes } = allAttributes;
---

&amp;lt;Tag
    class:list={[classes]}
    {...attributes}
&amp;gt;
    &amp;lt;slot /&amp;gt;
&amp;lt;/Tag&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That way we can never pass an attribute that doesn’t belong in our component.&lt;/p&gt;

&lt;p&gt;Of course, since in this component I am basically sharing styles between anchor tags and buttons, I only needed to create two components: ButtonAsAnchor and ButtonAsButton, and make them share CSS classes.&lt;/p&gt;

&lt;p&gt;Sometimes the best solution is the simplest. But taking the longer way may gift us with some more tools to our utility belt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Guidelines
&lt;/h2&gt;

&lt;p&gt;Wrapping up, here are some general guidelines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Avoid props that are protected terms (e.g.: class, style);&lt;/li&gt;
&lt;li&gt;  Allow classes to be passed, so your component is extensible;&lt;/li&gt;
&lt;li&gt;  Use the rest parameter if you might need to allow other attributes in your component;&lt;/li&gt;
&lt;li&gt;  When using the rest parameter, use the index signature feature from TypeScript in your type;&lt;/li&gt;
&lt;li&gt;  Check for your framework’s implementation of Polymorphic components;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://ishadeed.com/article/styling-the-good-old-button/" rel="noopener noreferrer"&gt;https://ishadeed.com/article/styling-the-good-old-button/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://docs.astro.build/en/basics/astro-syntax/#dynamic-tags" rel="noopener noreferrer"&gt;https://docs.astro.build/en/basics/astro-syntax/#dynamic-tags&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures" rel="noopener noreferrer"&gt;https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://davidwalsh.name/destructuring-alias" rel="noopener noreferrer"&gt;https://davidwalsh.name/destructuring-alias&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://docs.astro.build/en/guides/typescript/#polymorphic-type" rel="noopener noreferrer"&gt;https://docs.astro.build/en/guides/typescript/#polymorphic-type&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>astro</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Fluid Typography</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Mon, 11 Sep 2023 15:15:13 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/fluid-typography-1mfl</link>
      <guid>https://dev.to/marcelluscaio/fluid-typography-1mfl</guid>
      <description>&lt;p&gt;&lt;em&gt;Photo by Ross Findon in Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can access this article in Portuguese &lt;a href="https://dev.to/marcelluscaio/tipografia-fluida-104n"&gt;here&lt;/a&gt;&lt;br&gt;
Você pode acessar este artigo em português &lt;a href="https://dev.to/marcelluscaio/tipografia-fluida-104n"&gt;aqui&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A promise is a debt
&lt;/h2&gt;

&lt;p&gt;A few days ago, &lt;a href="https://dev.to/marcelluscaio/using-rem-doesnt-make-your-website-responsive-heres-why-4b0e"&gt;I wrote about some typography tips&lt;/a&gt;. We discussed the importance of using the REM unit and how to make our fonts responsive using Media Queries. With that, you can already create impeccable web projects in terms of font size. But I promised to talk about making fonts responsive without using Media Queries, and a promise is a debt. So, here we go!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flly5ctf7jqgs8zjg9fy0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flly5ctf7jqgs8zjg9fy0.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The limits of Media Queries
&lt;/h2&gt;

&lt;p&gt;When we adapt font sizes using media queries, our fonts remain the same size until they reach the breakpoint, and only then they change.&lt;/p&gt;

&lt;p&gt;Open the CodePen below and adjust the screen width to see the sudden change in font size.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/XWopvde?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;a href="https://codepen.io/marcelluscaio/pen/XWopvde" rel="noopener noreferrer"&gt;Open the CodePen in another tab.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using the fluid typography technique, our font will always adjust to the screen size. For every pixel the screen increases, there will be an increment in font size.&lt;/p&gt;

&lt;p&gt;"Caio, what kind of witchcraft is this? How is that possible?"&lt;/p&gt;

&lt;p&gt;It's not witchcraft, but a powerful CSS function: clamp().&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting to know 'clamp()'
&lt;/h2&gt;

&lt;p&gt;With clamp(), we can define a minimum value, an ideal value, and a maximum value.&lt;/p&gt;

&lt;p&gt;Let's say we want our font to be 16px on a screen width of 320px and 32px on a screen width of 1920px. Our clamp() would look something like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;valor&lt;/span&gt; &lt;span class="nt"&gt;ideal&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c"&gt;/*
You noticed that we're using REM, right?
No PX for fonts, remember?
*/&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;What about the ideal value? Well, since we want our font to adapt to the screen size, we'll use one of the viewport units, VW. 100vw is the size of the screen, and 1vw is 1% of the screen width. On a 320px screen, 100vw is 320px, and 1vw equals 3.2px.&lt;/p&gt;

&lt;p&gt;Let's temporarily use the value of 5vw.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="nt"&gt;vw&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;With this, our font still has those minimum and maximum limits of 16px and 32px (based on the browser's default font), but with 5vw as the ideal value, it will always try to be 5vw in size.&lt;/p&gt;

&lt;p&gt;Let's see some examples:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;On a 300px screen: 5vw would be 15px. 15px is less than 16px - our minimum font size. In this case, the font would be 16px.&lt;/p&gt;

&lt;p&gt;On a 320px screen: 5vw would be 16px. The font used would be 16px.&lt;/p&gt;

&lt;p&gt;On a 500px screen: 5vw would be 25px. 25px is greater than 16px, and it's less than the maximum limit of 32px. So, the font used would be 25px.&lt;/p&gt;

&lt;p&gt;On a 1000px screen: 5vw would be 50px. Since this value is greater than our limit, the font used would be 32px.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See this applied in the example below:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/eYbvYyZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/marcelluscaio/pen/eYbvYyZ" rel="noopener noreferrer"&gt;Open the CodePen in another tab.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Not everything is perfect
&lt;/h3&gt;

&lt;p&gt;We have two problems here:&lt;/p&gt;

&lt;p&gt;1) Our font is growing too quickly in this example. It reached our limit at a screen width of 640px, but we wanted it to vary fluidly up to 1920px. It becomes static for 1280px! &lt;/p&gt;

&lt;p&gt;2) Using a font based solely on viewport units poses an accessibility problem. Try going back to the previous CodePen and zoom in on the screen. Users cannot zoom in on the font, which remains frozen since it's based on the screen size. You'll notice that the text in the center of the screen doesn't change in size, while the screen and font size counter in the upper-left corner increases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using VW + REM
&lt;/h2&gt;

&lt;p&gt;A technique that helps with these two problems is to define the ideal value, the one in the middle of the clamp(), not just in VW, but as a sum of VW and REM.&lt;/p&gt;

&lt;p&gt;Let's use the following values:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;8&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;vw&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;See in the example below that the font starts to grow exactly after 320px and stops just before 1920px!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/MWZpYwJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/marcelluscaio/pen/MWZpYwJ" rel="noopener noreferrer"&gt;Open the CodePen in another tab.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgq82nvo82r82fhvy5et.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgq82nvo82r82fhvy5et.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Caio, you're a genius! How did you come up with that value?"&lt;/p&gt;

&lt;p&gt;I hate to disappoint you, dear reader, but I didn't do this calculation in my head! There is a formula to calculate this ideal value, and all the explanations for that will be in one of the articles I'll leave in the references. In this example and in my daily work, I use a tool that calculates it for me.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://utopia.fyi/type/calculator" rel="noopener noreferrer"&gt;You can access this tool here.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Fluid Type Calculator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2exkk76jg2ft60qinjnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2exkk76jg2ft60qinjnl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we can define the minimum and maximum screen widths and the minimum and maximum font sizes — let's just ignore the Type Scale option for now.&lt;/p&gt;

&lt;p&gt;The tool provides the clamp() values for you. Then, just add them to your code, and you're good to go.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dealing with multiple font sizes simultaneously
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;"Caio, I've never worked on a project with just one font size!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I know, I know. The example with only one font size was to make things simple. But there's no catch 22 here. Let's apply this logic to our first example, the one with fonts using Media Queries.&lt;/p&gt;

&lt;p&gt;There, we had the following font model:&lt;/p&gt;

&lt;p&gt;Level 1 -&amp;gt; 16px to 18px;&lt;/p&gt;

&lt;p&gt;Level 2 -&amp;gt; 20px to 24px;&lt;/p&gt;

&lt;p&gt;Level 3 -&amp;gt; 25px to 32px;&lt;/p&gt;

&lt;p&gt;Level 4 -&amp;gt; 31px to 42px;&lt;/p&gt;

&lt;p&gt;Now we just need to use our calculator for each of these ranges!&lt;/p&gt;

&lt;p&gt;Previously, we had:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.125rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.625rem&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40em&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5625rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.9375rem&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we end up with this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.00rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.98rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.13vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;1.13rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.20rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.25vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;1.50rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.56rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.48rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.44vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;2.00rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;--fs-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.95rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.81rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.71vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;2.66rem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;See the example below:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/VwqpYdO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/marcelluscaio/pen/VwqpYdO" rel="noopener noreferrer"&gt;Open the CodePen in another tab.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Ok, what about the Type Scale Thing?
&lt;/h2&gt;

&lt;p&gt;As developers, we often don't take part in the font size selection process. Designers usually lead that decision. "And how do they do that?", you might be wondering.&lt;/p&gt;

&lt;p&gt;That's a science of its own. There are different systems: the 4-point grid, the 8-point grid, Google's Material Design, and many others. None of these systems can do without the trained eyes of design professionals: systems are not magic and often require adaptations.&lt;/p&gt;

&lt;p&gt;One of these systems is modular scale typography. In this system, we start with a font size and increase or decrease it based on a multiplication factor. For example, let's say our smallest font is 10px, and the multiplication factor is 2. Our font system could have the following values: 10px, 20px, 40px, 80px, and so on. This example is exaggerated for didactic purposes, of course.&lt;/p&gt;

&lt;p&gt;This methodology adds objectivity to font size selection and helps make our typography hierarchy more consistent.&lt;/p&gt;

&lt;p&gt;The Type Scale field in our calculator helps generate fonts using this type of methodology. Let's say I have a project with 4 font levels (4 different sizes), and the smallest font should be 14px on mobile and 20px on monitors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9dkwqsii1rncstt1uh46.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9dkwqsii1rncstt1uh46.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I'm applying a growth rate of 1.25 on 320px screens while applying a growth rate of 1.414 on 1900px screens. The result is as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtl9wqlpbpl5g383h2xu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtl9wqlpbpl5g383h2xu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that font sizes grow much faster on the 1900px screen because we used a higher rate. I invite you to read the excellent articles on modular typography scales that will be in the references of this article to better understand when to choose which rate for your scale. I also encourage you to generate and test different scales and compare the results. What happens when the scale rate is higher on larger screens than on smaller screens? What happens when the rate is the same? And when it's smaller?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We've learned how to apply the fluid typography technique using CSS. Fluid typography is an elegant solution that brings visual integrity to your project on various screens.&lt;/p&gt;

&lt;p&gt;Always remember that accessibility is a priority. To ensure your website is accessible, always test it with a 200% zoom.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Kevin Powell - Simple solutions to responsive typography&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=wARbgs5Fmuw" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=wARbgs5Fmuw&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Modern Fluid Typography Using CSS Clamp&lt;br&gt;
&lt;a href="https://www.smashingmagazine.com/2022/01/modern-fluid-typography-css-clamp/" rel="noopener noreferrer"&gt;https://www.smashingmagazine.com/2022/01/modern-fluid-typography-css-clamp/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Generating &lt;code&gt;font-size&lt;/code&gt; CSS Rules and Creating a Fluid Type Scale&lt;br&gt;
&lt;a href="https://moderncss.dev/generating-font-size-css-rules-and-creating-a-fluid-type-scale/" rel="noopener noreferrer"&gt;https://moderncss.dev/generating-font-size-css-rules-and-creating-a-fluid-type-scale/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Responsive Type and Zoom&lt;br&gt;
&lt;a href="https://adrianroselli.com/2019/12/responsive-type-and-zoom.html" rel="noopener noreferrer"&gt;https://adrianroselli.com/2019/12/responsive-type-and-zoom.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resize text&lt;br&gt;
&lt;a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html" rel="noopener noreferrer"&gt;https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Should I change the default HTML font-size to 62.5%?&lt;br&gt;
&lt;a href="https://fedmentor.dev/posts/rem-html-font-size-hack/" rel="noopener noreferrer"&gt;https://fedmentor.dev/posts/rem-html-font-size-hack/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4-Point Grid System for more consistent interface design&lt;br&gt;
&lt;a href="https://medium.com/@aratidube12lns/4-point-grid-system-for-more-consistent-interface-design-efea81dea3f3" rel="noopener noreferrer"&gt;https://medium.com/@aratidube12lns/4-point-grid-system-for-more-consistent-interface-design-efea81dea3f3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More Meaningful Typography&lt;br&gt;
&lt;a href="https://alistapart.com/article/more-meaningful-typography/" rel="noopener noreferrer"&gt;https://alistapart.com/article/more-meaningful-typography/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Um guia prático para criar um tipo de escala modular para suas interfaces&lt;br&gt;
&lt;a href="https://www.ux-republic.com/pt/guia-pr%C3%A1tico-para-criar-um-tipo-de-escala-modular-para-suas-interfaces/" rel="noopener noreferrer"&gt;https://www.ux-republic.com/pt/guia-pr%C3%A1tico-para-criar-um-tipo-de-escala-modular-para-suas-interfaces/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Tipografia fluida</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Mon, 11 Sep 2023 15:14:43 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/tipografia-fluida-104n</link>
      <guid>https://dev.to/marcelluscaio/tipografia-fluida-104n</guid>
      <description>&lt;p&gt;&lt;em&gt;Foto por Ross Findon no Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can access this article in English &lt;a href="https://dev.to/marcelluscaio/fluid-typography-1mfl"&gt;here&lt;/a&gt;&lt;br&gt;
Você pode acessar este artigo em inglês &lt;a href="https://dev.to/marcelluscaio/fluid-typography-1mfl"&gt;aqui&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Promessa é dívida
&lt;/h2&gt;

&lt;p&gt;Alguns dias atrás &lt;a href="https://dev.to/marcelluscaio/usar-rem-nao-torna-seu-site-responsivo-entenda-por-que-559e"&gt;escrevi sobre algumas dicas de tipografia&lt;/a&gt;. Vimos a importância de usarmos a unidade REM, e como tornar responsivas nossas fontes usando Media Queries. Com isso você já consegue fazer projetos para a web impecáveis do ponto de vista do tamanho de fontes. Mas eu prometi que iria falar sobre como tornar as fontes responsivas sem usar Media Queries, e promessa é dívida. Vamos lá!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jTog7axo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hplee4zelqbexw0m8xef.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jTog7axo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hplee4zelqbexw0m8xef.jpg" alt="Image description" width="484" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Os limites das Media Queries
&lt;/h2&gt;

&lt;p&gt;Quando adaptamos o tamanho de fontes usando media queries, nossas fontes ficam com o mesmo tamanho até atingir o ponto de quebra, e só aí mudam. &lt;/p&gt;

&lt;p&gt;Abra o codepen abaixo e mexa na largura da tela para ver a mudança repentina no tamanho da fonte.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/XWopvde?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;a href="https://codepen.io/marcelluscaio/pen/XWopvde"&gt;Abra o codepen em outra aba.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Usando a  técnica de tipografia fluida, nossa fonte vai sempre se ajustar ao tamanho da tela. A cada pixel que a tela aumenta, há um incremento nas fontes.&lt;/p&gt;

&lt;p&gt;“Caio, que bruxaria é essa? Como isso é possível?”&lt;/p&gt;

&lt;p&gt;Não é bruxaria, mas uma função poderosíssima do CSS: o clamp().&lt;/p&gt;
&lt;h2&gt;
  
  
  Conhecendo o clamp()
&lt;/h2&gt;

&lt;p&gt;Com o clamp a gente pode definir um valor mínimo, um valor ideal, e um valor máximo. &lt;/p&gt;

&lt;p&gt;Digamos que queremos que nossa fonte seja 16px em uma largura de tela de 320px, e que seja de 32px numa largura de tela de 1920px. Nosso clamp ficaria mais ou menos assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;valor&lt;/span&gt; &lt;span class="nt"&gt;ideal&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c"&gt;/*
Notou que estamos usando REM, certo? 
Nada de PX para fontes, lembra?
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E para o valor ideal? Bem, como a gente quer que nossa fonte se adapte ao tamanho da tela, vamos aplicar uma das viewport units, o VW. 100vw é o tamanho da tela. 1vw é 1% da largura da tela. Numa tela de 320px, 100vw são 320px, 1vw é igual a 3.2px.&lt;/p&gt;

&lt;p&gt;Vamos usar temporariamente o valor de 5vw.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="nt"&gt;vw&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Com isso, nossa fonte ainda tem aqueles limites mínimo e máximo de 16px e 32px (pela fonte padrão do navegador), mas com o 5vw como valor ideal ela vai sempre tentar ter 5vw de tamanho.&lt;/p&gt;

&lt;p&gt;Vejamos alguns exemplos:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Em uma tela de 300px: 5vw seria 15px. 15px é menor que 16px – nossa fonte mínima. Nesse caso, a fonte seria 16px.&lt;/p&gt;

&lt;p&gt;Em uma tela de 320px: 5vw seria 16px. A fonte usada seria 16px.&lt;/p&gt;

&lt;p&gt;Em uma tela de 500px: 5vw seria 25px. 25px é maior que 16px, e é menor que o limite máximo de 32px. A fonte usada seria 25px.&lt;/p&gt;

&lt;p&gt;Em uma tela de 1000px: 5vw seria 50px. Como esse valor é maior que o nosso limite, a fonte utilizada seria de 32px.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Veja esse exemplo aplicado abaixo:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/eYbvYyZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/marcelluscaio/pen/eYbvYyZ"&gt;Abra o codepen em outra aba.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Nem tudo são flores
&lt;/h3&gt;

&lt;p&gt;Temos dois problema aqui: &lt;/p&gt;

&lt;p&gt;1)  Nossa fonte está crescendo rápido demais nesse exemplo. Ela atingiu o nosso limite em 640px de largura de tela, e nós queríamos que ela variasse de forma fluida até 1920px. Ela ficaria estática por 1280px! &lt;/p&gt;

&lt;p&gt;2)  Usar uma fonte baseada somente em unidades de viewport traz um problema para a acessibilidade. Experimente voltar no codepen anterior, e dê zoom na tela. A pessoa usuária não consegue dar zoom na fonte, que fica congelada já que está baseada no tamanho da tela. Veja que o texto no centro da tela não altera de tamanho, enquando o contador de tamanho de tela e fonte no canto superior esquerdo aumenta. &lt;/p&gt;

&lt;h2&gt;
  
  
  Usando VW + REM
&lt;/h2&gt;

&lt;p&gt;Uma técnica que ajuda com esses dois problema é definir o valor ideal, do meio do clamp, não apenas em vw, mas em um cálculo da soma de vw com rem.&lt;/p&gt;

&lt;p&gt;Vamos usar os seguintes valores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;clamp&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;8&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="nt"&gt;vw&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;rem&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Veja no exemplo abaixo que a fonte começa a crescer exatamente depois de 320px, e para logo antes de 1920px!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/MWZpYwJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/marcelluscaio/pen/MWZpYwJ"&gt;Abra o codepen em outra aba.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QG_HJfgd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnd9qdhaa3mecrjtb28n.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QG_HJfgd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnd9qdhaa3mecrjtb28n.gif" alt="Image description" width="640" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;“Caio você é um gênio! Como você chegou nesse valor?”&lt;/p&gt;

&lt;p&gt;Odeio desapontar você, querida pessoa leitora, mas eu não fiz essa conta de cabeça! Existe uma fórmula para calcular esse valor ideal, e toda a explicação disso vai estar em um dos artigos que vou deixar nas referências. Nesse exemplo e no dia-a-dia eu uso uma ferramenta que calcula isso pra mim.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://utopia.fyi/type/calculator"&gt;Você pode acessar essa ferramenta aqui.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  O Fluid Type Calculator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--irqJwgx6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi7mm8mskhoe21dw802x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--irqJwgx6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi7mm8mskhoe21dw802x.png" alt="Image description" width="502" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aqui a gente pode definir a largura mínima e máxima de tela e o tamanho mínimo e máximo de fonte - ignore por hora a opção de Type Scale (Escala de tipografia).&lt;/p&gt;

&lt;p&gt;A ferramenta já dá os valores em clamp para você. Daí é só colocar no seu código e correr pro abraço.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lidando com mais de um tamanho ao mesmo tempo
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;“Caio, eu nunca trabalhei em um projeto com um tamanho de fonte só!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eu sei, eu sei. O exemplo com só um tamanho de fonte era pra facilitar o entendimento. Vamos aplicar essa lógica para aquele nosso primeiro exemplo, das fontes com Media Queries?&lt;/p&gt;

&lt;p&gt;Lá tínhamos o seguinte modelo de fonte:&lt;/p&gt;

&lt;p&gt;Nível 1 -&amp;gt; 16px até 18px;&lt;/p&gt;

&lt;p&gt;Nível 2 -&amp;gt; 20px até 24px;&lt;/p&gt;

&lt;p&gt;Nível 3 -&amp;gt; 25px até 32px;&lt;/p&gt;

&lt;p&gt;Nível 4 -&amp;gt; 31px até 42px;&lt;/p&gt;

&lt;p&gt;Daí é só a gente entrar naquela nossa calculadora e fazer cada um desses intervalos!&lt;/p&gt;

&lt;p&gt;Antes tínhamos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.125rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.625rem&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40em&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5625rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.9375rem&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;O resultado é esse daqui:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.00rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.98rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.13vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;1.13rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.20rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.25vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;1.50rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.56rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.48rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.44vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;2.00rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;--fs-4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.95rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.81rem&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="m"&gt;0.71vw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;2.66rem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Veja no exemplo abaixo:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/VwqpYdO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/marcelluscaio/pen/VwqpYdO"&gt;Abra o codepen em outra aba.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  E aquele lance de Type scale?
&lt;/h2&gt;

&lt;p&gt;Nós, como desenvolvedores, muitas vezes não participamos do processo de escolha do tamanho de fontes. Designers costumam estar à frente dessa decisão. “E como eles chegam naqueles valores?”, você pode estar se perguntando.&lt;/p&gt;

&lt;p&gt;Isso é uma ciência à parte. Há diferentes sistemas: o 4-point grid, o 8-point grid, o Material Design do Google, e muitos outros. E o uso de nenhum desses sistemas prescinde do olhar treinado dos profissionais de design: sistemas não são mágica, e muitas vezes necessitam de adaptações.&lt;/p&gt;

&lt;p&gt;Um desses sistemas é a tipografia com escala modular. Nesse sistema, nós partimos de um tamanho de fonte, e aumentamos ou diminuímos a partir de um fator de multiplicação. Por exemplo, digamos que nossa menor fonte seja 10px, e que o fator de multiplicação seja 2. Nosso sistema de fontes poderia ter os seguintes valores: 10px, 20px, 40px, 80px, etc. Esse exemplo é um exagero, apenas com fins didáticos, claro.&lt;/p&gt;

&lt;p&gt;Essa metodologia imprime uma maior objetividade na escolha dos tamanhos de fonte, e ajuda a hierarquia da nossa tipografia a ser mais consistente. &lt;/p&gt;

&lt;p&gt;O campo Type Scale da nossa calculadora ajuda a gerar fontes usando esse tipo de metodologia. Digamos que eu tenha um projeto com 4 níveis de fonte (4 tamanhos diferentes), e o menor deles deve ser 14px em celulares e 20px em monitores.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6enwbWue--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu3vxyobcl6yq7zo223j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6enwbWue--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu3vxyobcl6yq7zo223j.png" alt="Image description" width="780" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aqui estou aplicando uma taxa de crescimento de 1.25 em telas de 320px, enquanto aplico uma taxa de crescimento de 1.414 em telas de 1900px. O resultado é o seguinte:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3j1oSEub--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ogilib8u6vn0yeoqe2a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3j1oSEub--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ogilib8u6vn0yeoqe2a.png" alt="Image description" width="780" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note que os tamanhos de fonte crescem bem mais rápido na tela de 1900px, porque a taxa que usamos é maior. Convido você a ler os excelentes artigos sobre escalas modulares em tipografia que estarão nas referências deste artigo para entender melhor em que situações escolher qual taxa para a sua escala. Encorajo ainda a gerar e testar diferentes escalas e comparar o resultado. O que acontece quando a a taxa da escala em telas grandes é maior que em telas pequenas? O que acontece quando a taxa é a mesma? E quando é menor?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Aprendemos como aplicar a técnica de tipografia fluida usando CSS. A tipografia fluida é uma solução elegante que traz integridade visual para o seu projeto nas mais diversas telas. &lt;/p&gt;

&lt;p&gt;É sempre importante lembrar que a acessibilidade é uma prioridade. Para garantir que seu site está acessível, faça sempre testes com zoom em 200%.&lt;/p&gt;

&lt;h2&gt;
  
  
  Referências
&lt;/h2&gt;

&lt;p&gt;Kevin Powell - Simple solutions to responsive typography&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=wARbgs5Fmuw"&gt;https://www.youtube.com/watch?v=wARbgs5Fmuw&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Modern Fluid Typography Using CSS Clamp&lt;br&gt;
&lt;a href="https://www.smashingmagazine.com/2022/01/modern-fluid-typography-css-clamp/"&gt;https://www.smashingmagazine.com/2022/01/modern-fluid-typography-css-clamp/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Generating &lt;code&gt;font-size&lt;/code&gt; CSS Rules and Creating a Fluid Type Scale&lt;br&gt;
&lt;a href="https://moderncss.dev/generating-font-size-css-rules-and-creating-a-fluid-type-scale/"&gt;https://moderncss.dev/generating-font-size-css-rules-and-creating-a-fluid-type-scale/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Responsive Type and Zoom&lt;br&gt;
&lt;a href="https://adrianroselli.com/2019/12/responsive-type-and-zoom.html"&gt;https://adrianroselli.com/2019/12/responsive-type-and-zoom.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resize text&lt;br&gt;
&lt;a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html"&gt;https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Should I change the default HTML font-size to 62.5%?&lt;br&gt;
&lt;a href="https://fedmentor.dev/posts/rem-html-font-size-hack/"&gt;https://fedmentor.dev/posts/rem-html-font-size-hack/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4-Point Grid System for more consistent interface design&lt;br&gt;
&lt;a href="https://medium.com/@aratidube12lns/4-point-grid-system-for-more-consistent-interface-design-efea81dea3f3"&gt;https://medium.com/@aratidube12lns/4-point-grid-system-for-more-consistent-interface-design-efea81dea3f3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More Meaningful Typography&lt;br&gt;
&lt;a href="https://alistapart.com/article/more-meaningful-typography/"&gt;https://alistapart.com/article/more-meaningful-typography/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Um guia prático para criar um tipo de escala modular para suas interfaces&lt;br&gt;
&lt;a href="https://www.ux-republic.com/pt/guia-pr%C3%A1tico-para-criar-um-tipo-de-escala-modular-para-suas-interfaces/"&gt;https://www.ux-republic.com/pt/guia-pr%C3%A1tico-para-criar-um-tipo-de-escala-modular-para-suas-interfaces/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>typography</category>
      <category>webdev</category>
      <category>braziliandevs</category>
    </item>
    <item>
      <title>Using REM Doesn't Make Your Website Responsive - Here's Why</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Wed, 30 Aug 2023 16:14:15 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/using-rem-doesnt-make-your-website-responsive-heres-why-4b0e</link>
      <guid>https://dev.to/marcelluscaio/using-rem-doesnt-make-your-website-responsive-heres-why-4b0e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;You can access this article in portuguese &lt;a href="https://dev.to/marcelluscaio/usar-rem-nao-torna-seu-site-responsivo-entenda-por-que-559e"&gt;here&lt;/a&gt;&lt;br&gt;
Você pode acessar este artigo em português &lt;a href="https://dev.to/marcelluscaio/usar-rem-nao-torna-seu-site-responsivo-entenda-por-que-559e"&gt;aqui&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I love being part of technology communities. Besides learning a lot from people with more experience than me, it allows me to share some of what I've learned with other developers. In addition to that, while trying to answer some of the questions that come up, I am compelled to do a lot of research, which leads me to deeply understand some techniques that I knew to work but didn't know why.&lt;/p&gt;

&lt;p&gt;Recently, in Alura’s Discord community, I came across a question from a user who wanted to solve a layout problem on smaller screens. Her font sizes were too big, and layout would break. One of the Discord users advised her to change the font size measurements to REM. &lt;/p&gt;

&lt;p&gt;And this isn't the first time I've seen this misconception.&lt;/p&gt;

&lt;p&gt;I've worked on a project where an experienced developer used a library that converted all measurements originally in pixels to REM, believing that this contributed to the site's responsiveness.&lt;/p&gt;

&lt;p&gt;Knowing that typography is a topic that gets so little attention from developers (yeah, I am talking to you, who only declares font-size and font-family and completely ignores font-weight and line-height), I decided to write this article to talk about best practices when working with text in web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Organize your typography information in one place
&lt;/h2&gt;

&lt;p&gt;The first thing I see very often is the repetition of font size declarations. On the header, the developer declares:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.cabecalho&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Moments later, they need to declare:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.titulo&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This works, of course. But what if there's a change in the font sizes used in the project? You'll need to go on a scavenger hunt to find all occurrences.&lt;/p&gt;

&lt;p&gt;And change them.&lt;/p&gt;

&lt;p&gt;One.&lt;/p&gt;

&lt;p&gt;By.&lt;/p&gt;

&lt;p&gt;One.&lt;/p&gt;

&lt;p&gt;Not very practical, right?&lt;/p&gt;

&lt;p&gt;There's a programming principle we can use to solve this problem: DRY (Don't Repeat Yourself). It states that if we're copying a piece of code or information, it could be isolated in a function or variable that can be called or referenced elsewhere in the code.&lt;/p&gt;

&lt;p&gt;So, we could declare our font sizes as CSS Custom Properties, aka "CSS variables":&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.cabecalho&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hero-banner&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="nc"&gt;.titulo&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.rodape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This way we reduce the chance of errors, as well as keep this information in one place, greatly improving the maintainability of our code.&lt;/p&gt;

&lt;h2&gt;
  
  
  2) Never use PX again
&lt;/h2&gt;

&lt;p&gt;In programming, it's rare being able to say something so straightforward: never do X, always do Y. Usually, there are multiple ways to achieve a goal, different techniques with pros and cons, and we need to analyze each case to determine the best approach.  And that’s the beauty of this field. I like to think that in programming there is no right way of doing anything, just not-wrong ways.&lt;/p&gt;

&lt;p&gt;But in this case, I say it without hesitation: you shouldn't use PX for your font sizes.&lt;/p&gt;

&lt;p&gt;Let me tell you a story: Alberto can't read very small letters. They seem to shuffle in front of him, making it difficult for Alberto to do web research for school. This changed when Alberto discovered he could change the default font size in his browser! The default font size in browsers is 16px, but Alberto can change it to 24px, which makes his life much better.&lt;/p&gt;

&lt;p&gt;The problem is that the developer who created one of the sites Alberto wants to access used pixels (PX) for all fonts. And 18px will always be 18px because it's an absolute measurement that doesn't adapt to user preferences. Using PX for font size made Alberto's experience less satisfactory, perhaps even preventing him from accessing that content.&lt;/p&gt;

&lt;p&gt;That's what happens when we use PX for font sizes: we ignore user preferences and impose the exact size we've chosen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhmayrmfd9ydxinqbywx9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhmayrmfd9ydxinqbywx9.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, we can overcome this problem by using the REM unit. &lt;/p&gt;

&lt;p&gt;REM is based on the browser's default font size, which is typically 16px. So, usually, 1rem is equal to 16px.&lt;/p&gt;

&lt;p&gt;"But, Caio, I need to use 18px in my project, not 16px." .&lt;/p&gt;

&lt;p&gt;Easy-peasy: in the default measurement, 18px is equal to 1.125rem. We just need to divide the value we want by 16.&lt;/p&gt;

&lt;p&gt;Here's a list of some frequently used values:&lt;br&gt;
.25rem = 4px;&lt;br&gt;
.5rem = 8px;&lt;br&gt;
.75rem = 12px;&lt;br&gt;
1.5rem = 24px;&lt;/p&gt;

&lt;p&gt;Notice that I said these are &lt;strong&gt;generally&lt;/strong&gt; the REM values in pixels because this conversion was done using browsers’ default values. In Alberto's case, it would be different: 1rem would be equal to 24px, and 1.125rem would be equal to 27px.&lt;/p&gt;

&lt;p&gt;So, everyone wins: those who use the default font size will have the same experience, but those who choose to change it will have their choice respected.&lt;/p&gt;

&lt;p&gt;Let's see how our declaration from item 1 would look like:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This would become:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;.75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Easy, right?&lt;/p&gt;

&lt;p&gt;One more thing: many people, finding it difficult to divide by 16, do the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;62&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;5%&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This sets the default font size to 10px, making it much easier to define values in REM. &lt;/p&gt;

&lt;p&gt;Sounds great, doesn't it?&lt;/p&gt;

&lt;p&gt;But, please, don’t do it.&lt;/p&gt;

&lt;p&gt;Doing this can confuse other developers, it is difficult to undo, and can conflict with libraries possibly used in the project. &lt;/p&gt;

&lt;p&gt;So, don't change the base font size of the browser. It might provide some comfort and convenience for you now, but it could have negative consequences for your users and project collaborators.&lt;/p&gt;
&lt;h2&gt;
  
  
  3) REM doesn't solve responsiveness
&lt;/h2&gt;

&lt;p&gt;Now that you know what REM is and how to use it, your website will be fully responsive and beautiful, right?&lt;/p&gt;

&lt;p&gt;If you've been paying close attention, you've already read the introduction to this article, and you know that's not the case. Let's understand why that is.&lt;/p&gt;

&lt;p&gt;When we talk about responsiveness, we're generally referring to a website that adapts to various screen sizes: the site should work well on smartphones, tablets, laptop screens, and ultrawide monitors.&lt;/p&gt;

&lt;p&gt;However, REM has nothing to do with screen size. 1rem will be, by default, 16px on a smartphone screen or a television. &lt;/p&gt;

&lt;p&gt;Since it doesn't care about the screen size, let's say you create a rectangle for screens of 1600px width, and you define the width of this rectangle like this: width: 100rem.&lt;/p&gt;

&lt;p&gt;You'll get a 1600px rectangle for users who use the default font size. But if a user changes the default font size to 20px, your rectangle will now be 2000px wide, causing overflow on the screen you had in mind.&lt;/p&gt;

&lt;p&gt;I created an example of this on CodePen. Since each reader will be viewing this on different screens, I replicated the scenario of using REM to adjust content to the screen size by setting the width to 100%, then subtracting 16px and adding 1rem.&lt;/p&gt;

&lt;p&gt;In this way, with the default size, everything works fine, but when the user's default size is different, our layout breaks. That's because in this context, we shouldn't use REM or PX. It's ideal to work with percentages. But delving into responsiveness is a topic for another article!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/JjwGZyv?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Or access &lt;a href="https://codepen.io/marcelluscaio/pen/JjwGZyv" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: I am deining the font size on HTML to 16px to allow us to test changing the default font size more easily. That code snippet is for didactic purposes only.&lt;/p&gt;

&lt;p&gt;On the next example, you can see that the text inside the box will sometimes fit and sometimes overflow as we play with resizing the screen and changing the default font size via the input. &lt;/p&gt;

&lt;p&gt;The behavior is erratic. &lt;/p&gt;

&lt;p&gt;The width and height of the box are set in a way that, when the content varies, the layout breaks. The conclusion is that defining our H1 font size with REM didn't help with responsiveness at all.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/eYbJjjx?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Or access &lt;a href="https://codepen.io/marcelluscaio/pen/eYbJjjx" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: I set the height of this div using height &lt;strong&gt;for didactic purposes&lt;/strong&gt;. Setting height on elements with content is a bad practice for responsiveness.&lt;/p&gt;

&lt;p&gt;"Caio, my world fell apart! How do I make the fonts in my project responsive?"&lt;/p&gt;

&lt;p&gt;The most common way to make your fonts responsive is by using them: media queries. &lt;/p&gt;

&lt;p&gt;This allows you to define that from a certain screen size—let's say, 1200px—your fonts that were 12px, 16px, and 20px will have sizes of 18px, 24px, and 32px—yes, in this blog, we preach the gospel of mobile-first.&lt;/p&gt;

&lt;p&gt;It would look something like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;.75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;75em&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.125rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Don't be scared of the EM unit in the media query. It's a good practice to declare media queries with this unit. I can talk more about that another time.&lt;/p&gt;

&lt;p&gt;As seen in the previous section, REM helps make our site accessible. Note that I said "help make accessible." Accessibility is a complex and multifaceted issue, and we need to take many steps to ensure accessibility on our site for as many people as possible. We need to pay attention to colors, keyboard navigation, screen readers, and much more. In the case of REM, we're only dealing with one aspect of it: font size.&lt;/p&gt;

&lt;p&gt;To illustrate the distinction between responsiveness and accessibility, I created this example. It includes four text cases:&lt;/p&gt;

&lt;p&gt;1) Not responsive and not accessible (doesn't change with screen size, uses PX)&lt;/p&gt;

&lt;p&gt;2) Not responsive and accessible (doesn't change with screen size, but uses REM)&lt;/p&gt;

&lt;p&gt;3) Responsive and not accessible (changes with screen size, but uses PX)&lt;/p&gt;

&lt;p&gt;4) Responsive and accessible (changes with screen size and uses REM)&lt;/p&gt;

&lt;p&gt;Change the screen width and the font size to see how the font sizes behave.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/NWeGPoq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Or access &lt;a href="https://codepen.io/marcelluscaio/pen/NWeGPoq" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With these examples, we can see that it's past time for you to replace all your PX fonts with REM, but don't fool yourself: this alone won't make your site responsive.&lt;/p&gt;

&lt;h2&gt;
  
  
  4) Define your line heights
&lt;/h2&gt;

&lt;p&gt;When you were working on school or college assignments that needed a certain number of pages, you may have been tempted to increase the line height to make the content take up more space. &lt;/p&gt;

&lt;p&gt;"Set double-spacing. Do it, no one will notice.", said the voice in your head.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4i8z7ntaelt7jp8dbrga.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4i8z7ntaelt7jp8dbrga.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The truth is, line height makes all the difference in text legibility (the correct term here would be "readability." I encourage you to look up the difference).&lt;/p&gt;

&lt;p&gt;It's very common to find projects where the font family, weight, and size are defined, but the line height is not declared. &lt;/p&gt;

&lt;p&gt;When we do this, we delegate the setting of line height to the browser, and each browser has a different default. Sounds bad, right?&lt;/p&gt;

&lt;p&gt;So, we should always explicitly declare our line height. But how do we do that? With the line-height property!&lt;/p&gt;

&lt;p&gt;We should follow the same principles as with font size: no PX!&lt;/p&gt;

&lt;p&gt;Imagine you have a font of 1rem (remember, no PX for font size), and you set the line height to 20px. What will happen if the user's default font size is 24px? That's right: the font size will become 24px, but the line height will remain locked at 20px, and the text will become cluttered.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/vYvGaGo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Or access &lt;a href="https://codepen.io/marcelluscaio/pen/vYvGaGo" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One solution would be to define the line height in REM, this was it could vary along with the font size. However, by doing that, every time we change the font size within a media query we would have to change the line height too, to maintain the scale.&lt;/p&gt;

&lt;p&gt;There's an easier way: this property accepts percentages. So, we can declare the line height as we used to in Microsoft Word: 1, 1.2, 1.5, 2.&lt;/p&gt;

&lt;p&gt;In our example, if I have a font of 1rem and a line height of 1.25, the values will generally be 16px and 20px. But if the user's default font size is 24px, the values will be 24px and 30px. This way, we always maintain the same proportion between font and line height. What's even better is that if the size of our font changes with media queries, we don't need to redeclare the line height!&lt;/p&gt;

&lt;p&gt;See this example: here we are using REM units, changing them with media queries, and defining the line height relatively to the font size.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/jOXqppY?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Or access &lt;a href="https://codepen.io/marcelluscaio/pen/jOXqppY" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we learned some typography best practices, saw how to have more control over our fonts, how to avoid code repetition, and how to make our texts more accessible and responsive.&lt;/p&gt;

&lt;p&gt;With everything we've seen here, you already know everything you need about typography to create flawless web projects. But we can always go further, right?&lt;/p&gt;

&lt;p&gt;Did you notice that I mentioned, "The &lt;strong&gt;most common&lt;/strong&gt; way to make your fonts responsive is with them: media queries."?&lt;/p&gt;

&lt;p&gt;What if I told you that you can make your font sizes vary WITHOUT USING MEDIA QUERIES???&lt;/p&gt;

&lt;p&gt;So, stay tuned, because soon there will be an article about how to implement the technique of fluid typography.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>responsiveness</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Usar REM não torna seu site responsivo – entenda por quê</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Wed, 30 Aug 2023 16:13:36 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/usar-rem-nao-torna-seu-site-responsivo-entenda-por-que-559e</link>
      <guid>https://dev.to/marcelluscaio/usar-rem-nao-torna-seu-site-responsivo-entenda-por-que-559e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;You can access this article in English &lt;a href="https://dev.to/marcelluscaio/using-rem-doesnt-make-your-website-responsive-heres-why-4b0e"&gt;here&lt;/a&gt;&lt;br&gt;
Você pode acessar este artigo em inglês &lt;a href="https://dev.to/marcelluscaio/using-rem-doesnt-make-your-website-responsive-heres-why-4b0e"&gt;aqui&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eu adoro participar de comunidades de tecnologia. Além de aprender muito com pessoas com mais experiência do que eu, eu tenho a oportunidade de dividir um pouco do que aprendi com outros desenvolvedores. Além disso, ao tentar responder algumas dúvidas que surgem, eu me obrigo a pesquisar e acabo conhecendo profundamente algumas técnicas que eu sabia que funcionavam, mas não sabia por quê.&lt;/p&gt;

&lt;p&gt;Recentemente no Discord da Alura eu esbarrei com uma dúvida de uma usuária que queria resolver um problema de layout em telas menores. As fontes dela estavam grandes demais, e o conteúdo quebrava. Um dos usuários do Discord orientou ela a mudar as medidas dos tamanhos de fonte para REM.&lt;/p&gt;

&lt;p&gt;E não é a primeira vez que vi essa confusão.&lt;/p&gt;

&lt;p&gt;Já trabalhei em um projeto em que um desenvolvedor experiente utilizava uma biblioteca que convertia todas as medidas originalmente em PX (pixel) para REM, acreditando que assim estava contribuindo com a responsividade do site.&lt;/p&gt;

&lt;p&gt;Sabendo que tipografia é um assunto que recebe tão pouco carinho dos desenvolvedores (sim, eu tô falando com você que só declara font-size e font-family, e ignora completamente font-weight e line-height), resolvi escrever este artigo para falar de algumas boas práticas ao trabalhar com texto no desenvolvimento web.&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Concentre as informações de tipografia em um único lugar
&lt;/h2&gt;

&lt;p&gt;A primeira coisa que vejo com muita frequência é a repetição da declaração de tamanho de fonte.&lt;/p&gt;

&lt;p&gt;No cabeçalho, a pessoa desenvolvedora declara:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.cabecalho&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alguns momentos depois, essa pessoa vai precisar declarar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.titulo&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Isso funciona, é claro. Mas e se houver uma mudança nos tamanhos de fonte usados no projeto? Vamos precisar fazer uma gincana para encontrar todas as ocorrências.&lt;/p&gt;

&lt;p&gt;E mudar.&lt;/p&gt;

&lt;p&gt;Uma.&lt;/p&gt;

&lt;p&gt;A.&lt;/p&gt;

&lt;p&gt;Uma.&lt;/p&gt;

&lt;p&gt;Pouco prático, né?&lt;/p&gt;

&lt;p&gt;Há um princípio na programação que podemos usar para pensar como resolver esse problema: o DRY (Don’t repeat yourself – Não se repita). Ele postula que, se estamos copiando um trecho de código ou informação, aquilo poderia ser isolado em uma função ou variável, que poderão ser chamadas ou referenciadas em outros pontos do código.&lt;/p&gt;

&lt;p&gt;Poderíamos, então, declarar nosos tamanhos de fonte como Custom Properties do CSS (Propriedades Personalizadas, vulgo “variáveis do CSS”).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.cabecalho&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hero-banner&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="nc"&gt;.titulo&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.rodape&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim, reduzimos a chance de erros, além de ter essas informações concentradas em um só lugar, aumentando em muito a manutenibilidade do nosso código.&lt;/p&gt;

&lt;h2&gt;
  
  
  2) Nunca mais use PX
&lt;/h2&gt;

&lt;p&gt;É muito raro em programação a gente poder falar algo com essa força: nunca faça X, sempre faça Y. Com frequência temos múltiplas maneiras de atingir um objetivo, técnicas diferentes com vantagens e desvantagens, e temos sempre que analisar o caso para pensar qual a melhor forma de implementar. E essa é uma das belezas desse ramo. Gosto de pensar que em programação não existe uma forma certa de fazer algo, apenas formas não-erradas.&lt;/p&gt;

&lt;p&gt;Mas nesse caso eu falo sem medo de errar: você não deveria usar PX para o tamanho das suas fontes.&lt;/p&gt;

&lt;p&gt;Deixa eu contar uma história: Alberto não consegue ler com letras muito pequenas. Elas parecem se embaralhar diante dele, ficam borradas, o que desmotivava Alberto ao fazer pesquisas na web para a escola. Isso mudou quando Alberto descobriu que poderia alterar a fonte padrão do seu navegador! A fonte padrão dos navegadores é 16px, mas Alberto consegue alterar para 24px, o que torna sua vida muito melhor.&lt;/p&gt;

&lt;p&gt;Acontece que a pessoa desenvolvedora que fez um dos sites que o Alberto quer acessar usou PX (pixels) em todas as fontes. E 18px sempre vão ser 18px, porque ele  é uma medida absoluta, ou seja, não se adapta às preferências do usuário. Usar PX no tamanho da fonte tornou a experiência do Alberto menos satisfatória, talvez até impossibilitando ele de acessar aquele conteúdo.&lt;/p&gt;

&lt;p&gt;É isso que acontece quando usamos PX no tamanho das fontes: nós estamos ignorando a preferência dos usuários e impondo o tamanho exato que nós escolhemos.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhmayrmfd9ydxinqbywx9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhmayrmfd9ydxinqbywx9.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Felizmente temos como contornar esse problema usando a unidade de medida REM.&lt;/p&gt;

&lt;p&gt;O REM se baseia no tamanho de fonte padrão do navegador. Como o padrão é de 16px, geralmente 1rem vai ser igual a 16px.&lt;/p&gt;

&lt;p&gt;“Mas, Caio, eu preciso usar 18px no meu projeto, não 16px.”.&lt;/p&gt;

&lt;p&gt;Moleza: na medida padrão, 18px é igual a 1.125rem. É só dividir o valor que você quer por 16.&lt;/p&gt;

&lt;p&gt;Segue uma listinha de alguns valores comuns:&lt;br&gt;
.25rem = 4px;&lt;br&gt;
.5rem = 8px;&lt;br&gt;
.75rem = 12px;&lt;br&gt;
1.5rem = 24px;&lt;/p&gt;

&lt;p&gt;Perceba que eu falei que esses são &lt;strong&gt;geralmente&lt;/strong&gt; os valores de REM em PX. Isso porque essa conversão foi feita usando os valores padrão do navegador. No caso do nosso amigo Alberto, isso seria diferente: 1rem seria igual a 24px, e 1.125rem seria igual a 27px.&lt;/p&gt;

&lt;p&gt;Assim, todo mundo sai ganhando: quem usa o tamanho padrão de fonte vai ter a mesma experiência, mas quem escolhe mudar, tem a sua escolha respeitada.&lt;/p&gt;

&lt;p&gt;Vejamos como ficaria a nossa declaração lá no item 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Viraria:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;.75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fácil, né?&lt;/p&gt;

&lt;p&gt;Mais uma coisa: muita gente, por achar difícil fazer a divisão por 16, faz o seguinte:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;62&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;5%&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim a fonte padrão passa a ser 10px, e fica muito mais fácil definir o valor em REM. Maravilha, né?&lt;/p&gt;

&lt;p&gt;Só que não.&lt;/p&gt;

&lt;p&gt;Fazer isso pode confundir outros desenvolvedores, é difícil de desfazer, e pode trazer conflito com bibliotecas possivelmente utilizadas no projeto.&lt;/p&gt;

&lt;p&gt;Então, não mude a fonte base do navegador. Isso pode trazer algum conforto e facilidade para você agora, mas pode trazer consequências ruins para os seus usuários, e para colaboradores do projeto.&lt;/p&gt;

&lt;h2&gt;
  
  
  3) REM não resolve responsividade
&lt;/h2&gt;

&lt;p&gt;Agora que você sabe o que é o REM e como usá-lo, seu site vai ficar todo responsivo e bonitão, né?&lt;/p&gt;

&lt;p&gt;Você, pessoa leitora atenta, leu a introdução desse artigo e já sabe que não. Vamos entender isso direito.&lt;/p&gt;

&lt;p&gt;Quando falamos de responsividade estamos geralmente falando de um site que se adapte aos diversos tamanhos de tela que existem: o site funciona sendo aberto em celulares, em tablets, em telas de laptop, e em monitores ultrawide.&lt;/p&gt;

&lt;p&gt;Acontece que o REM não tem nada a ver com tamanho de tela. 1rem vai ser, por padrão, 16px em uma tela de celular ou em uma televisão.&lt;/p&gt;

&lt;p&gt;Como ele não liga para o tamanho da sua tela, digamos que você crie um retângulo para telas de 1600px. E você define a largura desse retângulo assim: width: 100rem.&lt;/p&gt;

&lt;p&gt;Você vai conseguir um retângulo de 1600px para os usuários que usarem a fonte padrão, mas se algum usuário mudar a fonte padrão para 20px, seu retângulo passa a ter 2000px, gerando transbordamento na tela que você tinha em mente.&lt;/p&gt;

&lt;p&gt;Fiz um exemplo disso no CodePen. Como cada um dos leitores vai estar vendo isso em telas diferentes, eu reproduzi o cenário de uso de REM para ajustar conteúdo ao tamanho da tela estabelecendo a largura como 100%, daí diminuí 16px e aumentei 1rem.&lt;/p&gt;

&lt;p&gt;Dessa forma, com o tamanho padrão vai dar tudo certo, mas quando o padrão do usuário for diferente, nosso layout quebra. Isso porque nesse tipo de contexto nós não queremos usar REM, nem PX. O ideal é trabalhar com porcentagem. Mas o mergulho em responsividade fica para outro artigo!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/JjwGZyv?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ou acesse &lt;a href="https://codepen.io/marcelluscaio/pen/JjwGZyv" rel="noopener noreferrer"&gt;aqui&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Observação: Eu estou definindo a fonte no HTML em 16px para permitir que façamos o teste da mudança da fonte padrão de forma mais fácil. Esse trecho de código tem fins puramente didáticos.&lt;/p&gt;

&lt;p&gt;No próximo exemplo, podemos ver que o texto dentro da caixa vai estar ora dentro, ora transbordando, conforme a gente brinca de diminuir e aumentar a tela, ou de mudar a fonte padrão pelo input.&lt;/p&gt;

&lt;p&gt;O comportamento é errático.&lt;/p&gt;

&lt;p&gt;A largura e altura da caixa são estabelecidas de forma que, quando o conteúdo varia, temos quebra do layout. A conclusão é: nosso H1 ter a fonte definida com REM não ajudou em nada a responsividade.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/eYbJjjx?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ou acesse &lt;a href="https://codepen.io/marcelluscaio/pen/eYbJjjx" rel="noopener noreferrer"&gt;aqui&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Observação: eu estabeleci a altura dessa div usando height &lt;strong&gt;com fins didáticos&lt;/strong&gt;. Estabelecer height em elementos com conteúdo é uma prática ruim para responsividade.&lt;/p&gt;

&lt;p&gt;"Caio, meu mundo caiu! Como eu faço para deixar as fontes do meu projeto responsivas?"&lt;/p&gt;

&lt;p&gt;A forma mais comum de tornar as suas fontes responsivas é com elas: as media queries. &lt;/p&gt;

&lt;p&gt;Com isso você define que a partir de determinado tamanho de tela – digamos, 1200px - suas fontes que eram 12px, 16px e 20px vão ter um tamanho de 18px, 24px e 32px – sim, nesse blog difundimos a palavra do mobile-first.&lt;/p&gt;

&lt;p&gt;Ficaria algo mais ou menos assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;.75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;75em&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.125rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Não se assuste com a media query definida com EM. É uma boa prática declarar media queries com essa medida. Um dia posso falar disso por aqui.&lt;/p&gt;

&lt;p&gt;O REM, como vimos no tópico anterior, vai ajudar a tornar nosso site acessível. Veja que eu disse “ajudar a tornar acessível”. O assunto acessibilidade é extenso e multifacetado, e precisamos tomar muitas medidas para garantir a acessibilidade no nosso site para o máximo de pessoas possível. Temos que atentar às cores, à navegação com teclado, leitores de tela e muito mais. No caso do REM, estamos lidando apenas com um aspecto: o tamanho das fontes.&lt;/p&gt;

&lt;p&gt;Para ilustrar essa distinção entre responsividade e acessibilidade eu criei esse exemplo. Nele, temos 4 casos de texto:&lt;/p&gt;

&lt;p&gt;1)  não-responsivo e não-acessível (não muda de acordo com o tamanho da tela, e usa PX)&lt;/p&gt;

&lt;p&gt;2)  não-responsivo e acessível (não muda de acordo com o tamanho da tela, mas usa REM)&lt;/p&gt;

&lt;p&gt;3)  responsivo e não-acessível (muda de acordo com o tamanho da tela, mas usa PX)&lt;/p&gt;

&lt;p&gt;4)  responsivo e acessível (muda de acordo com o tamanho da tela, e usa REM)&lt;/p&gt;

&lt;p&gt;Mexa na largura da tela e no tamanho da fonte para ver como o tamanho de fonte se comporta em cada caso&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/NWeGPoq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ou acesse &lt;a href="https://codepen.io/marcelluscaio/pen/NWeGPoq" rel="noopener noreferrer"&gt;aqui&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Com esses exemplos a gente consegue ver que, sim, já passou da hora de você substituir todas as suas fontes de PX para REM, mas não se engane: isso não vai tornar seu site responsivo.&lt;/p&gt;

&lt;h2&gt;
  
  
  4) Defina o tamanho das suas linhas
&lt;/h2&gt;

&lt;p&gt;Quando você ia fazer trabalhos da escola ou faculdade que precisavam ter um número X de páginas, você tinha a tentação de mudar a altura da linha, para o conteúdo ocupar mais espaço.&lt;/p&gt;

&lt;p&gt;“Coloca o espaçamento 2x, ninguém vai perceber”, diz a vozinha na sua cabeça.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4i8z7ntaelt7jp8dbrga.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4i8z7ntaelt7jp8dbrga.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A verdade é que a altura da linha faz toda a diferença na legibilidade de um texto (o termo correto aqui seria leiturabilidade. Fique aí com esse palavrão e pesquise a diferença).&lt;/p&gt;

&lt;p&gt;É muito comum encontrar projetos em que o texto tem a família da fonte definida, o peso e o tamanho, mas a altura da linha não é declarada.&lt;/p&gt;

&lt;p&gt;Quando fazemos isso, delegamos para o navegador a escolha da altura de linha, e cada navegador tem um padrão diferente. Não é uma boa, né?&lt;/p&gt;

&lt;p&gt;Por isso devemos sempre declarar explicitamente nossa altura de linha. Mas como fazemos isso? Com a propriedade line-height!&lt;/p&gt;

&lt;p&gt;A gente deve seguir os mesmos princípios que para tamanho de fonte: nada de PX!&lt;/p&gt;

&lt;p&gt;Imagina que você tenha uma fonte de 1rem (nada de PX pra fonte, lembra?), e coloca a altura da linha com 20px. O que vai acontecer se a fonte padrão do usuário for 24px? Isso mesmo: a fonte das letras vai passar a ser de 24px, mas a altura da linha vai ficar travada em 20px, e o texto vai ficar todo embolado.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/vYvGaGo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ou acesse &lt;a href="https://codepen.io/marcelluscaio/pen/vYvGaGo" rel="noopener noreferrer"&gt;aqui&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Uma saída seria definir a line-height em REM, assim ela poderia variar junto com o tamanho da fonte. Porém, fazendo dessa forma, sempre que a gente mudar o tamanho da fonte em uma media query a gente precisaria lembrar de mudar a line-height também, para manter sempre a mesma proporção.&lt;/p&gt;

&lt;p&gt;Tem uma forma mais fácil de fazer isso: essa propriedade aceita porcentagem. Então a gente pode declarar a line-height como a  gente fazia no Microsoft Word: 1, 1.2, 1.5, 2.&lt;/p&gt;

&lt;p&gt;Nesse nosso exemplo, caso eu tenha uma fonte de 1rem e line-height de 1.25, os valores por padrão serão 16px para o tamanho da fonte e 20px para o tamanho da linha. Mas se a fonte padrão da pessoa usuária for 24px, os valores serão 24px e 30px respectivamente. Assim teremos sempre a mesma proporção entre fonte e altura de linha. Para melhorar: caso o tamanho da nossa fonte mude com media queries, não precisamos redeclarar a line-height!&lt;/p&gt;

&lt;p&gt;Veja esse exemplo: aqui estamos usando REM para as fontes, mudando elas com media query e definindo line-height proporcionalmente ao tamanho da fonte.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/jOXqppY?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ou acesse &lt;a href="https://codepen.io/marcelluscaio/pen/jOXqppY" rel="noopener noreferrer"&gt;aqui&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Neste artigo aprendemos algumas boas práticas de tipografia, vimos como ter mais controle sobre as nossas fontes, como evitar a repetição de código, e como tornar nossos textos mais acessíveis e responsivos.&lt;/p&gt;

&lt;p&gt;Com tudo que vimos aqui, você já sabe tudo que precisa sobre tipografia para fazer projetos para a web impecáveis. Mas a gente sempre pode ir além, né?&lt;/p&gt;

&lt;p&gt;Você notou que eu falei que “A forma mais comum de tornar as suas fontes responsivas é com elas: as media queries.”? &lt;/p&gt;

&lt;p&gt;E se eu te dissesse que você pode fazer o tamanho das suas fontes variar SEM USAR MEDIA QUERIES???&lt;/p&gt;

&lt;p&gt;Pois fique de olho, que em breve sai um artigo falando sobre como implementar a técnica de tipografia fluida.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>a11y</category>
      <category>braziliandevs</category>
    </item>
    <item>
      <title>Dicas para criar projetos front-end melhores e mais rápido - Parte 2</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Mon, 12 Jun 2023 16:48:31 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/dicas-para-criar-projetos-front-end-melhores-e-mais-rapido-parte-2-431d</link>
      <guid>https://dev.to/marcelluscaio/dicas-para-criar-projetos-front-end-melhores-e-mais-rapido-parte-2-431d</guid>
      <description>&lt;p&gt;Essa é a segunda parte do artigo. Não deixe de ler a anterior &lt;a href="https://dev.to/marcelluscaio/dicas-para-criar-projetos-front-end-melhores-e-mais-rapido-parte-1-5213"&gt;aqui&lt;/a&gt;. Vou te dar uns minutinhos pra ir lá e voltar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnonu9ce1ho23dnw6nwi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnonu9ce1ho23dnw6nwi.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pronto! E aí, gostou? Então vamos ver mais algumas dicas para a criação de projetos de front!&lt;/p&gt;

&lt;h2&gt;
  
  
  2) HTML
&lt;/h2&gt;

&lt;p&gt;Ufa, planejamos bastante, temos uma boa noção dos estágios que vamos seguir com o desenvolvimento da nossa aplicação, e se você seguiu tudo certinho até aqui já temos até algum CSS escrito.&lt;/p&gt;

&lt;p&gt;O próximo passo que costumo dar é construir todo o HTML de uma página sem me preocupar com a estilização. É isso mesmo que você leu: antes de colocar cor, mudar fonte, fazer coisinhas bonitas e animações, eu crio o esqueleto da página toda. &lt;/p&gt;

&lt;p&gt;Aqui eu me preocupo basicamente com a semântica do HTML, ou seja, em usar as tags HTML que mais fazem sentido de acordo com o conteúdo.&lt;/p&gt;

&lt;p&gt;Fazendo dessa forma eu sinto que consigo me concentrar primeiro em escrever um bom HTML sem me preocupar com estilização, o que aumenta minha chance de manter coerência interna nas decisões que tomar.&lt;/p&gt;

&lt;p&gt;Importante dizer que nesse momento já entram as tags img, mas eu não adiciono a src delas. &lt;/p&gt;

&lt;p&gt;Faço isso porque as imagens por padrão, sem nenhum CSS, tendem a ficar do tamanho do arquivo original delas, o que faz uma bagunça danada na nossa tela.&lt;/p&gt;

&lt;h2&gt;
  
  
  3) CSS
&lt;/h2&gt;

&lt;p&gt;Finalmente chegou a hora do nosso site deixar de parecer um grande documento do Word!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu95l407czz06jnnzg7sp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu95l407czz06jnnzg7sp.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Aplicando os componentes
&lt;/h3&gt;

&lt;p&gt;Lembra que criamos classes utilitárias e componentes? Esse é um bom momento para aplicá-las na página toda.&lt;/p&gt;

&lt;p&gt;Como um desses componentes era o container, isso já deixa o nosso grid do site no lugar, e evita que a gente estrague o alinhamento por descuido.&lt;/p&gt;

&lt;p&gt;Além disso, vamos ver todas as fontes configuradas, talvez um botão já tomando forma aqui e ali.&lt;/p&gt;

&lt;p&gt;O coração fica até quentinho.&lt;/p&gt;

&lt;h3&gt;
  
  
  b) Avançando um passo de cada vez
&lt;/h3&gt;

&lt;p&gt;Minha abordagem, como já adiantei, é utilizar o paradigma mobile-first. O que eu fazia no começo: montava uma página inteira para celular e depois ia adaptando ela para telas maiores.&lt;/p&gt;

&lt;p&gt;E o que acontecia: o Caio do Futuro se deparava com um código escrito pelo Caio do Passado, e nem sempre entendia muito bem: "como você fez essa seção daqui? Qual a lógica por trás desse calc, Caio do Passado? O que a classe T60 quer dizer?????".&lt;/p&gt;

&lt;p&gt;Escrever códigos bem organizados é uma forma de mitigar esse problema. Lembre-se: um código bem escrito é um agrado para outros devs, mas também é um carinho no seu Eu do Futuro. &lt;/p&gt;

&lt;p&gt;Mas além de escrever um código bem organizado e documentado, existe outra forma de reduzir esse problema: reduzindo a distância temporal entre o seu Eu do Passado e seu eu do Futuro. &lt;/p&gt;

&lt;p&gt;E não, eu ainda não estou falando de viagem no tempo!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mhh1wmah82c4lzlea6w.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mhh1wmah82c4lzlea6w.gif" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Qual é o pulo do gato aqui: eu não faço a estilização do site inteiro no mobile, para depois adaptar para desktop. Eu gosto de fazer a estilização do site seção por seção.&lt;/p&gt;

&lt;p&gt;Sempre sigo a ordem das seções, então começo pelo header, por exemplo. Faço o header para celulares. Quando está tudo certo, antes de ir para a próxima seção, faço a responsividade do header para telas maiores, e testo aquela seção da largura de tela mínima até a máxima, para me certificar que todas as fotografia do meu filme estão funcionando.&lt;/p&gt;

&lt;p&gt;Assim, tudo que fiz está mais fresco na memória, e fica muito mais fácil adaptar. &lt;/p&gt;

&lt;p&gt;Além disso, eu garanto que só passo de uma seção para outra quando não tem nenhum bug na anterior. Assim, quando algum problema surge, provavelmente tem a ver com a seção na qual estou trabalhando naquele momento, em vez de ter que caçar na página toda o que ocasionou aquele overflow que atormenta a gente!&lt;/p&gt;

&lt;h3&gt;
  
  
  c) Padronize as suas propriedades CSS
&lt;/h3&gt;

&lt;p&gt;Você provavelmente já teve que voltar em um código que escreveu e teve dificuldade em encontrar alguma informação que queria, ou entender o que estava acontecendo ali, né?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fz65n0thhzn636el834.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fz65n0thhzn636el834.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Isso acontece por conta da organização do código. &lt;/p&gt;

&lt;p&gt;Por mais que a ordem das propriedades do CSS não faça diferença para o computador, nós não escrevemos o nosso código para máquinas, mas para outros desenvolvedores. E seres humanos gostam de padrões, lembra?&lt;/p&gt;

&lt;p&gt;Quando estamos começando, nosso CSS sai na ordem em que escrevemos. Conforme a gente precisa, ou lembra de uma propriedade, a gente coloca no código, e elas ficam lá na ordem em que escrevemos.&lt;/p&gt;

&lt;p&gt;Fica algo mais ou menos assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;350px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Esse código todo funciona, mas ele traz dois problemas: ele é um pouco complicado de ler, e ele permite que erros bobos aconteçam, como a redeclaração da propriedade width (você tinha percebido?).&lt;/p&gt;

&lt;p&gt;Por isso é importante que a gente siga alguma padrão na hora de fazer o nosso CSS.&lt;/p&gt;

&lt;p&gt;Muitas pessoas usam o padrão alfabético. Eu gosto de seguir um padrão que divide em propriedades de display, posicionamento, box-model, tipografia e depois uma miscelânea. Vou falar sobre isso em outro artigo, mas o mais importante é: escolha um padrão e seja coerente. Isso vai tornar seu projeto mais fácil de ler, de fazer manutenção, e evita declaração redundante de propriedades. &lt;/p&gt;

&lt;p&gt;Crie um padrão, documente e siga em frente. Na dúvida, coloque em ordem alfabética.&lt;/p&gt;

&lt;p&gt;Como ficaria nossa classe card em ordem alfabética:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aqui resolvemos o risco de declarar duas vezes a mesma propriedade, já que ao colocar em ordem alfabética ficaria gritante que temos duas propriedades repetidas, mas eu ainda acho que o código fica confuso de ler.&lt;/p&gt;

&lt;p&gt;Como eu faria no meu dia-a-dia:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dessa maneira, as propriedades afins estão agrupadas, e eu consigo saber como elas trabalham em conjunto para atingir o leiaute desejado. &lt;/p&gt;

&lt;h3&gt;
  
  
  d) Evite usar código inútil
&lt;/h3&gt;

&lt;p&gt;Essa parece óbvia, mas não é: é muito importante, até mesmo para que você atinja o domínio das linguagens com que for trabalhar, que mantenha apenas códigos que você realmente quer usar, que sabe o que estão fazendo naquela situação. &lt;/p&gt;

&lt;p&gt;É muito comum ver códigos com várias propriedades CSS que não tem nenhuma função. &lt;/p&gt;

&lt;p&gt;Uma div com todas as técnicas para centralizar um elemento aplicado nela, por exemplo. Dá pra ver a história por trás daquilo: o desenvolvedor back-end colocou uma propriedade, não funcionou; Colocou outra, não funcionou. No fim temos 10 declarações diferentes, e a div continua torta. (Esse relato é uma obra de ficção, qualquer semelhança com a realidade é mera coincidência. Beijo pra galera do back &amp;lt;3).&lt;/p&gt;

&lt;p&gt;Ao usar somente propriedades CSS que tenham utilidade no seu projeto, seu código fica mais legível, e você fortalece seu conhecimento das ferramentas que usa. &lt;/p&gt;

&lt;p&gt;Dica: use e abuse do DevTools. Você pode marcar e desmarcar as propriedades para ver o que acontece, e ele até mostra que propriedades estão declaradas, mas não estão sendo usadas.&lt;/p&gt;

&lt;h3&gt;
  
  
  e) Como nomear as suas classes?
&lt;/h3&gt;

&lt;p&gt;Para finalizar o tópico do CSS, o temido momento: como vamos nomear as nossas classes? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m64fpuypzs2v1ialsxl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m64fpuypzs2v1ialsxl.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A resposta é bem simples: tanto faz, mas seja coerente. &lt;/p&gt;

&lt;p&gt;Existem diversas metodologias, e isso pode variar de equipe para equipe quando trabalhamos com outros devs. O importante é experimentar, e encontrar uma que faça sentido para você. A metodologia BEM é muito utilizada, e é um ótimo lugar para começar.&lt;/p&gt;

&lt;p&gt;Eu, particularmente, uso uma adaptação dela, mas só nomeio novas classes quando estritamente necessário. Se posso resolver algo com seletores do CSS, eu não crio uma classe nova. Todas as seções do site têm uma classe específica (ou compartilhada, se forem seções-gêmeas), e a partir daí vou selecionando os elementos filhos com seletores CSS. &lt;/p&gt;

&lt;p&gt;Uso as classes apenas quando há possível ambiguidade, como no exemplo abaixo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;nav&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="nc"&gt;.menu-options&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;   
   &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--colorMain&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-100%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;top&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease-in&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease-in&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nesse caso eu criei uma classe específica pois havia duas uls no meu header.&lt;/p&gt;

&lt;p&gt;Esse código foi retirado do projeto criado durante o Challenge Front-End da Alura que aconteceu em março de 2023. Você pode conferir o projeto completo &lt;a href="https://github.com/marcelluscaio/Codechella_AluraChallenge" rel="noopener noreferrer"&gt;aqui&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  f) Organização de arquivos e pastas
&lt;/h3&gt;

&lt;p&gt;Por fim, tenha sempre seu CSS bem organizado. Eu costumo dividir ele em arquivos diferentes para cada seção, além de ter um arquivo para a estilização geral (guia de estilo, variáveis, componentes, classes utilitárias). Há quem goste de ter um arquivo separado para as media queries, mas eu prefiro que em cada arquivo eu tenha as media queries relevantes para aquela seção.&lt;/p&gt;

&lt;h2&gt;
  
  
  4) Bônus
&lt;/h2&gt;

&lt;p&gt;Queria falar de alguns princípios que costumo seguir quando estou escrevendo código:&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Legibilidade é mais importante que brevidade
&lt;/h3&gt;

&lt;p&gt;Muitas vezes vejo pessoas felizes da vida porque conseguem juntar a declaração de várias propriedades CSS em uma única propriedade. ‘font’ por exemplo substitui outras SETE propriedades. &lt;/p&gt;

&lt;p&gt;Usar esse artifício torna seu código mais curto, mas será que torna ele mais legível? &lt;/p&gt;

&lt;p&gt;Sempre que me deparo com uma dessas escolhas, esse é o primeiro princípio que me vem à mente: é mais importante ter um código legível, organizado e intuitivo do que deixar de escrever algumas linhas de código para no futuro ter dificuldade de fazer manutenção no código.&lt;/p&gt;

&lt;p&gt;Isso não quer dizer que está liberado o Ctrl + C; Ctrl + V! &lt;/p&gt;

&lt;p&gt;“Ah, o Caio falou que legibilidade é tudo e brevidade não importa. Vou fazer um código gigantesco e redundante e vou dormir feliz”.&lt;/p&gt;

&lt;p&gt;Intepretação de texto freestyle não se cria aqui, não. Por isso, vamos para o próximo tópico.&lt;/p&gt;

&lt;h3&gt;
  
  
  b) DRY (Don’t repeat yourself/Não se repita)
&lt;/h3&gt;

&lt;p&gt;Sempre que no nosso código estamos copiando e colando alguma estrutura, é sinal de que poderíamos abstrair aquela estrutura para evitar a repetição. &lt;/p&gt;

&lt;p&gt;Essa abstração pode ser na forma de uma classe ou Custom Property do CSS, ou mesmo uma variável ou função no JavaScript, depende do ambiente em que estamos.&lt;/p&gt;

&lt;p&gt;Nesse artigo já apliquei o DRY sem nomeá-lo: quando criamos nossas classes de componentes, estávamos abstraindo propriedades CSS para uma classe, a fim de não termos que repetir aquelas propriedades várias vezes.&lt;/p&gt;

&lt;h3&gt;
  
  
  c) Intencionalidade e Coerência
&lt;/h3&gt;

&lt;p&gt;Aqui a coisa fica meio abstrata, mas talvez seja o ponto mais importante: tenha uma razão por trás de suas escolhas, e não mude essa racionalidade no meio de um projeto.&lt;/p&gt;

&lt;p&gt;Digamos que você está fazendo um site, e dentro de uma seção você tem três informações: título, texto e uma foto, um embaixo do outro. No figma, todos eles têm o mesmo espaçamento inferior: 24px.&lt;/p&gt;

&lt;p&gt;Você pode construir essa tela assim. Você pode abrir em outra tela para ver melhor: &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/dygrKqd?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Mas isso, por mais que funcione agora na sua tela, pode trazer alguns problemas. &lt;/p&gt;

&lt;p&gt;Como escolhemos o tamanho da fonte do h1 utilizando px e do p utilizando rem, caso haja a mudança da fonte padrão do browser a relação entre as nossas fontes vai mudar. &lt;/p&gt;

&lt;p&gt;Pior que isso: se essa relação entre fontes mudar, como escolhemos as margin-bottom de cada um utilizando também padrões diferentes, o espaçamento inferior entre eles também vai ser prejudicado.&lt;/p&gt;

&lt;p&gt;Podemos consertar esse problema assim:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/JjmzZqM?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;O segundo código muda pouca coisa, mas muda tudo: nele escolhemos as nossas medidas com a intenção de manter o tamanho da fonte adaptável para os diferentes padrões de fonte que nossos usuários podem ter. &lt;/p&gt;

&lt;p&gt;E usamos a mesma racionalidade para o h1 e para o p, sendo coerentes com a nossa escolha inicial. &lt;/p&gt;

&lt;p&gt;Isso não significa ser obrigado a usar a mesma unidade sempre, mas, sim, usar sempre a mesma linha de raciocínio.&lt;/p&gt;

&lt;p&gt;Talvez a gente possa resumir isso em dois princípios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;não use unidades diferentes para o mesmo objetivo;&lt;/li&gt;
&lt;li&gt;não use técnicas diferentes para fazer a mesma coisa;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  d) Não use números mágicos
&lt;/h3&gt;

&lt;p&gt;Quem nunca foi posicionar um elemento na tela e usou aquele número super preciso, que funciona perfeitamente, mas... de onde ele veio mesmo? &lt;/p&gt;

&lt;p&gt;“Tentativa e erro, Caio. Deixa eu ser feliz!”.&lt;/p&gt;

&lt;p&gt;Claro, claro. Mas eu estou aqui para te poupar de dores muito maiores, jovem gafanhoto.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa7b1m1e5wl7pzxqiqkmh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa7b1m1e5wl7pzxqiqkmh.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Para exemplificar isso, me inspirei na &lt;a href="https://dev.to/nataliafdev"&gt;Natália&lt;/a&gt; e fiz o começo de um desenho com CSS. &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/JjmzBXv?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Na minha tela, essa posição para os olhos está funcionando perfeitamente. 58px! O que poderia dar errado? &lt;/p&gt;

&lt;p&gt;Err... será que em outras telas funciona também?&lt;/p&gt;

&lt;p&gt;Convido você a brincar de arrastar o tamanho da tela para ver que só em uma largura de tela específica que os olhos ficam no lugar desejado.&lt;/p&gt;

&lt;p&gt;Lembre-se, temos sempre que pensar no filme, não na foto.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Esses são alguns dos princípios e técnicas que sigo ao criar projetos Front-end. &lt;/p&gt;

&lt;p&gt;Planejando, tendo organização, coerência e tendo domínio do código que produzimos conseguimos criar projetos mais robustos. &lt;/p&gt;

&lt;p&gt;Espero que você tenha gostado das dicas. Me conta aqui nos comentários algo que você faz e que eu não comentei. Me conta também sobre qual das dicas você nunca tinha parado para pensar.&lt;/p&gt;

&lt;p&gt;Aproveito para agradecer à leitura atenta e às contribuições da &lt;a href="https://dev.to/sucodelarangela"&gt;Ângela&lt;/a&gt; e da &lt;a href="https://dev.to/monicahillman"&gt;Moni&lt;/a&gt;, que além de terem dado pitacos valiosos no texto, são inspirações para mim. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Dicas para criar projetos front-end melhores e mais rápido - Parte 1</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Mon, 05 Jun 2023 16:17:28 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/dicas-para-criar-projetos-front-end-melhores-e-mais-rapido-parte-1-5213</link>
      <guid>https://dev.to/marcelluscaio/dicas-para-criar-projetos-front-end-melhores-e-mais-rapido-parte-1-5213</guid>
      <description>&lt;p&gt;Quando estamos aprendendo a programar a gente se acostuma a seguir tutoriais. O instrutor faz, a gente segue tin tin por tin tin, a coisa (quase sempre) funciona, o mundo é lindo e os passarinhos cantam.&lt;/p&gt;

&lt;p&gt;Aí a gente vai fazer nosso primeiro projeto por conta própria (ou segundo, ou terceiro...) e bate aquela sensação... E agora? O que eu faço? Por onde começo?&lt;/p&gt;

&lt;p&gt;Eu passei por essa situação bem mais de três vezes, cara leitora/caro leitor. Com o tempo, fui reunindo alguns hábitos e práticas que me ajudam a ter maior controle e eficiência nos projetos em que trabalho. Reuni neste artigo algumas dessas dicas/conselhos que vão aumentar sua produtividade, a qualidade do seu código, além de te ajudar a ter mais segurança na hora de começar novos projetos.&lt;/p&gt;

&lt;p&gt;É bom logo tirar uma coisa do nosso caminho: não existe maneira certa de fazer esse tipo de coisa, apenas maneiras não-erradas. Essas práticas me ajudam, e pode ser que algumas dessas coisas não funcionem para você. Ficarei feliz em ler todos os feedbacks e experiências, o campo de comentários está aberto. Educados comentam.&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Planejamento
&lt;/h2&gt;

&lt;p&gt;A primeira coisa a se fazer para escrever um bom código é: não abra o seu editor de código favorito agora. &lt;/p&gt;

&lt;p&gt;É isso mesmo que você leu. Deixa para abrir o VS Code daqui a pouco.&lt;/p&gt;

&lt;p&gt;A gente começa planejando. E para isso vamos abrir o leiaute que vamos construir.&lt;/p&gt;

&lt;p&gt;Com sorte, você recebeu um arquivo de referência criado por uma/um designer. Com mais sorte ainda, a/o designer teve tempo de ser meticulosa/o e todos os elementos do leiaute seguem uma lógica: os espaçamentos, respiros, tamanhos de fontes, tudo tem alguma coerência interna.&lt;/p&gt;

&lt;p&gt;Mas no mundo real estamos todos trabalhando com prazos apertados, e algumas coisas podem passar batidas. É nosso trabalho interpretar aquele arquivo, entender qual era a intenção de quem criou, perguntar quando houver dúvidas e sugerir alterações.&lt;/p&gt;

&lt;p&gt;Com o leiaute aberto, você vai prestar atenção nos seguintes pontos:&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Existe um guia de estilo?
&lt;/h3&gt;

&lt;p&gt;Aqui é a hora de construir o nosso guia de estilos no CSS. Vamos olhar para o leiaute e nos perguntar: Quais são as cores utilizadas? Quais são as fontes utilizadas (família, tamanho, peso)?&lt;/p&gt;

&lt;p&gt;Eu costumo fazer isso criando propriedades personalizadas no CSS (CSS Custom Properties), que muitas vezes chamamos de variáveis CSS. &lt;/p&gt;

&lt;p&gt;Nas Custom Properties eu defino todas as cores do projeto, font-family, font-weight e font-size. Assim, alguns tipos de mudanças podem ser feitas no guia de estilo do projeto, sem precisar acessar cada ocorrência daquela propriedade.&lt;/p&gt;

&lt;p&gt;O resultado fica algo mais ou menos assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--color-main&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FF0000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--color-secondary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#00FF00&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--ff-arial&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--fw-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fw-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Não reparem na escolha de fontes e cores. O que quero demonstrar aqui é que nosso guia de estilos vai estar definido nessas variáveis e pode ser acessado e modificado com facilidade, pois a fonte daquela informação está em apenas um lugar. &lt;/p&gt;

&lt;p&gt;Um exemplo do que poderia acontecer: digamos que a empresa foi comprada por outra, que reformula a identidade visual, mudando as cores da marca. Em vez de correr atrás de todas as ocorrências de cores, podemos apenas alterar no nosso guia de estilos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--color-main&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FFFF00&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--color-secondary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#00FFFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--ff-arial&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--fw-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fw-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim as mudanças serão replicadas onde quer que eu tenha colocado as Custom Properties "color-main" e "color-secondary". &lt;/p&gt;

&lt;h3&gt;
  
  
  b) Qual o alinhamento? Existe uma linha de grade?
&lt;/h3&gt;

&lt;p&gt;O alinhamento é um dos principais responsáveis por orientar a leitura do usuário. Alinhamento é aquela linha invisível que passa pelas extremidades do conteúdo do site. A ponta esquerda do conteúdo do seu header é uma das linhas de grade do seu site. Um site com alinhamento coerente e intuitivo melhora muito a experiência do usuário. Por isso é importante que você tenha clareza no início do projeto quantas larguras diferentes de seção vai haver no site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93uoywuiioiyuohrwf0o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93uoywuiioiyuohrwf0o.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aqui temos um exemplo de um site desalinhado. Criei as bordas laterais para que a gente possa ver como não existe padrão nenhum no alinhamento.&lt;/p&gt;

&lt;p&gt;Olha só como fica bem melhor com um alinhamento feito com mais cuidado:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnjfm8u0zs9gq6t6k0xkl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnjfm8u0zs9gq6t6k0xkl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quando estamos começando, fazemos o alinhamento caso a caso, seção a seção. O que acaba acontecendo: seguimos critérios diferentes a cada vez que fazemos. Uma hora definimos a width da seção com px, depois com %, mais na frente fazemos usando padding. Isso faz com que a gente não tenha clareza de qual é o tamanho que cada tipo de seção do site deve ter. E se isso não está claro na sua cabeça enquanto você está programando, isso não vai estar claro no seu código, nem vai estar claro na tela.&lt;/p&gt;

&lt;p&gt;Para fazer esse trabalho a gente usa os containers. A gente ouve essa palavra, vê em códigos de cursos, mas muitas vezes não paramos para pensar qual a finalidade desse tal de container. &lt;/p&gt;

&lt;p&gt;O papel de um container é... conter um determinado conteúdo.&lt;/p&gt;

&lt;p&gt;Tá, tá, vou dar uma definição menos óbvia.&lt;/p&gt;

&lt;p&gt;O container é responsável por definir a largura máxima  dos elementos que estão dentro dele. Se temos dois conteúdos distintos com a mesma largura e alinhados ao centro, podemos ter (quase) certeza que esses conteúdos estão alinhados. Digo 'quase' porque podemos quebrar esse alinhamento colocando padding no container, por exemplo, estragando o alinhamento que o container estava tentando criar.&lt;/p&gt;

&lt;p&gt;Há duas técnicas para a criação de um container. Uma usa width e a outra usa padding lateral. Elas tem suas vantagens e desvantagens e vou explorar isso mais a fundo em um artigo em breve. &lt;/p&gt;

&lt;p&gt;“Tá, Caio, mas e se eu tiver várias larguras diferentes?”&lt;/p&gt;

&lt;p&gt;Pode ser o caso de você conversar com o designer para entender melhor as linhas de grade do projeto. Pode ser que determinada seção possa aumentar um pouco, outra possa diminuir e vocês consigam uniformizar um pouco as linhas de grade.&lt;/p&gt;

&lt;p&gt;Nos seus projetos pessoais, comece usando um tamanho só de container. Depois aumente para dois. Isso vai te dar uma clareza maior, e treinar seu olhar para identificar conteúdos desalinhados.&lt;/p&gt;

&lt;p&gt;Naquele exemplo do caio-chella  - projeto criado durante o Challenge Front-End da Alura que aconteceu em março de 2023) - eu estruturei da seguinte maneira:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--container-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;86.5%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--container-width&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="py"&gt;margin-inline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dessa forma eu estabeleci uma mesma largura para todos os meus containers, e na classe container eu aplico essa largura, além de alinhar ao centro com a propriedade margin-inline.&lt;/p&gt;

&lt;p&gt;Se quiser conferir o projeto, dá um pulo no meu github: &lt;a href="https://github.com/marcelluscaio/Codechella_AluraChallenge/tree/main" rel="noopener noreferrer"&gt;https://github.com/marcelluscaio/Codechella_AluraChallenge/tree/main&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;c) Há elementos gráficos repetidos?&lt;/p&gt;

&lt;p&gt;O cérebro humano evoluiu para reconhecer padrões. E que sensação gostosa quando nós identificamos um! Essa sensação boa que a familiaridade traz está chumbada no nosso cérebro. Isso se reflete no design de sites. &lt;/p&gt;

&lt;p&gt;Seria muito estranho que um botão na primeira seção do site fosse retangular e azul e outro no final fosse redondo e rosa, não é? Por isso, normalmente o design de um site costuma ter elementos semelhantes.&lt;/p&gt;

&lt;p&gt;Esses elementos semelhantes terão a estilização semelhante no CSS. Agora é a melhor hora para identificar esses elementos e criar componentes e classes utilitárias. Para isso, a  gente vai criar classes no CSS que reúnem todas as características comuns daquele componente.&lt;/p&gt;

&lt;p&gt;A distinção que faço aqui entre componentes e classes utilitárias é meramente teórica, e tem a ver com o tipo de propriedade que as classes manipulam. Se está lidando apenas com elementos da tipografia, por exemplo, entendo que estamos diante de uma classe utilitária (como no exemplo de fontes que irei dar mais adiante). Se estamos lidando com mais de uma característica do elemento, entendo que estamos diante de um componente (como no caso do container ali em cima, e do botão que vou mostrar logo adiante).&lt;/p&gt;

&lt;p&gt;Essa distinção é menos importante que a lógica por trás dela, não se apegue muito a isso. &lt;/p&gt;

&lt;p&gt;Digamos que você viu que os botões do seu site todos tem fundo vermelho e cor do texto verde. O que você faz? &lt;/p&gt;

&lt;p&gt;Demite seu designer!&lt;/p&gt;

&lt;p&gt;Brincadeira! Ao percebermos esse padrão, podemos criar uma classe que vai reunir essas características:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--color-main&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ff0000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--color-secondary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#00ff00&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.button&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--color-main&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--color-secondary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Você pode observar ainda outras características em comum aos botões, como padding, border-radius e text-align, por exemplo.&lt;/p&gt;

&lt;p&gt;Outro elemento de um site que costuma ter um alto grau de padronização é a tipografia.&lt;/p&gt;

&lt;p&gt;Vale a pena dedicar um tempo para anotar todos os tamanhos de fonte, famílias, peso e altura da linha para compreender o padrão do site. Fazendo isso, podemos chegar ao seguinte resultado:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--ff-calistoga&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Calistoga'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;cursive&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--ff-raleway&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Raleway'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--fw-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fw-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="py"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="py"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;48px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.title&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--ff-raleway&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fw-2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.title--small&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--ff-calistoga&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fw-1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fs-1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.text--bold&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--fw-2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E aí no seu HTML você pode fazer algo do tipo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Título&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"title title--small"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Título menor&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Texto&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text text--bold"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Texto em negrito&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d) Qual foi a largura de tela utilizada no leiaute?&lt;/p&gt;

&lt;p&gt;Muitas vezes nós olhamos o leiaute e tentamos replicar ele na nossa tela: “O designer colocou 30px de padding lateral na página? Vou colocar o mesmo aqui na minha página e vai ficar igualzinho”.&lt;/p&gt;

&lt;p&gt;Eis que você chega num ponto em que não consegue reproduzir fielmente o que vê no leiaute. “Mas eu coloquei exatamente as mesmas medidas que estavam lá! Viu, Caio, por isso que eu não gosto de front!”.&lt;/p&gt;

&lt;p&gt;Eu entendo a sua revolta, mas eu posso te ajudar a nunca mais ter esse problema. A questão aqui é simples: &lt;strong&gt;o leiaute é apenas uma fotografia da nossa aplicação&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Essa foto é como um mapa que vamos seguir, e ali estão representados alguns momentos-chave da nossa aplicação – no geral a versão mobile e desktop (se você tem mais do que isso você é privilegiado SIM). &lt;/p&gt;

&lt;p&gt;O desenvolvimento do site é um filme, a junção de todas essas fotografias/cenas. &lt;/p&gt;

&lt;p&gt;Cada cena é uma largura de tela, e devemos pensar como toda a movimentação dos atores - nossos componentes/elementos em tela - está acontecendo. Algo pode sair muito bem na foto aos 1700px, mas quando chega aos 1300px alguma coisa pode quebrar, ficar fora de quadro. &lt;/p&gt;

&lt;p&gt;Um grande salto na mentalidade de um bom desenvolvedor é parar de olhar a foto (“funciona na minha tela!”) e passar a se preocupar com o filme (“Como será que isso vai se comportar quando a tela for menor/maior que a minha? Qual é a experiência do usuário do produto que estou criando?”).&lt;/p&gt;

&lt;p&gt;Então, quando olhamos para o leiaute é essencial pensar qual momento do nosso site aquele leiaute está retratando. Se olharmos para um leiaute construído em 1700px e começarmos a construir o nosso site na nossa tela de 1300px vamos criar distorções involuntariamente. &lt;/p&gt;

&lt;p&gt;Lembre-se, o dev tools é o seu melhor amigo.&lt;/p&gt;

&lt;p&gt;e) Mobile-first ou Desktop-first?&lt;/p&gt;

&lt;p&gt;Outro ponto para considerar é: qual paradigma adotar no projeto, mobile-first ou desktop-first? Caso você não saiba do que estou falando, esses são dois paradigmas que definem como vamos começar o nosso projeto: “mobile-first” (celular primeiro) desenvolve primeiro a versão mobile  e “desktop-first” (computador primeiro) começa pela versão desktop. &lt;/p&gt;

&lt;p&gt;É bom você se acostumar com esses conceitos. =)&lt;/p&gt;

&lt;p&gt;Mas afinal, por onde começar, pelo desenvolvimento para celulares ou para desktop?&lt;/p&gt;

&lt;p&gt;Se alguma vozinha aí dentro da sua cabeça já está tipo a Hermione, afoita para responder, gritando “DEPENDE! DEPENDE!” você está no caminho para se tornar sênior! 500 pontos para a grifinória!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufwcoxdn9qsryiagqivu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufwcoxdn9qsryiagqivu.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Na minha experiência, começar pelo desenvolvimento para celulares facilita muito o trabalho, mas não quero me aprofundar nesse tema aqui, senão a gente se perde do assunto principal. A escolha entre os dois paradigmas é livre, mas deve ser consciente. E ela é importante porque &lt;strong&gt;isso vai afetar como você declara as suas media queries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Se você começa desenvolvendo para uma tela de 370px, por exemplo, quando for adaptar para telas maiores, digamos 1200px, vai usar min-width 1200px. &lt;/p&gt;

&lt;p&gt;Se, por outro lado, começou desenvolvendo para 1653px, quando for fazer a versão tablet vai precisar declarar a media query com max-width 768px, por exemplo. &lt;/p&gt;

&lt;p&gt;Manter suas media queries em ordem é muito importante para não surtar na hora de caçar bugs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fye54uvcn8yfj0crb8793.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fye54uvcn8yfj0crb8793.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Seguindo todos esses passos do planejamento nossos projetos ficam muito melhor organizados, e a gente passa a ter muito mais controle sobre o que está acontecendo na tela. &lt;/p&gt;

&lt;p&gt;Mas a gente mal começou a escrever código. Semana que vem eu trago mais dicas para tornar o seu projeto ainda mais robusto.&lt;/p&gt;

&lt;p&gt;Me conta aqui nos comentários: qual dica você mais gostou, e de qual sentiu falta?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Quem tem medo do nth-child?</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Mon, 03 Apr 2023 16:34:53 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/quem-tem-medo-do-nth-child-1mlk</link>
      <guid>https://dev.to/marcelluscaio/quem-tem-medo-do-nth-child-1mlk</guid>
      <description>&lt;p&gt;Digamos que você precisa dar manutenção em um código na empresa em que você trabalha, e se depara com isso daqui no CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;9&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;4&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Talvez a sua primeira reação seja essa daqui:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pSXYFRas--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlr01g4ci7bsdplmjc8j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pSXYFRas--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlr01g4ci7bsdplmjc8j.jpg" alt="Meme Nothing to do here em que desenho de pessoa está fugindo com uma mochila voadora de uma situação desconfortável" width="500" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Palma, palma, não priemos cânico! Pega um café e vamos destrinchar passo a passo de como esse megazord funciona. Depois de ler esse artigo você vai entender e apreciar essa ferramenta poderosa que é a pseudo-classe :nth-child(). Ficou na dúvida do que é uma pseudo-classe? Dá uma olhada no artigo da &lt;a class="mentioned-user" href="https://dev.to/sucodelarangela"&gt;@sucodelarangela&lt;/a&gt; que está lá nas referências. Mas, em linhas gerais, é só lembrar da partícula “pseudo” que a gente viu na escola (pseudociências, pseudofrutos), que significava aquilo que parece ser, mas não é. As pseudo-classes são seletores do CSS que ajudam a mirar em certos elementos sem necessidade de criar uma classe específica para eles.&lt;/p&gt;

&lt;p&gt;Vamos estudar alguns casos?&lt;/p&gt;

&lt;h2&gt;
  
  
  1 – Usando :nth-child() com um número absoluto
&lt;/h2&gt;

&lt;p&gt;Aqui a coisa é bem intuitiva: você seleciona o elemento que é o enésimo filho dentro de outro. &lt;/p&gt;

&lt;p&gt;Enésimo????&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oyJ9mA3L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbdbu9updc3nk1si3g9w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oyJ9mA3L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbdbu9updc3nk1si3g9w.jpg" alt="Meme da Nazaré em que a personagem de uma novela olha para cálculos complexos com perplexidade" width="702" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tá, talvez fique mais fácil com exemplos, né? É o seguinte: se você colocar :nth-child(1), vai selecionar o primeiro elemento, :nth-child(2), o segundo, e assim por diante.&lt;/p&gt;

&lt;p&gt;No exemplo abaixo eu usei o seletor&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.filho&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;para pintar o terceiro quadrado de verde.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/rNZEvKL?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;O que está acontecendo aqui: estamos selecionando o elemento com classe "filho" &lt;strong&gt;que também seja o terceiro filho de outro elemento&lt;/strong&gt;. E isso é muito importante, como vamos ver a seguir.&lt;/p&gt;

&lt;p&gt;Um erro muito comum é pensar “Eu quero o terceiro elemento com a classe ‘filho’” e usar o nth-child. Veja o exemplo abaixo:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/NWLQxYo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;No primeiro cenário, estamos tentando mirar no elemento com classe filho que seja o terceiro filho de algum elemento. Acontece que nesse caso, o terceiro filho é uma tag p sem a classe “filho”. Então o CSS não encontra ninguém para pintar de verde. &lt;/p&gt;

&lt;p&gt;No segundo cenário, corrigimos usando nth-child(4), mas a correção vai depender de qual o nosso objetivo (poderia ser aplicar ‘.pai &amp;gt; :nth-child(3)’, ou mesmo ‘:nth-of-type(3)’, atingindo resultados diferentes).&lt;/p&gt;

&lt;p&gt;Aí você que leu até aqui pensa “Que moleza! Já entendi, nem vou ler o resto” e corre pro seu projeto querendo estilizar aquela lista de links. Com a segurança  de quem sabe que CSS se aprende em 30 minutos, você digita:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.lista__item__link&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ao ver que não funcionou, com lágrimas nos olhos, você corre para o twitter e lança a hashtag #ocaiomentiupramim.&lt;/p&gt;

&lt;p&gt;Mas calma lá. Vamos entender o que aconteceu aqui hipotética pessoa apressada.&lt;/p&gt;

&lt;p&gt;Sua lista de links tem mais ou menos essa cara aqui:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/ExeqPeg?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;O que acontece é que você estava dizendo pro CSS: “Corre lá, e busca o 'lista__item__link' que seja o terceiro filho de alguém”. O CSS foi e só encontrou “lista__item__link” que era o primeiro filho do “lista__item”. Ele ficou bem confuso, e com um balde de tinta vermelha inutilizado.&lt;/p&gt;

&lt;p&gt;Agora você já entendeu e já sabe como consertar: é só mirar no terceiro “lista__item”, e depois selecionar o filho dele.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.lista__item&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;.lista__item__link&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/RwYXrey?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Até agora os exemplos que vimos não parecem tão úteis. Como estamos mirando em apenas um elemento, todas as vezes seria possível utilizar classes sem prejuízo da manutenibilidade do código. E se precisássemos aplicar uma ação nos elementos múltiplos de 3? Você precisaria aplicar várias vezes aquela classe no HTML. Daria para usar nth-child(3), nth-child-(6), nth-child-(9), nth-child(12), mas e se você não soubesse de antemão quantos elementos vão estar naquela lista? &lt;/p&gt;

&lt;p&gt;É aí que o nth-child começa a brilhar.&lt;/p&gt;

&lt;h2&gt;
  
  
  2 – Usando múltiplos
&lt;/h2&gt;

&lt;p&gt;Quando usamos o ‘n’ do nth-child, é como se substituíssemos esse ‘n’ por cada posição dos elementos filhos. Uma ul que tenha 6 li’s, e na qual colocássemos o seletor “li:nth-child(2n)” faria por trás dos panos algo assim:&lt;/p&gt;

&lt;p&gt;li:nth-child(2 * 1), logo li:nth-child(2);&lt;br&gt;
li:nth-child(2 * 2), logo li:nth-child(4);&lt;br&gt;
li:nth-child(2 * 3) , logo li:nth-child(6);&lt;br&gt;
...&lt;br&gt;
li:nth-child(2 * 6) , logo li:nth-child(12);&lt;/p&gt;

&lt;p&gt;Então ele iria selecionar o 2º, 4º e 6º elementos.&lt;/p&gt;

&lt;p&gt;Digamos que a gente precise pintar todo o terceiro quadrado de uma lista de 20 quadrados de verde.  Agora a gente já consegue fazer isso bem fácil:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/WNgVrYB?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Agora, e se a gente precisasse fazer isso, só que começando do primeiro? No caso, pintar o primeiro e depois ir pulando de três em três (4º, 7º, etc)?&lt;/p&gt;

&lt;h2&gt;
  
  
  3 – Adicionando deslocamento
&lt;/h2&gt;

&lt;p&gt;Bem , nós já sabemos fazer a seleção do 3º, 6º, 9º... certo?&lt;/p&gt;

&lt;p&gt;Agora compare essas duas seleções:&lt;/p&gt;

&lt;p&gt;0º, 3º, 6º, 9º...&lt;br&gt;
1º, 4º, 7º, 10º...&lt;/p&gt;

&lt;p&gt;A diferença entre elas é que na segunda, em vez de começarmos do zero, começamos do número 1&lt;/p&gt;

&lt;p&gt;Para fazermos isso com nth-child basta a gente somar o deslocamento que a gente quer ao múltiplo de 'n'. Nesse caso, nth-child(3n + 1).&lt;/p&gt;

&lt;p&gt;Na dúvida, substitua o n pelo número de elementos, em sequência, começando do zero.&lt;/p&gt;

&lt;p&gt;nth-child(3n + 1) =&amp;gt;&lt;br&gt;
nth-child(3 * 0 + 1), logo nth-child(1);&lt;br&gt;
nth-child(3 * 1 + 1), logo nth-child(4);&lt;br&gt;
nth-child(3 * 2 + 1), logo nth-child(7);&lt;br&gt;
...&lt;br&gt;
nth-child(3 * 20 + 1), logo nth-child(61);&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/wvEVmoo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Isso também pode ser usado para mirar em todos os elementos menos alguns do início. Digamos que a gente quer pintar todos os quadrados de verde, menos os três primeiros.&lt;/p&gt;

&lt;p&gt;Se usássemos “nth-child(n)” estaríamos dizendo para selecionar todos os elementos. Se somássemos 1, o resultado seria... o mesmo!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LSqnTL0s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxpmyxqez10ja9ela2b0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LSqnTL0s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxpmyxqez10ja9ela2b0.jpg" alt="Cachorrinho decepcionado" width="275" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aqui temos que entender o pulo do gato do nth-child: a contagem dele começa do 0. Então, quando somamos 1, não vamos ver diferença no resultado. Temos sempre que pensar um número à frente para compensar esse primeiro “n-fantasma”.&lt;/p&gt;

&lt;p&gt;É só fazer aquela substituição marota:&lt;br&gt;
nth-child(n + 1) =&amp;gt;&lt;br&gt;
nth-child(0 + 1), logo nth-child(1);&lt;br&gt;
nth-child(1 + 1), logo nth-child(2);&lt;br&gt;
nth-child(2 + 1), logo nth-child(3);&lt;br&gt;
...&lt;br&gt;
nth-child(20 + 1), logo nth-child(21);&lt;/p&gt;

&lt;p&gt;Com isso, podemos concluir que para pular os três primeiros elementos, temos que somar 4, usando nth-child(n + 4). Podemos ainda pensar da seguinte forma: usando nth-child(n + 4) estamos selecionando do 4º elemento em diante,&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/jOvgzmG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Um outro pulo do gato do nth-child: a contagem do 'n' na verdade não para na quantidade de elementos da lista. Por isso um seletor como nth-child(n - 5), que poderia servir para selecionar todos os itens, menos os cinco últimos &lt;strong&gt;não funciona&lt;/strong&gt;. Esse seletor vai selecionar TODOS os elementos. Mas a gente consegue contornar isso. &lt;/p&gt;

&lt;h2&gt;
  
  
  4 –Olhando só para os primeiros
&lt;/h2&gt;

&lt;p&gt;No tópico anterior, aprendemos a olhar para todos menos para os primeiros com a notação nth-child(n + X). Podemos fazer o inverso disso, e mirar somente nos primeiros X elementos e não no resto.&lt;br&gt;
Para isso, usamos “-n”. Não se assuste, é tão fácil quanto os outros!&lt;/p&gt;

&lt;p&gt;Quando declaramos nth-child(-n), não vamos ver nada acontecendo. Isso porque por trás dos panos o CSS vai fazer numa lista, por exemplo, de 6 itens:&lt;/p&gt;

&lt;p&gt;nth-child(-n) =&amp;gt;&lt;br&gt;
nth-child(-1 * 0), logo nth-child(0);&lt;br&gt;
nth-child(-1 * 1), logo nth-child(-1);&lt;br&gt;
nth-child(-1 * 2), logo nth-child(-1);&lt;br&gt;
...&lt;br&gt;
nth-child(-1 * 6), logo nth-child(-6);&lt;br&gt;
...&lt;/p&gt;

&lt;p&gt;Como não temos elementos negativo no nth-child, nenhum será selecionado.&lt;/p&gt;

&lt;p&gt;Mas se somarmos ao “-n” uma quantidade X, podemos selecionar quantos elementos do início da lista nós quisermos!&lt;/p&gt;

&lt;p&gt;nth-child(-n + 3) =&amp;gt;&lt;br&gt;
nth-child(-1 * 0 + 3), logo nth-child(3);&lt;br&gt;
nth-child(-1 * 1 + 3), logo nth-child(2);&lt;br&gt;
nth-child(-1 * 2 + 3), logo nth-child(1);&lt;br&gt;
...&lt;br&gt;
nth-child(-1 * 6 + 3), logo nth-child(-3);&lt;br&gt;
...&lt;/p&gt;

&lt;p&gt;Note que nesse caso nós vamos selecionar os três primeiros elementos. Logo, podemos pensar que o seletor nth-child(-n + 3) está dizendo “selecionar todos, mas só até o terceiro elemento”.&lt;/p&gt;

&lt;p&gt;Veja ainda o exemplo abaixo:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/eYLqMPQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  5 –Montando nosso Megazord
&lt;/h2&gt;

&lt;p&gt;Agora estamos prontos para montar o nosso nth-child monstrão!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Njcyg0__--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ablqjf74w0a2sfx6lc46.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Njcyg0__--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ablqjf74w0a2sfx6lc46.jpg" alt='Meme com fisiculturista dizendo "Tá saindo da jaula o monstro"' width="800" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Digamos que a gente queira selecionar a partir do sétimo quadrado, e parar no décimo-quinto.&lt;/p&gt;

&lt;p&gt;Para fazer isso a gente pode encadear seletores nth-child!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container__square&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;7&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;15&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim, estamos falando pro CSS: “Vai lá, e pinta de verde todos os quadrados a partir do sétimo, mas não vá além do décimo quinto”.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/eYLqrmo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;E se agora nós quiséssemos fazer a mesma coisa, mas pulando um?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container__square&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;7&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;15&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marcelluscaio/embed/VwGoxjm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5ZpiXgnb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qgd6bzpk9lqufk9evxn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5ZpiXgnb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qgd6bzpk9lqufk9evxn.jpg" alt='Jesse Pinkman da série Breaking Bad falando "Ciência!"' width="600" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conseguimos!
&lt;/h3&gt;

&lt;p&gt;Aquele emaranhado que parecia indecifrável agora parece bem mais simpático, não é? &lt;/p&gt;

&lt;p&gt;Utilizando nth-child nos seus projetos você consegue criar seletores complexos sem poluir seu código com classes muito específicas, que tornariam difícil a inserção de novos elementos em uma lista, por exemplo.&lt;/p&gt;

&lt;p&gt;Parabéns por ter mais uma ferramenta no seu cinto de utilidades. &lt;/p&gt;

&lt;p&gt;Referências:&lt;/p&gt;

&lt;p&gt;:nth-child&lt;br&gt;
&lt;a href="https://css-tricks.com/almanac/selectors/n/nth-child/"&gt;https://css-tricks.com/almanac/selectors/n/nth-child/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;:nth-child()&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How does CSS nth-child() really work?&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=KIIktcWu6hc&amp;amp;ab_channel=WesBos"&gt;https://www.youtube.com/watch?v=KIIktcWu6hc&amp;amp;ab_channel=WesBos&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Entendendo CSS: Pseudo-Classes e Pseudo-Elementos&lt;br&gt;
&lt;a href="https://dev.to/sucodelarangela/entendendo-css-pseudo-classes-e-pseudo-elementos-b83"&gt;https://dev.to/sucodelarangela/entendendo-css-pseudo-classes-e-pseudo-elementos-b83&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mais 5 atalhos do VS Code que você precisa conhecer</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Fri, 17 Feb 2023 20:23:14 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/mais-5-atalhos-do-vs-code-que-voce-precisa-conhecer-2cnk</link>
      <guid>https://dev.to/marcelluscaio/mais-5-atalhos-do-vs-code-que-voce-precisa-conhecer-2cnk</guid>
      <description>&lt;p&gt;No &lt;a href="https://dev.to/marcelluscaio/3-atalhos-do-vs-code-que-voce-precisa-conhecer-1-bonus-3g5n"&gt;último post&lt;/a&gt; eu falei sobre alguns atalhos do VS Code que eu uso sempre. Como toda boa lista, ela teve ausências notáveis, ausências que vocês me ajudaram a compilar e a trazer nesse segundo post. Vamos lá!&lt;/p&gt;

&lt;h2&gt;
  
  
  Duplicando código
&lt;/h2&gt;

&lt;p&gt;Essa daqui foi uma que aprendi com vocês e não consigo parar de usar! Digamos que você vai fazer um card, e dentro dele tem 8 filhos. Uma forma de otimizar esse trabalho seria fazendo o primeiro e copiando ele 7 vezes. Todos os cards iguais, com a mesma estrutura, sem margem para erros. &lt;/p&gt;

&lt;p&gt;Dar Ctrl + C, Ctrl + V é a primeira solução que a gente pensa, mas e se eu te disser que tem uma forma ainda mais fácil de resolver isso?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Alt + Shift + ↑
Alt + Shift + ↓
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usando esse comando você copia uma bloco de código para cima ou para baixo, a depender da seta que apertou. Então para fazer o card, você só precisaria segurar o Alt + Shift e apertar a seta para baixo 7 vezes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Corrigindo e refatorando código
&lt;/h2&gt;

&lt;p&gt;Eis que você está revisando seu código e viu que precisava mudar o nome de uma classe. O que era “cartaozinho” vai virar “client-card”. Só que no seu HTML tem 10 elementos com essa classe. E o pior, como você é adepto da convenção BEM, dentro  desses elementos tem diversas classes “cartaozinho_&lt;em&gt;titulo”, “cartaozinho&lt;/em&gt;_numero”. E ainda têm todos os seletores no CSS... Desesperador, né?&lt;/p&gt;

&lt;p&gt;Não! Afinal você já leu este artigo, e você sabe como resolver sem ter que passar um pente fino à olho no código todo!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ctrl + F
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apertando esse comando você abre uma aba de pesquisa como essa:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgips7yieazbtbiqmyoxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgips7yieazbtbiqmyoxc.png" alt=" " width="504" height="93"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Agora é só você colocar que vai substituir cartaozinho por client-card, e o VS Code substitui um a um, ou todas as ocorrências. &lt;/p&gt;

&lt;p&gt;Para substituir caso a caso, aperte Enter. Se você tem confiança que não vai quebrar nada no código (ou se você é vidaloka #YOLO) você pode mudar todos de uma vez apertando Ctrl + Alt + Enter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Salvando
&lt;/h2&gt;

&lt;p&gt;Essa daqui é bem simples, mas vai que alguém não conhece, né? Para salvar o seu código sem ter que clicar em File &amp;gt; Save, você pode apertar Ctrl + S. Eu confesso que faço isso de forma quase obsessiva a cada alteração no código rs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Indentando código
&lt;/h2&gt;

&lt;p&gt;Indentar bem o código é fundamental para um código legível, e um código legível é o que diferencia um bom programador de um ótimo programador que está preparado para trabalhar em equipe.&lt;/p&gt;

&lt;p&gt;Para adicionar indentação ao código, selecione a seção e aperte Tab. Exagerou? Aperte Shift + Tab.&lt;/p&gt;

&lt;p&gt;Simples, mas essencial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Abrindo o terminal
&lt;/h2&gt;

&lt;p&gt;Não adianta fugir, você vai usar o terminal. Seja para instalar frameworks, bibliotecas ou para subir seu código para o GitHub. O VS Code ajuda bastante nessas tarefas com seu terminal integrado.&lt;br&gt;
Uma maneira de abrir ele é clicar em Terminal &amp;gt; New. Mas você pode fazer isso com uma só mão apertando Ctrl + J.&lt;/p&gt;

&lt;p&gt;Me conta, o que mais ficou faltando?&lt;/p&gt;

&lt;p&gt;Bons códigos!&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>3 atalhos do VS Code que você precisa conhecer (+ 1 bônus)</title>
      <dc:creator>Caio Marcellus Cabral</dc:creator>
      <pubDate>Wed, 18 Jan 2023 23:24:27 +0000</pubDate>
      <link>https://dev.to/marcelluscaio/3-atalhos-do-vs-code-que-voce-precisa-conhecer-1-bonus-3g5n</link>
      <guid>https://dev.to/marcelluscaio/3-atalhos-do-vs-code-que-voce-precisa-conhecer-1-bonus-3g5n</guid>
      <description>&lt;p&gt;Olá, pessoa. Espero que você esteja bem!&lt;/p&gt;

&lt;p&gt;Programar é muito mais que digitar código rápido. Planejar, estruturar e produzir código legível e de fácil manutenção são de longe características mais desejáveis em um programador que a velocidade para escrever o código em si.&lt;/p&gt;

&lt;p&gt;Ainda assim, convém ter algumas cartas na manga que acelerem alguns processos para a gente, ou que diminuam atividades repetitivas. Isso é quase um lema para nós programadores, né? Por isso vim aqui dividir com vocês as três funcionalidades do VS Code que eu uso sempre que estou programando&lt;/p&gt;

&lt;h2&gt;
  
  
  Comentar bloco de código
&lt;/h2&gt;

&lt;p&gt;A arte de comentar (ou não) o código rende um artigo à parte, mas não entraremos nessa seara: o fato é que todo mundo comenta o código em algum momento, seja como um recado para o seu eu do futuro, ou como uma instrução para outros devs, ou apenas para neutralizar alguns fragmentos do código durante um processo de &lt;del&gt;dedetização&lt;/del&gt; debugging. Para comentar um bloco de código, o VS Code tem dois atalhos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alt + shift + a

ctrl + /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Mover fragmento de código
&lt;/h2&gt;

&lt;p&gt;Suponhamos que você tomou pouco café, e que acabou colocando o seu footer antes do header. Uma solução possível é dar &lt;code&gt;ctrl + x&lt;/code&gt; para recortar o footer todo, e &lt;code&gt;ctrl + v&lt;/code&gt; para colar ele no lugar certo. Resolvido, muito bom.&lt;/p&gt;

&lt;p&gt;Você também poderia fazer isso usando os atalhos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alt + ↑
alt + ↓
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Você pode usar eles em uma linha ou bloco de código. Se for uma linha, não precisa selecionar ela inteira. O atalho vai funcionar só de estar com o cursor nela. É ótimo para fazer pequenos ajustes, e movimentar blocos de código, reordenar listas, tirar ou colocar um elemento dentro de outro, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alterar múltiplas linhas
&lt;/h2&gt;

&lt;p&gt;Esse daqui é o meu favorito. Imagine que você estruturou sua navbar toda bonitinha. De repente você percebe que não colocou o href dentro da tag a. Bateu um desânimo? Não precisa mais chorar! O VS Code tem os seguintes atalhos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctrl + d
alt + click
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Com esses atalho você pode multiplicar o seu cursor e alterar, acrescentando ou apagando, diversas linhas de código ao mesmo tempo. Nesse caso, teríamos duas alternativas:&lt;br&gt;
1) Selecionar a tag &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; clicando e arrastando o mouse, e apertar o &lt;code&gt;ctrl + d&lt;/code&gt; até que todas estejam selecionadas. Então você digita o href somente uma vez para todas.&lt;br&gt;
2) Você poderia ainda segurar o &lt;code&gt;alt&lt;/code&gt; e clicar em todas as linhas que quer alterar. Estando com todas selecionadas, é só inserir a informação que ficou faltando.&lt;/p&gt;

&lt;p&gt;Depois de ter feito isso, é só apertar o &lt;code&gt;esc&lt;/code&gt; que tudo volta ao normal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eu prometi um bônus, né?
&lt;/h2&gt;

&lt;p&gt;Essa não vale pelo atalho em si, mas para acessar outros atalhos do VS Code. Utilizando &lt;code&gt;ctrl + shit + p&lt;/code&gt; e digitando "Open Keyboard Shortcuts" você tem acesso a uma lista vertiginosa de atalhos. Divirta-se.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
