<?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: mikkel250</title>
    <description>The latest articles on DEV Community by mikkel250 (@mikkel250).</description>
    <link>https://dev.to/mikkel250</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%2F99096%2Fce1b9981-f017-4c29-965b-bbca5fd2b5d3.jpg</url>
      <title>DEV Community: mikkel250</title>
      <link>https://dev.to/mikkel250</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mikkel250"/>
    <language>en</language>
    <item>
      <title>CSS notes and references</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 01:21:56 +0000</pubDate>
      <link>https://dev.to/mikkel250/css-notes-and-references-352m</link>
      <guid>https://dev.to/mikkel250/css-notes-and-references-352m</guid>
      <description>&lt;h3&gt;
  
  
  CSS
&lt;/h3&gt;

&lt;p&gt;These are my notes from the fantastic (free!) &lt;a href="https://frontendmasters.com/bootcamp/introduction-css/"&gt;course&lt;/a&gt; on CSS in the Frontend Masters' &lt;a href="https://frontendmasters.com/bootcamp/"&gt;bootcamp&lt;/a&gt;. Definitely check it out, I wish I'd known about it when I was starting out. &lt;/p&gt;

&lt;h4&gt;
  
  
  Basics
&lt;/h4&gt;

&lt;p&gt;All html elements are boxes. A great way to see what you are doing is to give elements borders. Then you can see exactly how large they are and where they lay on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parents and children:&lt;/strong&gt;&lt;br&gt;
The property of a parent will affect the children (for the most part, depending on the selector, e.g. most font properties), unless they are overridden:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hi&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;with the style of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&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;blue&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;will make the text color of the &lt;code&gt;h1&lt;/code&gt; blue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Specificity&lt;/strong&gt;&lt;br&gt;
The more specific the selector, the higher precedence it will have.&lt;/p&gt;

&lt;p&gt;You can chain classes together without a space to increase specificity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.main-brand.title-5&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;span class="nc"&gt;.main-brand&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;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;In the above, the first selector (with two classes) will be applied, even though it is higher in the cascade (literally higher in the file), because it has two classes, and is therefore more specific.&lt;/p&gt;

&lt;p&gt;The ID selector takes the highest precedence and will override any other selector. &lt;br&gt;
The !important flag will override anything else, including ID's.&lt;br&gt;
For these reasons, it's generally better not to use either ID or !important - use classes (by adding a second class or combine classes and tags) to get more specific so they can then be overridden later if necessary without too much effort (or using ID's or !important). It makes styling much easier if everything uses one class, and occasionally two classes (if necessary).&lt;/p&gt;

&lt;p&gt;Descendant Selectors&lt;br&gt;
Another trick that can be used if there aren't that many elements on a page, or if they are fairly deeply nested, is combining type selectors (but it's generally easier to just add a class). To do this, chain the selectors together with spaces:&lt;br&gt;
&lt;code&gt;div ul li { color: red; }&lt;/code&gt; will only select an &lt;code&gt;li&lt;/code&gt; element that is inside a &lt;code&gt;ul&lt;/code&gt; element, that is inside a &lt;code&gt;div&lt;/code&gt;.&lt;br&gt;
However, using descendant selectors is not very specific (another reason to use classes), but can be made more so with the &lt;code&gt;&amp;gt;&lt;/code&gt; symbol:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* selects ANY paragraph that inside ANY div, no matter how deeply nested */&lt;/span&gt;
&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nt"&gt;p&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;span class="nt"&gt;div&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* will only select a p tag directly inside a div (first child) */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The reason to avoid using these is if someone ever changes the structure of the page (or the tags), your CSS will break. A class can remain on any element, regardless of type, at any position on the page.&lt;/p&gt;

&lt;p&gt;Specificity is calculated&lt;br&gt;
Note that the specificity is based on number values, which can be researched for more granular control if necessary, but the broad strokes are that CSS specificity can be thought of in the following order (lowest to highest specificity):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Type selctors (tags: &lt;code&gt;h1&lt;/code&gt;) and Pseudo elements &lt;code&gt;::before&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Classes &lt;code&gt;.main&lt;/code&gt;, attributes &lt;code&gt;[type="radio"]&lt;/code&gt;, and Pseudo Classes &lt;code&gt;:hover&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;ID selectors &lt;code&gt;#hero-image&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Inline styles always override any external style sheets.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!important&lt;/code&gt; overrides everything else.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To learn more, Emma Bostonian wrote a great article on it at &lt;a href="https://dev.to/emmabostian/css-specificity-1kca"&gt;https://dev.to/emmabostian/css-specificity-1kca&lt;/a&gt;&lt;br&gt;
This includes the math for how to calculate specificity which can be helful if you're having trouble.&lt;br&gt;
Another great resource is the 'specifishity' chart at &lt;a href="http://www.standardista.com/css3/css-specificity/"&gt;http://www.standardista.com/css3/css-specificity/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pseudo Classes&lt;/strong&gt;&lt;br&gt;
These come after the selector, with no space, and a colon at the beginning. They are most commonly used for interactivity (things like links):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:hover&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;Other handy Pseudo Classes&lt;br&gt;
&lt;code&gt;:focus&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:visited&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:active&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:checked&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:first-child&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:last-child&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:nth-child(3)&lt;/code&gt; put in the child number in the parentheses&lt;br&gt;
...and more that can be googled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pseudo elements&lt;/strong&gt;&lt;br&gt;
Not as frequently used, but handy to know.&lt;br&gt;
The &lt;code&gt;::before&lt;/code&gt; and &lt;code&gt;::after&lt;/code&gt; pseudo-elements in CSS allows you to insert content onto a page without it needing to be in the HTML. While the end result is not actually in the DOM, it appears on the page as if it is, and would essentially be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"before"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;::after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"after"&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;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  before
  &lt;span class="c"&gt;&amp;lt;!-- Rest of stuff inside the div --&amp;gt;&lt;/span&gt;
  after
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Layout
&lt;/h4&gt;

