<?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: Jmlpez</title>
    <description>The latest articles on DEV Community by Jmlpez (@jmlpez).</description>
    <link>https://dev.to/jmlpez</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%2F882274%2Fe4924cea-7877-4c97-920f-0ceae045db39.png</url>
      <title>DEV Community: Jmlpez</title>
      <link>https://dev.to/jmlpez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jmlpez"/>
    <language>en</language>
    <item>
      <title>How create the Kotlin Logo with CSS3</title>
      <dc:creator>Jmlpez</dc:creator>
      <pubDate>Sat, 02 Jul 2022 14:36:29 +0000</pubDate>
      <link>https://dev.to/jmlpez/how-create-the-kotlin-logo-with-css3-40b0</link>
      <guid>https://dev.to/jmlpez/how-create-the-kotlin-logo-with-css3-40b0</guid>
      <description>&lt;p&gt;Hi!, in a previous post I explain &lt;a href="https://dev.to/jmlpez/how-make-a-triangle-in-css3-1b8a"&gt;how to make a triangle in CSS3&lt;/a&gt; , in this post I will show you how to create the Kotlin logo using that tecnique, gradients and a few CSS3 tricks.&lt;/p&gt;

&lt;p&gt;This is the goal (there are another Kotlin logos but I choose this because is more interesting to explain):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uB24xuuz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/athltygzo40y5rkxv5lf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uB24xuuz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/athltygzo40y5rkxv5lf.png" alt="Kotlin Logo Original" width="880" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Create it!
&lt;/h2&gt;

&lt;h2&gt;
  
  
  First!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1- Prepare the environment
&lt;/h3&gt;

&lt;p&gt;Create a folder and open it in your code editor&lt;/p&gt;

&lt;p&gt;Create two files: &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;style.css&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Now just type the basic HTML and open it in your browser
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="UTF-8" /&amp;gt;
        &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
        &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
        &amp;lt;title&amp;gt;Template Static Web App&amp;lt;/title&amp;gt;
        &amp;lt;link rel="stylesheet" href="./css/style. css" /&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;section class="section"&amp;gt;
            &amp;lt;div class="logo-container"&amp;gt;
                &amp;lt;div class="logo-back"&amp;gt;
                    &amp;lt;div class="logo"&amp;gt;&amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;strong class="logo-name"&amp;gt;Kotlin&amp;lt;/strong&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/section&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have a &lt;code&gt;section&lt;/code&gt; to wrap all the content and the &lt;code&gt;logo-container&lt;/code&gt; wrap the logo and the logo-name&lt;/p&gt;

&lt;p&gt;The logo is drawn in the &lt;code&gt;logo-back&lt;/code&gt; and the &lt;code&gt;logo&lt;/code&gt; classes&lt;/p&gt;

&lt;h4&gt;
  
  
  Basic Styles
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