&lt;p&gt;CSS is used not just to style elements but to lay out the page how it should look.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block level elements&lt;/strong&gt; always start on a new line and automatically span the width of their containers (think: building block).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inline elements&lt;/strong&gt; (e.g. the &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;em&lt;/code&gt;, and &lt;code&gt;strong&lt;/code&gt; tags) only take up the amount of space required to hold their content: the &lt;code&gt;&amp;lt;a&amp;gt;hello&amp;lt;/a&amp;gt;&lt;/code&gt; tag will only take up exactly the amount of space to enclose the word 'hello'.&lt;br&gt;
Another noteworthy feature of inline elements is that padding and margins can only be added to the sides, not the top and bottom.&lt;br&gt;
This property can be manually changed by using &lt;code&gt;display: block;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using the property &lt;code&gt;display: inline-block;&lt;/code&gt; does not add a line-break after the element, so the element can sit next to other elements, and allows to set a width and height on the element. In practice, this method is commonly used to get items to appear in a row as opposed to a column, as in a navbar with a &lt;code&gt;ul&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To make sure the document is always correctly sized to the window with no overlap or scrollbars is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;*,&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:before&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inherit&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;Display properties&lt;br&gt;
All tags have a default display property, that then can be overridden using CSS.&lt;br&gt;
&lt;code&gt;block&lt;/code&gt; spans the entire width of the container.&lt;br&gt;
&lt;code&gt;inline&lt;/code&gt; is only as large as its text.&lt;br&gt;
&lt;code&gt;inline-block&lt;/code&gt; is a hybrid of the previous two. The browser will place the tag inline, but will still allow you to control the height, width, padding, and margins (whereas an inline element does not allow any modifications to the height propery).&lt;br&gt;
&lt;code&gt;flex&lt;/code&gt; and &lt;code&gt;inline-flex&lt;/code&gt; are similar to block in that they affect the tags around them like &lt;code&gt;block&lt;/code&gt; (covered in depth later).&lt;br&gt;
&lt;code&gt;grid&lt;/code&gt; and &lt;code&gt;inline-grid&lt;/code&gt; are more advanced display modes like &lt;code&gt;flex&lt;/code&gt; (covered later), but only supported by relatively modern browsers.&lt;br&gt;
&lt;code&gt;table&lt;/code&gt; will make something act like a table (even if it's not a table). Generally, it's better to use &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; in the HTML for this.&lt;/p&gt;
&lt;h4&gt;
  
  
  Width and Height
&lt;/h4&gt;

&lt;p&gt;Width&lt;br&gt;
Using percents is an easy way to divide up the width of a page or section (because the math is easy to do in your head), and the percentage will be relative to the size of the container.&lt;/p&gt;

&lt;p&gt;Height&lt;br&gt;
Elements/boxes have a height property as well, but a generally good practice is to not set the height property manually, but to set the height and use &lt;code&gt;auto&lt;/code&gt; for the width, which will allow it to resize and be responsive. Another reason is that setting the height manually won't allow for the container to expand if, say a bunch of content is added after originally styling it.&lt;br&gt;
One exception is when a div contains only an image, since there is no other content to give the element height, it must contain a height in order for the image to appear (i.e. if you have a 300px image, set the container to 300px).&lt;/p&gt;
&lt;h4&gt;
  
  
  Margin and Padding
&lt;/h4&gt;

&lt;p&gt;Padding is around the content, up to the border.&lt;br&gt;
Margin is the spacing between the border and the next element.&lt;br&gt;
By default, the &lt;code&gt;width&lt;/code&gt; property does &lt;strong&gt;not&lt;/strong&gt; include border and padding (just the content), so it's very handy to declare at the top of every CSS file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&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 will make it so that all width measurements include both the padding &lt;strong&gt;and&lt;/strong&gt; the border.&lt;/p&gt;

&lt;p&gt;To quickly center all content within the parent, use &lt;code&gt;margin: 0 auto;&lt;/code&gt;. The shorthand here is: &lt;code&gt;margin: top/bottom, left/right;&lt;/code&gt;, but it can also be set with 4 values - Top Right Bottom Left (TRBL, mnemonic 'TRouBLe'), and is the equivalent of &lt;code&gt;margin: 0 auto 0 auto;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Float and Clear
&lt;/h4&gt;

&lt;p&gt;Floats will move an element to the side of the page, and the next element will 'stick' to the side that has the open space. &lt;br&gt;
Floats feature rows and cells. Rows clear the floats on the cells. The source order determines the display, and is fairly limited as to options. All cells are equal heights. &lt;br&gt;
One thing to note is that if there other elements below the next one, they will never be higher than the height of the preceding element, no matter how large the screen size (e.g. if box 1 is floated left, and two more boxes, box 3 will never be higher on the page than box 2).&lt;br&gt;
&lt;code&gt;float: left;&lt;/code&gt;, and &lt;code&gt;float: right;&lt;/code&gt; are how they are declared.&lt;br&gt;
If you float, then you need to clear!&lt;br&gt;
There is an 'incantation' (aka a formula) that is commonly used to make sure that the parent element that contains any floats will not have elements that end up outside the container (clearing the floats). It is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;parentSelector&lt;/span&gt;&lt;span class="nd"&gt;::after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;""&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;table&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;both&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;If you need to rearrange the columns for some reason, this can be accomplished with another incantation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;class&lt;/span&gt;&lt;span class="o"&gt;*=&lt;/span&gt;&lt;span class="s1"&gt;"col-"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

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



&lt;h4&gt;
  
  
  Flexbox
&lt;/h4&gt;

&lt;p&gt;Flexbox only works with parents and children, known as the flex container and items respectively. It does not work with descendants or ancestors beyond parents/children. A common use case is using a &lt;code&gt;ul&lt;/code&gt; to make a navbar.&lt;br&gt;
Most changes to flex are made on the parent container, not the items themselves.&lt;br&gt;
The main axis is the direction of the flexbox: for columns, it's up to down, and for rows it's left to right. The cross axis is the dimension perpendicular to the main axis.&lt;br&gt;
For some older browsers, prefixes are required, so check canIuse.com to see if it's necessary. &lt;/p&gt;

&lt;p&gt;All properties can be found here: &lt;a href="https://static.frontendmasters.com/resources/2017-10-03-responsive-web-design-flexbox-css-grid/Flexbox-and-CSS-Grid-Properties-Cheat-Sheet.pdf"&gt;https://static.frontendmasters.com/resources/2017-10-03-responsive-web-design-flexbox-css-grid/Flexbox-and-CSS-Grid-Properties-Cheat-Sheet.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some useful properties are:&lt;br&gt;
&lt;strong&gt;On the container&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;display: flex;&lt;/code&gt; set on the container to make the items go into a row.&lt;br&gt;
&lt;code&gt;flex-flow: column;&lt;/code&gt; to change this to a stacked list.&lt;br&gt;
&lt;code&gt;flex-flow: row wrap;&lt;/code&gt; manually sets the items in a row, and wrap them to new lines.&lt;br&gt;
&lt;code&gt;flex-flow: nowrap;&lt;/code&gt; will prevent the items from ever wrapping to a new line.&lt;br&gt;
&lt;code&gt;flex-direction: row-reverse;&lt;/code&gt; will reverse the order of the elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;justify-content&lt;/code&gt; has a number of properties that can be set, and controls the way the items are laid out, some of which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;justify-content: flex-start;&lt;/code&gt; sets the items to hug the left side of the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;justify-content: flex-end;&lt;/code&gt; sets the items to hug the right side of the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;justify-content: center;&lt;/code&gt; centers the items in the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;justify-content: space-around;&lt;/code&gt; sets evenly sized spaces on the left and right of each of the items, including the start and ending items.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;justify-content: space-between;&lt;/code&gt; sets an even amount of space only between items.
&lt;code&gt;justify-content: space-evenly;&lt;/code&gt; will evenly space everything.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;align-items:&lt;/code&gt; will align the items on the cross axis to the flex-direction. It has the &lt;code&gt;flex-end&lt;/code&gt;, &lt;code&gt;flex-start&lt;/code&gt; properties. &lt;br&gt;
There is also &lt;code&gt;flex-center&lt;/code&gt;, which centers them in the parent, and &lt;code&gt;stretch&lt;/code&gt; which will modify the height of anything that doesn't explicitly have a height set to fit the parent. It also has a neat feature where all elements that doesn't explicitly have a height set will stretch to match the height of the tallest element that &lt;em&gt;does&lt;/em&gt; have a height set.&lt;/p&gt;

&lt;p&gt;Centering with flexbox&lt;br&gt;
To make sure everything stays centered (text inside the items, and the items themselves), set&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.centered-box&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;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="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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and no matter what the width or height of the parent, the items and content will stay centered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manipulating the items&lt;/strong&gt;&lt;br&gt;
Shorthand&lt;br&gt;
The shorthand property for this is to use &lt;code&gt;flex:&lt;/code&gt; followed by the values for &lt;code&gt;Grow Shrink Basis&lt;/code&gt;, or they can be written out individually. &lt;br&gt;
&lt;code&gt;flex-grow: value;&lt;/code&gt; where the value is how much the unit will grow relative to the other units as the screen size changes. The default is that they all resize equally.&lt;br&gt;&lt;br&gt;
&lt;code&gt;flex-shrink: value;&lt;/code&gt;, is the same as the above, but for when the items are shrinking. &lt;br&gt;
&lt;code&gt;flex-basis: value;&lt;/code&gt; is the width of the items, where the values are some unit of measure (commonly percentages or viewport units). Never use width on flex items, use &lt;code&gt;flex-basis&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;Order&lt;br&gt;
Using &lt;code&gt;order&lt;/code&gt; you can individually override align-items using &lt;code&gt;align-self&lt;/code&gt;, definitely worth looking at more:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;align-self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex-end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;order&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;span class="c"&gt;/* the higher the number the earlier direction it will appear */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;On the items:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;flex-basis: 10%;&lt;/code&gt; will override the default box sizing and set it to roughly 10% of the total size of the container instead.&lt;/p&gt;
&lt;h4&gt;
  
  
  Patterns for writing CSS
&lt;/h4&gt;

&lt;p&gt;Write all of the default styles for multiple elements first, then add the specific styles for each element in their own selectors futher down in the file. E.g. if you have a number of button types on a page/site, and you want them all to have similar properties (size, font, border, etc.), then write those general rules for all buttons, then add the specific (or override) styles later in the CSS file (ideally with comments):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.ex-btn&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="m"&gt;#eee&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;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#aaa&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;4px&lt;/span&gt; &lt;span class="m"&gt;15px&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="nb"&gt;bold&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;17px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.ex-btn-warn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* inherits from .ex-btn */&lt;/span&gt;
  &lt;span class="c"&gt;/* above comment shows where to look for default styles */&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;white&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;crimson&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;darkred&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.ex-btn-success&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* inherits from .ex-btn */&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;white&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;limegreen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-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;Another neat trick to quickly change styles is to right click on the element and choose 'inspect element'. In the devtools, you can turn styles on or off, and in the 'This Element' box, even add styles. Once it looks the way you want, you can just copy and paste the code from the 'This Element' box into the editor, which allows for quick iteration.&lt;br&gt;
In the 'Computed' tab, it will show the exact values of the content, paddding, border, and margins. The values can be clicked on and modified directly as well.&lt;br&gt;
There's even a color dropper tool that can be used to find out a color on a page (in Firefox at least, in Chrome it shows up in the popup when using 'inspect element')&lt;/p&gt;

&lt;p&gt;Interesting properties:&lt;br&gt;
There is a a text-decoration: overline property (a line above like underline).&lt;/p&gt;

&lt;h4&gt;
  
  
  Resources
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://htmlcheatsheet.com/css/"&gt;https://htmlcheatsheet.com/css/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://frontendmasters.github.io/bootcamp/css"&gt;https://frontendmasters.github.io/bootcamp/css&lt;/a&gt;&lt;br&gt;
&lt;a href="https://frontendmasters.com/bootcamp/introduction-css/"&gt;https://frontendmasters.com/bootcamp/introduction-css/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;list of all css properties:&lt;br&gt;
&lt;a href="https://meiert.com/en/indices/css-properties/"&gt;https://meiert.com/en/indices/css-properties/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://css-tricks.com/nerds-guide-color-web/"&gt;https://css-tricks.com/nerds-guide-color-web/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tools:&lt;br&gt;
BrowserStack at &lt;a href="https://www.browserstack.com/"&gt;https://www.browserstack.com/&lt;/a&gt; can test your CSS for compatibility across browsers.&lt;br&gt;
ColorZilla extension lets you pick colors you see on screen and will give you the hex, rgb, etc. color values.&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Functions in Sass</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 01:04:00 +0000</pubDate>
      <link>https://dev.to/mikkel250/functions-in-sass-g9n</link>
      <guid>https://dev.to/mikkel250/functions-in-sass-g9n</guid>
      <description>&lt;p&gt;The final piece of the puzzle is functions.&lt;br&gt;
Defining a function in Sass is similar to the syntax for a mixin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// a variable that holds a value for use later&lt;/span&gt;
&lt;span class="nv"&gt;$w&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// defining the function&lt;/span&gt;
&lt;span class="k"&gt;@function&lt;/span&gt; &lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@return&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.thin-border&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$w&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;  &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="n"&gt;border-width&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.thick-border&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt; &lt;span class="n"&gt;border-width&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using function and combining them with other features of Sass, such as conditionals, allows for great flexibility when coding your CSS. &lt;/p&gt;

&lt;p&gt;Hope you enjoyed this series! If you want more details and experience practicing the syntax with exercises, check out the course on which these notes are based &lt;a href="https://frontendmasters.com/courses/sass"&gt;here&lt;/a&gt; at Frontend Masters, and big thanks to them and Mike North such great material!&lt;/p&gt;

</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Reusing style with mixins</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:59:52 +0000</pubDate>
      <link>https://dev.to/mikkel250/reusing-style-with-mixins-lea</link>
      <guid>https://dev.to/mikkel250/reusing-style-with-mixins-lea</guid>
      <description>&lt;p&gt;There are a few different ways to extend styles with Sass, some of which have been covered in this series already. We'll cover some new concepts by first going over each and how they behave in order to understand the new syntax and why it might be used. &lt;/p&gt;

&lt;h5&gt;
  
  
  include
&lt;/h5&gt;

&lt;p&gt;The first way to extend a style is using a mixin and using &lt;code&gt;@include&lt;/code&gt; to bring it into other styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// using @include&lt;/span&gt;
&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;danger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt; &lt;span class="n"&gt;parentheses&lt;/span&gt; &lt;span class="n"&gt;even&lt;/span&gt; &lt;span class="n"&gt;if&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;passed&lt;/span&gt; &lt;span class="n"&gt;in&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;2px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.alert-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;danger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="err"&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;100%&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// compiles to CSS&lt;/span&gt;
&lt;span class="nc"&gt;.btn-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&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;2px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.alert-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&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;100%&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that the things that are common to both (defined in the mixin) are included in both CSS rules, which is not particularly DRY and could end up bloating your CSS file.&lt;/p&gt;

&lt;h5&gt;
  
  
  extend
&lt;/h5&gt;

&lt;p&gt;The second way to is by using &lt;code&gt;@extend&lt;/code&gt;. You can define the common elements in a 'parent' style rule and add specific tweaks as needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// using @extend&lt;/span&gt;
&lt;span class="nc"&gt;.danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@extend&lt;/span&gt; &lt;span class="nc"&gt;.danger&lt;/span&gt;&lt;span class="o"&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;2px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.alert-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@extend&lt;/span&gt; &lt;span class="nc"&gt;.danger&lt;/span&gt;&lt;span class="o"&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;100%&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// compiles to CSS&lt;/span&gt;
&lt;span class="nc"&gt;.danger&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.btn-danger&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.alert-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.btn-danger&lt;/span&gt; &lt;span class="err"&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;2px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.alert-danger&lt;/span&gt; &lt;span class="err"&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;100%&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This method works great, and results in much DRYer code and smaller CSS files. The problem with this method is if &lt;code&gt;@extend&lt;/code&gt; is used in different places, and someone changes the danger style, it will affect the entire app wherever &lt;code&gt;@extend&lt;/code&gt; was used, and this may not be immediately clear that would be the case, especially if the styles are spread out over different files and partials throughout the app.&lt;/p&gt;

&lt;h5&gt;
  
  
  Introducing: Placeholder
&lt;/h5&gt;

&lt;p&gt;In order to deal with this potential problem with @extend, Sass has a way to let everyone working on the app know that a style is meant to be extended: placeholders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// with placeholders&lt;/span&gt;
&lt;span class="nv"&gt;%danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@extend&lt;/span&gt; &lt;span class="nv"&gt;%danger&lt;/span&gt;&lt;span class="o"&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;2px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.alert-danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@extend&lt;/span&gt; &lt;span class="nv"&gt;%danger&lt;/span&gt;&lt;span class="o"&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;100%&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

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



&lt;p&gt;The compiled CSS looks the same as the previous example using &lt;code&gt;@extend&lt;/code&gt; on a regular class, but it lets everyone know that danger is meant to be extended and to check before making changes. Using placeholders and extend are a great way to pass in style rules that don't require any variables.&lt;/p&gt;

&lt;p&gt;There are some caveats to note when using @extend. &lt;br&gt;
First, if there are multiple layers of nesting in your Sass (especially if each layer has multiple selectors in it), using @extend can cause the size of your CSS to blow up very quickly because nearly every permutation of each selector will be created in the compiled CSS, so keep an eye on it and consider breaking out classes into separate rules if this happens. The takeaway: be careful with nesting, and don't nest too deep, even if it means making your Sass file a bit longer, and a bit more work for you at the outset. The final product will have better performance and happier users.&lt;br&gt;
Second, always use placeholders with @extend, even if it means having to create a separate class and bringing in @extend there, because this will avoid unintended changes later. I.e. if you wanted to create a parent &lt;code&gt;.danger&lt;/code&gt; class, do it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// with placeholders&lt;/span&gt;
&lt;span class="nv"&gt;%danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="err"&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;white&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.danger&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@extend&lt;/span&gt; &lt;span class="nv"&gt;%danger&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>architecture</category>
    </item>
    <item>
      <title>BEM CSS Architecture and Sass</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:53:22 +0000</pubDate>
      <link>https://dev.to/mikkel250/bem-css-architecture-and-sass-1c60</link>
      <guid>https://dev.to/mikkel250/bem-css-architecture-and-sass-1c60</guid>
      <description>&lt;h3&gt;
  
  
  BEM
&lt;/h3&gt;

&lt;p&gt;BEM is a way of architecting your html in such a way that you can use a conventional set of classes in your CSS to style your pages using a system/convention. The way I think about it is that you group sections of the page together in a way that makes sense, and apply flags or toggles to the html in order to apply styles to it. &lt;/p&gt;

&lt;p&gt;BEM stands for Block Element Modifier:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Block: a standalone entity, meaningful on its own (e.g. header, container, menu, checkbox, input, button).&lt;/li&gt;
&lt;li&gt;Element: a part of a block that has no standalone meaning and is semantically tied to its block (e.g. menu-item, list-item, header-title).&lt;/li&gt;
&lt;li&gt;Modifier: a flag on a block or element, used to change appearance and/or behavior (e.g. disabled, highlighted, checked, size-big, color-yellow).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a convention for BEM elements: double underscores after the block name indicates you're defining an element inside a block, and double dashes mean that you're defining a modifier. In the &lt;code&gt;label&lt;/code&gt; element below is an example of an element inside a block (&lt;code&gt;textfield__label&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;textfield&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"first-name"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"textfield__label"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    First Name
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"first-name"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"textfield__input"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The use of this convention prevents collision with other elements because it is unlikely that another element will have the same class. Sass makes building these easier because of the ability to use the parent selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nc"&gt;.textfield&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;__input&lt;/span&gt; &lt;span class="err"&gt;{}&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;__label&lt;/span&gt; &lt;span class="err"&gt;{}&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;__validation-error&lt;/span&gt; &lt;span class="err"&gt;{}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Continuing with the html example from above, the html would then look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;textfield&lt;/span&gt; &lt;span class="na"&gt;textfield--state--validated&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"first-name"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"textfield__label"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    First Name
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"first-name"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"textfield__input"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"texfield__validation-error"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Must be two characters or longer
  &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that because the parent selector can only be used once, there is a specific way to write the rules for the block element itself, which is why the &lt;code&gt;textfield&lt;/code&gt; appears after the parent selector in the modifiers below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nc"&gt;.textfield&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;.textfield--state-error&lt;/span&gt; &lt;span class="err"&gt;{}&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;.textfield--state-validated&lt;/span&gt; &lt;span class="err"&gt;{}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Sass Data Structures</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:46:08 +0000</pubDate>
      <link>https://dev.to/mikkel250/sass-data-structures-168l</link>
      <guid>https://dev.to/mikkel250/sass-data-structures-168l</guid>
      <description>&lt;h5&gt;
  
  
  Lists
&lt;/h5&gt;

&lt;p&gt;A list is an ordered collection (aka an array) separated by either spaces or commas, but it's best to pick one stick to it. Mixing spaces and commas will end up creating lists within lists, which may not have been intentional. The syntax looks very similar to a property list, and is intended to mirror CSS, which, for example, will have a mix of space and comma separated values for multiple shadows, which can be read about &lt;a href="https://css-tricks.com/almanac/properties/b/box-shadow/#article-header-id-3"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;Lists are NOT zero indexed, they are one indexed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;@each&lt;/code&gt; loop is a handy way to iterate through lists because it is a bit more flexible than a for loop: it will run once for each item in the list, regardless of size. The syntax for lists below creates a new block comment for each item in the list inside the &lt;code&gt;foo&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lists&lt;/span&gt;
&lt;span class="nv"&gt;$myList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="mh"&gt;#000&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// results in [0, 0, 2px, #000]&lt;/span&gt;

&lt;span class="c1"&gt;// if a comma was added, and more values with spaces:&lt;/span&gt;
&lt;span class="nv"&gt;$myList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="mh"&gt;#000&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// results in [0, 0, 2px, #000, [1, 2, 3]]&lt;/span&gt;

&lt;span class="nc"&gt;.foo&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@each&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$myList&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* #{$i} */
&lt;/span&gt;  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  nth
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;nth&lt;/code&gt; is another familiar term from programming, which is a method on a list that has two parameters: the list of values (array), and the item to pluck out (i.e. the nth index). Note that like lists, nth is NOT zero indexed, it is one indexed. Note that in some cases, the parentheses are optional, but for clarity and to avoid unexpected results, it may be best to default to using them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nv"&gt;$gradients&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;left&lt;/span&gt; &lt;span class="nt"&gt;top&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;left&lt;/span&gt; &lt;span class="nt"&gt;top&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;yellow&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;.foo&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// sets the linear gradient to the second item &lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;nth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$gradients&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// sets the background to the second item in the gradients list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Maps
&lt;/h5&gt;

&lt;p&gt;Maps are &lt;code&gt;key: value&lt;/code&gt; pairs, like objects in JS or hashmaps in many other languages. They resemble CSS property value combinations, which, after all, are key: value pairs themselves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nv"&gt;$myMap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="na"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#009&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt; &lt;span class="n"&gt;light&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#66f&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;theme-button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* Theme: #{$t} */
&lt;/span&gt;  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;map-get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$myMap&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn-dark&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;theme-button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dark"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// CSS&lt;/span&gt;
&lt;span class="nc"&gt;.btn-dark&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* Theme: dark */
&lt;/span&gt;  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#009&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>stylesheets</category>
    </item>
    <item>
      <title>Sass Control Flow</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:42:30 +0000</pubDate>
      <link>https://dev.to/mikkel250/sass-control-flow-1085</link>
      <guid>https://dev.to/mikkel250/sass-control-flow-1085</guid>
      <description>&lt;h5&gt;
  
  
  If Else
&lt;/h5&gt;

&lt;p&gt;Sass gives more control flow than CSS, beginning with the form of &lt;code&gt;@if&lt;/code&gt; and &lt;code&gt;@else&lt;/code&gt;. Based on the results of the control flow, the Sass will compile to different CSS based on the conditions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&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="nv"&gt;$size&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;@if&lt;/span&gt; &lt;span class="nv"&gt;$size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt; &lt;span class="err"&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="nv"&gt;$size&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt; &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nt"&gt;else&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// @else shown as syntax demo, no need for it here&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.small&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;14px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.large&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;foo&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="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// compiles to CSS&lt;/span&gt;
&lt;span class="nc"&gt;.small&lt;/span&gt; &lt;span class="err"&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;14px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.large&lt;/span&gt; &lt;span class="err"&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;24px&lt;/span&gt;&lt;span class="err"&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;24px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you work with any other programming language, this should look  familiar, just note that there are no parentheses around the condition following the @if keyword. &lt;/p&gt;

&lt;h5&gt;
  
  
  For loops
&lt;/h5&gt;

&lt;p&gt;Sass also provides a &lt;code&gt;for&lt;/code&gt; loop that can be used for control flow and automate repetitive tasks. Some things to note are that for loops can be either inclusive or exclusive, depending on how it is written. Using &lt;code&gt;through&lt;/code&gt; is inclusive. Using &lt;code&gt;to&lt;/code&gt; is exclusive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="k"&gt;@for&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="ow"&gt;from&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;through&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
 &lt;span class="c1"&gt;// inclusive&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@for&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="ow"&gt;from&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;to&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
 &lt;span class="c1"&gt;// exclusive&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The syntax of how to create style rules for different font sizes for the various &lt;code&gt;h&lt;/code&gt; tags based on some simple math is shown below. On the second line of the example below, the &lt;code&gt;#{$i}&lt;/code&gt; is interpolation, which tacks on the value of &lt;code&gt;i&lt;/code&gt; after the &lt;code&gt;h&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="k"&gt;@for&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="ow"&gt;from&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;through&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;h&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="err"&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;5rem&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="mi"&gt;.75rem&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// compiles to CSS &lt;/span&gt;
&lt;span class="na"&gt;h1&lt;/span&gt;&lt;span class="err"&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;4&lt;/span&gt;&lt;span class="mi"&gt;.25rem&lt;/span&gt;&lt;span class="err"&gt;;}&lt;/span&gt;
&lt;span class="na"&gt;h2&lt;/span&gt;&lt;span class="err"&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;3&lt;/span&gt;&lt;span class="mi"&gt;.5rem&lt;/span&gt;&lt;span class="err"&gt;;}&lt;/span&gt;
&lt;span class="na"&gt;h3&lt;/span&gt;&lt;span class="err"&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;2&lt;/span&gt;&lt;span class="mi"&gt;.75rem&lt;/span&gt;&lt;span class="err"&gt;;}&lt;/span&gt;
&lt;span class="na"&gt;h4&lt;/span&gt;&lt;span class="err"&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;2rem&lt;/span&gt;&lt;span class="err"&gt;;}&lt;/span&gt;
&lt;span class="na"&gt;h5&lt;/span&gt;&lt;span class="err"&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;1&lt;/span&gt;&lt;span class="mi"&gt;.25rem&lt;/span&gt;&lt;span class="err"&gt;;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Another good application of a loop might be if a grid system is used, a more DRY method could use a loop to generate the values instead of repeatedly writing the measurement values, and later being able to change the values once and have them reflected everywhere.&lt;/p&gt;

&lt;h5&gt;
  
  
  Each
&lt;/h5&gt;

&lt;p&gt;Another loop which can be used is &lt;code&gt;@each&lt;/code&gt;, which is used to iterate over lists, which will be covered in the next installment in this series. The syntax is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="k"&gt;@each&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$myList&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* your code */ 
&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>stylesheets</category>
    </item>
    <item>
      <title>Sass Functions</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:38:49 +0000</pubDate>
      <link>https://dev.to/mikkel250/sass-functions-j6e</link>
      <guid>https://dev.to/mikkel250/sass-functions-j6e</guid>
      <description>&lt;h4&gt;
  
  
  Functions in Sass
&lt;/h4&gt;

&lt;p&gt;The full list of functions is available in the Sass docs. Only the ones likely to be frequently used will be covered here.&lt;br&gt;
The builtin functions are written in C, and so performance concerns are not a big factor when deciding whether to use them. Functions that are written by us as developers do not necessarily share this trait, so it's something to bear in mind when writing and using your own functions. More on functions:&lt;br&gt;
&lt;a href="https://sass-lang.com/documentation/at-rules/function"&gt;https://sass-lang.com/documentation/at-rules/function&lt;/a&gt;&lt;br&gt;
and the complete list of built-ins: &lt;br&gt;
&lt;a href="https://sass-lang.com/documentation/modules"&gt;https://sass-lang.com/documentation/modules&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that an entire series on just colors could be written, so use Google to find out more about colors if necessary. A good place to start would be &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Applying_color"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Applying_color&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Color functions
&lt;/h5&gt;