.section {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    background-color: white;
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Next!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2- Create the Logo
&lt;/h3&gt;

&lt;p&gt;WARNING: this is an aproximation of the original Logo because  I couldn't get get the original values , however is quite similar :)&lt;/p&gt;

&lt;p&gt;The background of the Kotlin logo is a &lt;code&gt;linear-gradient&lt;/code&gt;, but we are painting triangles (with the &lt;code&gt;border-property&lt;/code&gt; tecnique) so to achieve "gradient-borders" we paint a box (the &lt;code&gt;logo-back&lt;/code&gt; class) with a &lt;code&gt;linear-gradient&lt;/code&gt; (which is supported for the &lt;code&gt;background&lt;/code&gt; property).&lt;/p&gt;

&lt;p&gt;The trick is that in the &lt;code&gt;logo&lt;/code&gt; class we set &lt;code&gt;border: 100px solid transparent&lt;/code&gt;. The &lt;code&gt;border-width&lt;/code&gt; is 100px - the half of the parent width/height - because the border is applied to all the sides so 100px in top, 100px in the bottom ... and the goal is to make it fit perfectly in the container so I set &lt;code&gt;position: absolute&lt;/code&gt; to remove it from the document flow and positioning the way I want.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;border-right-color&lt;/code&gt; is equal to the &lt;code&gt;background-color&lt;/code&gt; of the section and with that trick I "remove" the triangle of the right and our logo start to take shape.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.logo-back {
    width: 200px;
    height: 200px;
    background: linear-gradient(45deg, #0096d6 20%, #7972e3 60%);
    position: relative;
}
.logo {
    position: absolute;
    top: 0;
    left: 0;
    border: 100px solid transparent;
    border-right-color: white;
}
.logo-name{
    display:none;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's set &lt;code&gt;display:none&lt;/code&gt; to the &lt;code&gt;logo-name&lt;/code&gt; and look the result at this time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YBaV7Beh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jvofza1mk567wuq5t70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YBaV7Beh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jvofza1mk567wuq5t70.png" alt="Kotlin logo" width="682" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;if you are interested in learning more about "gradient-borders" check this &lt;a href="https://nikitahl.com/gradient-border-css"&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The final shape
&lt;/h2&gt;

&lt;p&gt;It's turn of create and correct positioning the quadrilateral in the middle.&lt;/p&gt;

&lt;p&gt;Let use the &lt;code&gt;after&lt;/code&gt; pseudo-element of the &lt;code&gt;logo&lt;/code&gt; class to achieve that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.logo::after{
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    background: linear-gradient(0, #c856bd 0%, #f88a02 65%;
    width: 75px;
    height: 300px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look what just happen 😯:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--39_Fl2DM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjy8fwnhb8k65pbzba9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--39_Fl2DM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjy8fwnhb8k65pbzba9c.png" alt="Kotlin logo" width="880" height="945"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Why is positioning in the middle if I set &lt;code&gt;top: 0&lt;/code&gt; and &lt;code&gt;left: 0&lt;/code&gt; ?
&lt;/h3&gt;

&lt;p&gt;There is no problem at all, it's working in the exactly way is suppose to work (And fortunaly in the way we want 😁). That's because the &lt;code&gt;position: absolute&lt;/code&gt; property position the element respect to the closest parent with non-static position and the &lt;code&gt;top&lt;/code&gt; start exactly in the&lt;br&gt;
&lt;strong&gt;padding&lt;/strong&gt; not at the &lt;strong&gt;border&lt;/strong&gt;, and the parent does not have any padding or content so is positioning where the padding should start, right in the middle!!.&lt;/p&gt;
&lt;h2&gt;
  
  
  Time to transform
&lt;/h2&gt;

&lt;p&gt;Let use the &lt;code&gt;transform&lt;/code&gt; property to move the rectangle, but first let's think in a clever solution 🤔.&lt;/p&gt;

&lt;p&gt;It's necessary rotate the rectangle but by default the &lt;code&gt;tranform-origin&lt;/code&gt; is set right in the middle of the box so if I set &lt;code&gt;transform: rotate(45deg)&lt;/code&gt; look what happen:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---7Y2wiZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mssis4j0c44mio7j8r5m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---7Y2wiZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mssis4j0c44mio7j8r5m.png" alt="Kotlin logo" width="880" height="945"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You could move it and try to correct positioning the shape but it's quite difficult to achieve that cleanly so let's think in other approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transform-origin: 0% 0%;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that all the transformations will be starting  from (0, 0) or the top-left corner, look what happen now if I rotate the shape:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oauuL7zA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42f5tyuwirjrc9v7scct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oauuL7zA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42f5tyuwirjrc9v7scct.png" alt="Kotlin logo" width="880" height="945"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's correctly rotated, it's time to translate it.&lt;/p&gt;

&lt;p&gt;The shape needs to cover the upper triangle. if you look carefully I just have to move it all of it &lt;code&gt;width&lt;/code&gt; in the y-axis and the half of it &lt;code&gt;heigth&lt;/code&gt; in the x-axis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transform: rotate(45deg) translate(-100%, -50%);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convence yourself of those values (if you don't understand the minus in the translation, remove the rotation and you will notice)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NR1KE5sg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj57dai97x1ums71yx62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NR1KE5sg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj57dai97x1ums71yx62.png" alt="Kotlin logo" width="880" height="945"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it's just set &lt;code&gt;overflow-hidden&lt;/code&gt; to the &lt;code&gt;logo-back&lt;/code&gt; box to remove all the content out of it boundaries:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Bl-IjYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbjyic2qz4nxydqrr73g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Bl-IjYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbjyic2qz4nxydqrr73g.png" alt="Kotlin logo" width="714" height="772"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can change the witdh of the shape and it will be exactly in the same place 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling the logo-name
&lt;/h2&gt;

&lt;p&gt;Before all set &lt;code&gt;display: flex&lt;/code&gt; to the &lt;code&gt;logo-container&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.logo-container{
    display: flex;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then just basic styles for the logo-name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.logo-name {
    font-size: 290px;
    display: block;
    line-height: 200px;
    margin-left: 32px;
    color: #1e191a;
    font-family: sans-serif;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;line-height&lt;/code&gt; property have the same &lt;code&gt;height&lt;/code&gt; of the logo and the &lt;code&gt;font-size&lt;/code&gt; it is a little bigger so that it is exactly at the same height as the logo. if you want to know more about the &lt;code&gt;line-height&lt;/code&gt; property check this &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/line-height"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;p&gt;The font-family is sans-serif because the original font which is "JetBrains Sans" is property of the company and requires a license to use.&lt;/p&gt;

&lt;p&gt;Check the final result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KfuURdSD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8w1qk3fgw0dryodtp8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KfuURdSD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8w1qk3fgw0dryodtp8i.png" alt="Kotlin logo" width="880" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can compare both logos and look some differences but I am satisfied and I really enjoyed doing it.&lt;/p&gt;

&lt;p&gt;If you have any doubt, question or suggestion , please leave a comment. Thanks in advance!&lt;/p&gt;

&lt;p&gt;Check and test the code &lt;a href="https://codepen.io/Jmlpez/pen/qBodXBv"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How make a Triangle in CSS3</title>
      <dc:creator>Jmlpez</dc:creator>
      <pubDate>Fri, 24 Jun 2022 21:28:42 +0000</pubDate>
      <link>https://dev.to/jmlpez/how-make-a-triangle-in-css3-1b8a</link>
      <guid>https://dev.to/jmlpez/how-make-a-triangle-in-css3-1b8a</guid>
      <description>&lt;p&gt;Hi! There are several ways to make a triangle in CSS3, in this post I will show one of them, using the &lt;code&gt;border&lt;/code&gt; property&lt;/p&gt;

&lt;h2&gt;
  
  
  First!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1- Prepare the environment
&lt;/h3&gt;

&lt;p&gt;You can use any text editor, however I recommend vscode :).&lt;/p&gt;

&lt;p&gt;Now just create a folder and inside it two the &lt;code&gt;index.html&lt;/code&gt; and the &lt;code&gt;style.css&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you are using linux just type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir triangleExample
cd triangleExample
touch index.html style.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open the folder in vscode typing:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Next!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2- Create a simple static web page
&lt;/h3&gt;

&lt;p&gt;Write the html content with a section tag and a div with the class triangle inside it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="UTF-8" /&amp;gt;
        &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
        &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
        &amp;lt;title&amp;gt;Triangle Example&amp;lt;/title&amp;gt;
        &amp;lt;link rel="stylesheet" href="./style.css" /&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;section class="section"&amp;gt;
            &amp;lt;div class="triangle"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/section&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write the basic style for the section tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.section {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

&lt;/div&gt;



&lt;p&gt;Open the &lt;code&gt;index.html&lt;/code&gt; file in your browser (I recommend  &lt;a href="https://www.google.com/chrome/" rel="noopener noreferrer"&gt;Google Chrome&lt;/a&gt; :))&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3- Create a triangle
&lt;/h3&gt;

&lt;p&gt;Once you get here is just type the triangle styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.triangle {
    width: 0;
    height: 0;
    display: inline-block;
    border: 50px solid transparent;
    border-top-color: crimson;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You sould see something like this in your browser:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How it works...?
&lt;/h2&gt;

&lt;p&gt;The trick is that the triangle does not has &lt;code&gt;width&lt;/code&gt; or &lt;code&gt;height&lt;/code&gt;, and we set the &lt;code&gt;border&lt;/code&gt; property to 50px (the size tha we want :))&lt;/p&gt;

&lt;p&gt;Also the &lt;code&gt;border-style&lt;/code&gt; is solid so is fully painted and the &lt;code&gt;border-color&lt;/code&gt; is transparent so in that way, you will not see anything&lt;/p&gt;

&lt;p&gt;But if we set &lt;code&gt;border-top-color&lt;/code&gt; to crimson for example, then we will see just the to top of our element (because the others sides are transparent), which is in fact a triangle!&lt;/p&gt;

&lt;p&gt;You can play around with those values and paint any of the sides, and even paint a rectangle triangle&lt;/p&gt;

&lt;p&gt;To achieve this just paint the top and the left &lt;code&gt;border&lt;/code&gt; in the triangle styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    border-top-color: crimson;
    border-left-color: crimson;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like this:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Usage Examples
&lt;/h2&gt;

&lt;p&gt;There are many uses for a triangle in a web page&lt;/p&gt;

&lt;p&gt;You can create a message box with an arrow like this:&lt;/p&gt;

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

&lt;p&gt;To achieve this let's wrap our triangle in div tag with the class "message-box" and put a message inside it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="message-box"&amp;gt;
    Message Box!
    &amp;lt;div class="triangle"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then modify the message-box element style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.message-box {
    background-color: crimson;
    width: 200px;
    height: 60px;
    text-align: center;
    line-height: 60px;
    color: white;
    text-transform: uppercase;
    font-weight: bold;
    position: relative;
    border-radius: 6px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally create and position the triangle correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.message-box .triangle {
    display: inline-block;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: crimson;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We set &lt;code&gt;position: absolute&lt;/code&gt; to the triangle, for correct positioning, because it must be right down the message box, and centered&lt;/p&gt;

&lt;p&gt;For centered we set the &lt;code&gt;left: 50%&lt;/code&gt; property to paint the element right after the middle (because the paint starts exactly in the middle) so is necessary move it the half of it's size and for that we use &lt;code&gt;transform: translateX(-50%)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concluying
&lt;/h2&gt;

&lt;p&gt;Now you should know how to easy create triangles in CSS3&lt;/p&gt;

&lt;p&gt;You can play around with those values and create the perfect triangle for your page!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