&lt;h5&gt;
  
  
  Creating color
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nt"&gt;rgb&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;green&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;rgba&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;green&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;green&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;mix&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;weight&lt;/span&gt;&lt;span class="o"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above are pretty self-explanatory given the function names and variable names, but research them if needed, to learn more. Some of the more complicated functions are outlined below to get an idea of how functions work.&lt;/p&gt;

&lt;h5&gt;
  
  
  adjust-hue
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nt"&gt;adjust-hue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;#63f&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;60deg&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;adjust-hue takes the initial color as as the first argument, and the degrees of rotation (clockwise around the color wheel) as the second (the 'deg' is optional, but helpful for remembering later that this value is degrees on a circle). &lt;/p&gt;

&lt;h5&gt;
  
  
  darken and lighten
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nt"&gt;darken&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;lighten&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that the percent value is not multiplicative. In other words, we are subtracting 20% from its brightness value. We are not decreasing its current brightness value by multiplying the current value by 20% and subtracting the product. It is a scale of 0-100.&lt;/p&gt;

&lt;h5&gt;
  
  
  saturate and desaturate
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nt"&gt;desaturate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;saturate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Color saturation is essentially how much of a channel is mixed into a particular color. A color saturated to 100% is very vivid, whereas a color with 0% saturation would be grey scale.&lt;/p&gt;

</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>stylesheets</category>
    </item>
    <item>
      <title>Sass Mixins and Arguments</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:36:42 +0000</pubDate>
      <link>https://dev.to/mikkel250/sass-mixins-and-arguments-1jo7</link>
      <guid>https://dev.to/mikkel250/sass-mixins-and-arguments-1jo7</guid>
      <description>&lt;h4&gt;
  
  
  Mixins
&lt;/h4&gt;

&lt;p&gt;Mixins are a way to define styles that can be reused. The declaration block of the mixin is merged into the your main file by way of &lt;code&gt;@include&lt;/code&gt;, and best practice is to keep them separate from styles in partials, like variables (e.g. &lt;code&gt;_mixins.scss&lt;/code&gt;), and included after the variables partial. An example of how it would be used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside the _mixins partial&lt;/span&gt;
&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;alert-text&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="mh"&gt;#f00&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;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-variant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;small-caps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// in the main scss file&lt;/span&gt;
&lt;span class="nc"&gt;.error-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;alert-text&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;h4&gt;
  
  
  Mixins: arguments
&lt;/h4&gt;

&lt;p&gt;Using variables allow for parameterization in Sass, much like a function in JS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside the _mixins partial&lt;/span&gt;
&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;alert-text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color&lt;/span&gt;&lt;span class="p"&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="nv"&gt;$color&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;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-variant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;small-caps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// in the main scss file&lt;/span&gt;
&lt;span class="nc"&gt;.error-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;alert-text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;blue&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;The above has the same effect as the previous example, but now the background color can be chosen when it is included, which allows for much greater flexibility.&lt;/p&gt;

&lt;h5&gt;
  
  
  Default Argument values
&lt;/h5&gt;

&lt;p&gt;Defining default values for arguments is done by using a colon and the value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside the _mixins partial&lt;/span&gt;
&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;alert-text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#f33&lt;/span&gt;&lt;span class="p"&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="nv"&gt;$color&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;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-variant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;small-caps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// in the main scss file&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;alert-text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;h2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;alert-text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color&lt;/span&gt;&lt;span class="o"&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;span class="nt"&gt;h3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;alert-text&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;In the case above, the h3 would have the default color of #f33.&lt;br&gt;
The arguments can also be passed in using the &lt;code&gt;key: value&lt;/code&gt; syntax, as in h2 above, which will allow the arguments to be passed in any order, which is handy when there are a few different parameters with default, and only one or two need to be changed (or if you forget in what order they were defined). If this style is not used to pass in the arguments, then they must be passed in the same order as when the mixin was defined.&lt;/p&gt;
&lt;h5&gt;
  
  
  Null as default value
&lt;/h5&gt;

&lt;p&gt;A really useful aspect of default values is defining the default as null, which results in the value being completely omitted from the compiled CSS if it is not passed in with the arguments. So, it can be thought of in this case as an optional value that is only applied if it's passed into the &lt;a class="comment-mentioned-user" href="https://dev.to/include"&gt;@include&lt;/a&gt;
.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside the _mixins partial&lt;/span&gt;
&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$opacity&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="p"&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="mh"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$opacity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// in the main scss file&lt;/span&gt;
&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.other-btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="mi"&gt;.5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// compiled CSS&lt;/span&gt;
&lt;span class="nc"&gt;.btn&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="mh"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.other-btn&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="mh"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="mi"&gt;.5&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;h4&gt;
  
  
  Mixins: passing in a declaration block
&lt;/h4&gt;

&lt;p&gt;Another neat thing that can be done with mixins is that the &lt;code&gt;@content&lt;/code&gt; directive can be used to pass in additional values when it is included in the main scss file (almost like a callback in JS):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside the _mixins partial&lt;/span&gt;
&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color&lt;/span&gt;&lt;span class="p"&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="nv"&gt;$color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;.inner&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@content&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// in the main scss file&lt;/span&gt;
&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;#c69&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// note the curly braces&lt;/span&gt;
    &lt;span class="c1"&gt;// this is what will appear in compiled CSS where @content appears above&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// compiled CSS&lt;/span&gt;
&lt;span class="nc"&gt;.btn&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="mh"&gt;#c69&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="nc"&gt;.inner&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;



</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>stylesheets</category>
    </item>
    <item>
      <title>Sass Imports and variables</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:29:21 +0000</pubDate>
      <link>https://dev.to/mikkel250/sass-imports-and-variables-40fa</link>
      <guid>https://dev.to/mikkel250/sass-imports-and-variables-40fa</guid>
      <description>&lt;h4&gt;
  
  
  Imports
&lt;/h4&gt;

&lt;p&gt;CSS allows imports, but requires a new round-trip HTTP request, which can be a performance concern. Sass handles this differently. &lt;/p&gt;

&lt;p&gt;Files that have the underscore in front of their names are known as "partials", which are designed to be imported into other &lt;code&gt;.scss&lt;/code&gt; files. They will not become their own CSS files after Sass is compiled. Import is not limited to partials, it can be pointed to other &lt;code&gt;.scss&lt;/code&gt; files, folders, or even libraries by pointing it to the appropriate node_modules folder, and importing.&lt;br&gt;
Import statements are written as &lt;code&gt;@import&lt;/code&gt;, and the name of the file or library in quotes, followed by a semicolon. No file extension is necessary, and the paths are relative.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;'_variables'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Variables
&lt;/h4&gt;

&lt;p&gt;Variables are declared using the dollar sign at the beginning of the name, followed by a colon, and the value. E.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nv"&gt;$error_color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#f00&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;default&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the example above, &lt;code&gt;!default&lt;/code&gt; translates to "if error color has not been defined elsewhere." So if the variable &lt;code&gt;$error_color&lt;/code&gt; has been assigned previously, it will not override it. &lt;br&gt;
Note that the exclamation point is not a negation operator -- it has a different definition in Sass than it does in most programming languages.  &lt;/p&gt;
&lt;h5&gt;
  
  
  Variable Scope and Manipulation
&lt;/h5&gt;

&lt;p&gt;Note that, similar to &lt;code&gt;let&lt;/code&gt; in JavaScript, variables are only available in the scope in which they are defined (the curly bracket set) and its children, but variables defined inside a child scope are not available in the parent. &lt;br&gt;
Simple arithmetic can also be used with variables, and Sass will handle typical unit conversion for you, as long as it's possible (e.g. &lt;code&gt;rem&lt;/code&gt; to pixel cannot be converted because of how &lt;code&gt;rem&lt;/code&gt; are calculated, but percent to decimal works fine). &lt;/p&gt;
&lt;h4&gt;
  
  
  Types
&lt;/h4&gt;

&lt;p&gt;There are 5 types in Sass:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numbers (10, 200px, 50%, 14pt)&lt;/li&gt;
&lt;li&gt;Colors (#FFF, rgb(255, 0, 0), red)&lt;/li&gt;
&lt;li&gt;Strings ("a.png", url("a.png"))&lt;/li&gt;
&lt;li&gt;Booleans (true, false)&lt;/li&gt;
&lt;li&gt;Lists (e.g. border-radius has several space-delimited values in a specific order, which is a list. Similar to an array in JS)&lt;/li&gt;
&lt;li&gt;Maps (key: value pairs similar to objects in JS)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  String Interpolation
&lt;/h4&gt;

&lt;p&gt;Interpolation in Sass uses the octothorpe and curly braces: &lt;code&gt;#{hue(green)}&lt;/code&gt;&lt;br&gt;
Comments have another feature handy for debugging, which is that they can be used along with interpolation, and the output can be viewed in the CSS file to see what values are actually being used after compilation. Note that block level comments must be used for them to appear in the CSS file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
&lt;/span&gt;&lt;span class="nt"&gt;Error&lt;/span&gt; &lt;span class="nt"&gt;color&lt;/span&gt; &lt;span class="nt"&gt;is&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;error_color&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;Hue&lt;/span&gt; &lt;span class="nt"&gt;is&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nf"&gt;hue&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="si"&gt;}&lt;/span&gt;
&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="m"&gt;2rem&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;compiles to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
&lt;/span&gt;&lt;span class="nt"&gt;Error&lt;/span&gt; &lt;span class="nt"&gt;color&lt;/span&gt; &lt;span class="nt"&gt;is&lt;/span&gt; &lt;span class="nn"&gt;#f00&lt;/span&gt;
&lt;span class="nt"&gt;Hue&lt;/span&gt; &lt;span class="nt"&gt;is&lt;/span&gt; &lt;span class="nt"&gt;120deg&lt;/span&gt;
&lt;span class="nt"&gt;4px&lt;/span&gt;
&lt;span class="o"&gt;*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are few limits to what can be used with interpolation, and if it's not possible, it won't compile to valid CSS, so it can be checked in the manner outlined above. If nothing appears for the interpolated value, it cannot be interpolated. It won't throw an error and break your CSS, but nothing will appear where the interpolated value was supposed to be (as in the last line of the comment block in the example above), so best to find a workaround or hard code it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Combining imports and variables
&lt;/h4&gt;

&lt;p&gt;To maintain separation of concerns and fewer lines of code in the main Sass stylesheet, separate partials (files beginning with underscore) can be created to hold all variables (and other things, covered later), and then imported into the main file, which gives access to everything defined in the partials. An example of how this might work well would be a team defining a specific palette of colors in a &lt;code&gt;_variables.scss&lt;/code&gt; file, and then universal variable names can be used in the stylesheet without having to remember the specific color (e.g. primary, secondary, accent, primary_border, etc.). If a change is needed, changing it once in the variables partial will then be immediately applied to the entire app. &lt;/p&gt;

</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>stylesheets</category>
    </item>
    <item>
      <title>Getting started with Sass: nesting and parent selectors</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Mon, 04 May 2020 00:21:53 +0000</pubDate>
      <link>https://dev.to/mikkel250/getting-started-with-sass-nesting-and-parent-selectors-4617</link>
      <guid>https://dev.to/mikkel250/getting-started-with-sass-nesting-and-parent-selectors-4617</guid>
      <description>&lt;p&gt;What is Sass? It is a preprocesser that adds some extra syntax options and functionality on top of CSS, and then it compiles the &lt;code&gt;.scss&lt;/code&gt; file to a standard CSS file that will be used in the final web page/app. The way I think about it is that Sass is an enhancement to CSS that gives you extra tools (logic, functions, variables, mixins) and syntax that reads a bit more like other programming languages.&lt;/p&gt;

&lt;p&gt;These are my notes on the basics of syntax and functionality (i.e. learning to write Sass), from Mike North's fantastic &lt;a href="https://frontendmasters.com/courses/sass"&gt;course&lt;/a&gt; and I won't really be covering much in terms of setup. The official docs are a good place to start if you want to learn more than what's covered here: &lt;a href="https://sass-lang.com/documentation"&gt;https://sass-lang.com/documentation&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Installing and file types
&lt;/h4&gt;

&lt;p&gt;Just briefly touching on this topic, you'll want to add Sass to your project or system (globally) using NPM or Yarn, or use Google for other methods. I'd recommend using the .scss file extension because it's backwards compatible with standard CSS, so to convert an existing project to Sass, all that's needed is to change the file extension, but you can Google 'Sass file extensions' to find out more about this topic.&lt;/p&gt;

&lt;h4&gt;
  
  
  Nesting
&lt;/h4&gt;

&lt;p&gt;Styles can be nested by declaring them within the block (i.e. before the closing curly brace) of the parent selector, and compiles to CSS as if the selectors are parent, then a space, then child.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// styles for the container&lt;/span&gt;
  &lt;span class="nc"&gt;.left-area&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// styles for the left-area children of container&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* compiles to CSS as */
&lt;/span&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="nc"&gt;.left-area&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* styles for the left-area children of container */
&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Another neat feature of Sass is it allows inline comments, but they will not compile to the final CSS, only the &lt;code&gt;/* block comments */&lt;/code&gt; will show up. &lt;/p&gt;

&lt;p&gt;It is also possible to use the 'direct descendant' operator in Sass, but it will apply the defined styles to ALL of the children, and can lead to undesirable behavior, so is not frequently used. E.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// styles for the container&lt;/span&gt;
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;.left-area&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// styles are applied to the left-area, and all its children&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Parent Selector
&lt;/h4&gt;

&lt;p&gt;The parent selector is the &lt;code&gt;&amp;amp;&lt;/code&gt; ampersand, and will insert the name of the style that is the parent scope of the current selector. It can be helpful in adding conditional styles, (e.g. using a class as a flag to apply specific styles, or theming).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="err"&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="err"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;.right-nav&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// styles for the container class only if it also has the right-nav class&lt;/span&gt;
   &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;right&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* compiles to CSS as */
&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="na"&gt;container&lt;/span&gt;&lt;span class="err"&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="err"&gt;;&lt;/span&gt; &lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.container.right-nav&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;right&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The ability to nest and using parent selectors can make reading Sass a bit more like other programming languages in terms of logical flow and the cascade can be used to override previous styles to create themes and conditional styling. &lt;/p&gt;

&lt;p&gt;Next up: Imports and Variables.&lt;/p&gt;

</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
      <category>stylesheets</category>
    </item>
    <item>
      <title>Scope in JavaScript</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Thu, 13 Feb 2020 22:54:43 +0000</pubDate>
      <link>https://dev.to/mikkel250/scope-in-javascript-143d</link>
      <guid>https://dev.to/mikkel250/scope-in-javascript-143d</guid>
      <description>&lt;h4&gt;
  
  
  IIFE pattern
&lt;/h4&gt;

&lt;p&gt;If you want to use a variable that exists in a larger, enclosing scope (e.g. global), or "hide" it to avoid accidental use/reassignment, or want to avoid polluting the global namespace, an Immediately Invoked Function Expression (IIFE) can be used. It will not reassign the variable in the parent scope, because it first looks for the name in the local scope and uses it if found.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mikkel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;changeName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// declares new variable in the function scope&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Bob" is logged in the console&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;  

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// "Mikkel"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Wrapping the entire function in the parentheses has the effect of turning it into an expression instead of a function declaration. This allows the function to be immediately used and then discarded, and accomplishes the tasks of using the same variable name that exists in enclosing scope without affecting it. &lt;/p&gt;

&lt;h4&gt;
  
  
  Block scoping
&lt;/h4&gt;

&lt;p&gt;Another method for accomplishing the same goal is to use block scoping, using the keyword "let", which will allow for a more concise method. Interestingly, blocks are not scopes &lt;em&gt;until&lt;/em&gt; the have &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; used inside of them, but once they have been, it creates a local scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mikkel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// wrapping the statement in curly braces and using 'let' creates local scope&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// "Bob" is logged in the console&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// "Mikkel"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A different mental model for when to use &lt;code&gt;var&lt;/code&gt; vs &lt;code&gt;let&lt;/code&gt; would be to use &lt;code&gt;var&lt;/code&gt; when you need access to the variable outside of the local scope. For example, in a try/catch block, because var is available in the enclosing scope (in the example below, the function scope), it avoids having to create an undefined variable at the top of the function scope just so it can be used in the block below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;lookupRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchStr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchStr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;id&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;Using &lt;code&gt;var&lt;/code&gt; gives the return statement access to the &lt;code&gt;id&lt;/code&gt; variable even though it's enclosed in the try/catch block's scope. Another advantage to using var is that it can be declared more than once in the same scope, and let cannot. It might also be handy in a long if/else block where there are lots of conditions to check, or a switch statement with lots of possible options, or where a number of different variables need to be assigned and then returned at the end of the statement. &lt;br&gt;
A use of &lt;code&gt;let&lt;/code&gt;'s block scoping that can be taken advantage of is to use curly braces when variables only need to be used for a few lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;formatStr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;theRest&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;theRest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;str&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;h4&gt;
  
  
  &lt;code&gt;const&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;const&lt;/code&gt; keyword can be helpful as an indicator that you don't want the value to be changed, and pair it with primitive types that can't be changed anyway, because it also has some quirks. A good example would be to use it at the top of the program to store an string for an API that probably never needs to be changed by the program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;databaseApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://myDB.com/1235&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A generally good practice when using either &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; is to always declare them at the top of the scope in which they will be used, to avoid TDZ errors, because they behave differently than &lt;code&gt;var&lt;/code&gt; when it comes to scope.&lt;/p&gt;

&lt;p&gt;These are my notes from &lt;a class="comment-mentioned-user" href="https://dev.to/getify"&gt;@getify&lt;/a&gt;
's Deep JavaScript Foundations v3 course on Frontend Masters. If you'd like to dive more deeply into these topics, I highly recommend the course, and you can read his 'You Don't Know JS' books on Scope and Closure, This and Prototypes, and Types and Grammar, available on Github or for purchase at your favorite bookseller.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>scope</category>
      <category>variables</category>
    </item>
    <item>
      <title>Javascript types and type checking</title>
      <dc:creator>mikkel250</dc:creator>
      <pubDate>Wed, 12 Feb 2020 21:35:11 +0000</pubDate>
      <link>https://dev.to/mikkel250/javascript-types-and-type-checking-45a6</link>
      <guid>https://dev.to/mikkel250/javascript-types-and-type-checking-45a6</guid>
      <description>&lt;h4&gt;
  
  
  Types
&lt;/h4&gt;

&lt;p&gt;Note: throughout this post, I shorten JavaScript to 'JS'. &lt;/p&gt;

&lt;p&gt;The reason for the idea that "everything is an object" in JS is because most of the values in JS can &lt;em&gt;behave&lt;/em&gt; as objects. But this doesn't make them objects. &lt;/p&gt;

&lt;p&gt;JS Types that differ from objects are Primitive Types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;li&gt;string (the string literal, created "with quotes like this")&lt;/li&gt;
&lt;li&gt;number&lt;/li&gt;
&lt;li&gt;boolean (these are actual special values &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;, not 0 and 1 like some other languages)&lt;/li&gt;
&lt;li&gt;symbol (added with ES6)&lt;/li&gt;
&lt;li&gt;bigint (added in ES10, 2019) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other things that behave like types that are not explicitly listed as types in the spec:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;undeclared&lt;/li&gt;
&lt;li&gt;null (quirky, due to a historical bug)&lt;/li&gt;
&lt;li&gt;function (referred to as a subtype of the object type, a "callable object")&lt;/li&gt;
&lt;li&gt;array (a subtype of the object type, even though it has specific behavior)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only items in JS that are actual objects are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;object&lt;/li&gt;
&lt;li&gt;function&lt;/li&gt;
&lt;li&gt;array&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Variables, types, and &lt;code&gt;typeof&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Unlike in other languages where the type is declared when creating the variable, such as in C, &lt;code&gt;int myNum = 3;&lt;/code&gt;, In JS, variables don't have types, but the values contained in the variable do, so this is how they are evaluated, and can change over time depending on what they are assigned to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "undefined"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "string"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "number"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "boolean"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "object"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "symbol"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The typeof operator will &lt;em&gt;always&lt;/em&gt; return a string, and there is a short list of values it can be returned (essentially an enum list). So, when checking for type,  always make sure to put quotes around the value you are checking for, or the expression will not evaluate as expected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// will return false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that there is some "quirky" behavior when using &lt;code&gt;typeof&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;doesntExist&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "undefined"&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "object"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; 
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "function"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "object"&lt;/span&gt;

&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// or: BigInt(42)&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "bigint"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that &lt;code&gt;null&lt;/code&gt; will return the "object" type, so it can fail checks. This can basically be treated as a bug in the language (but there are historical reasons for it). For this reason, if you want to assign a variable to an "empty" value, it's best to avoid using &lt;code&gt;null&lt;/code&gt;. Either leave it blank or assign it to &lt;code&gt;undefined&lt;/code&gt; if you want to be more explicit. The same goes for assigning &lt;code&gt;0&lt;/code&gt; as a 'placeholder' value to a variable, since zero is a number, and the variable will evaluate to that type and can cause unplanned-for behavior.&lt;/p&gt;

&lt;p&gt;Note also that when checking a variable that didn't exist (above), it still returned "undefined". There is no "undeclared" type in JS, so you could get undefined back from a check even if the variable has never been declared, but you can &lt;em&gt;also&lt;/em&gt; get "undefined" back when the variable &lt;em&gt;has&lt;/em&gt; been declared but not yet assigned a value. The &lt;code&gt;typeof&lt;/code&gt; operator is the only operator in JS that is able to reference a thing that does not exist and not throw an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;DoesntExist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;passed the if check&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// evaluates to true, logs "passed the if check"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DoesntExist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;passed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="c1"&gt;// this will throw an error&lt;/span&gt;

&lt;span class="c1"&gt;// even more explicit&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;DoesntExist&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;this will only return if the variable exists and something has been assigned to it&lt;/span&gt;&lt;span class="dl"&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;The full list of what &lt;code&gt;typeof&lt;/code&gt; can return is: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Undefined&lt;/td&gt;
&lt;td&gt;"undefined"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Null&lt;/td&gt;
&lt;td&gt;"object"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;td&gt;"boolean"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Number&lt;/td&gt;
&lt;td&gt;"number"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BigInt (new in ECMAScript 2020)&lt;/td&gt;
&lt;td&gt;"bigint"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;"string"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Symbol (new in ECMAScript 2015)&lt;/td&gt;
&lt;td&gt;"symbol"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Function object (implements [[Call]] in ECMA-262 terms)&lt;/td&gt;
&lt;td&gt;"function"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Any other object&lt;/td&gt;
&lt;td&gt;"object"&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Special Values: NaN
&lt;/h4&gt;

&lt;p&gt;A good mental model to use for NaN is "invalid number" as opposed to the instinctual "Not a Number". &lt;br&gt;
NaN is returned if, for example, you try to convert an invalid string into a number, or if JS tries to do so through implicit conversion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;n/a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// NaN&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;39&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 39  here JS does implicit conversion&lt;/span&gt;
&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// NaN   because JS implicitly tries to convert x to a number&lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;  &lt;span class="c1"&gt;// false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;NaN is the only value in JS that is not equal to itself, which is how the &lt;code&gt;x === x&lt;/code&gt; comparison can fail. &lt;/p&gt;

&lt;p&gt;JS does ship with a way to check for the NaN value, &lt;code&gt;isNaN()&lt;/code&gt;, but this too can have some quirks. The reason is because it first tries to coerce the value passed in to a number, which can result in false positives.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Above, it is coercing the string to a number, which results in the NaN value, so it returns true (the same way declaring &lt;code&gt;x&lt;/code&gt; in the block above it did). &lt;br&gt;
As a result of this unexpected behavior, ES6 shipped with a new utility &lt;code&gt;Number.isNaN()&lt;/code&gt;, which will &lt;em&gt;not&lt;/em&gt; try to coerce the parameter to a number first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Special Values: Negative zero &lt;code&gt;-0&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The negative zero can have some unexpected consequences. When using the -0, be aware of some of the gotchas when using comparison operators, demonstrated below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;trendRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;trendRate&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="nx"&gt;trendRate&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// true &lt;/span&gt;
&lt;span class="nx"&gt;trendRate&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;trendRate&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// false&lt;/span&gt;

&lt;span class="c1"&gt;// since the triple equals doesn't reliably return comparisons to zero, &lt;/span&gt;
&lt;span class="c1"&gt;// the Object.is() method was introduced, which can reliably check for -0&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;trendRate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;trendRate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;

&lt;span class="nx"&gt;trendRate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// "0"  the sign is dropped when converted to a string&lt;/span&gt;

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



&lt;p&gt;The takeaway from the above is that, if you need to check for a negative zero, use the &lt;code&gt;Object.is()&lt;/code&gt; method, and if you need it in string form, don't use the &lt;code&gt;toString()&lt;/code&gt; method. One option would be to create your own function that will check the parameter using the &lt;code&gt;Object.is()&lt;/code&gt; method, and then create and return a string literal &lt;code&gt;"-0"&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;negZeroToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is not the number negative zero! This function only accepts negative zero as an argument.`&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;And that's a brief overview. Hopefully you like this 'type of' post (womp womp)!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>types</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
