<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Mr Devops Blog - Medium]]></title>
        <description><![CDATA[A blog for developers - Medium]]></description>
        <link>https://medium.com/mr-devops-blog?source=rss----f1735e5b3d7f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Mr Devops Blog - Medium</title>
            <link>https://medium.com/mr-devops-blog?source=rss----f1735e5b3d7f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:30:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/mr-devops-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use ::after and ::before pseudo-elements in CSS?]]></title>
            <link>https://medium.com/mr-devops-blog/https-medium-com-mr-devops-blog-how-to-use-after-and-before-pseudo-elements-in-css-dd76ed17b7f0?source=rss----f1735e5b3d7f---4</link>
            <guid isPermaLink="false">https://medium.com/p/dd76ed17b7f0</guid>
            <category><![CDATA[website]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Shamin Meerankutty]]></dc:creator>
            <pubDate>Wed, 28 Feb 2018 02:44:20 GMT</pubDate>
            <atom:updated>2018-02-28T02:44:19.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLvfZLNOWl0JgQHYkeAXNA.jpeg" /></figure><p>As we know in css while we apply a style to an element it applies completely to the element so, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements">Pseudo-elements</a> are introduced in css to style specific parts of elements. Two most widely used pseudo-elements in css are ::after and ::before. These two elements are hard to understand at first. We can see many applications of these elements in web.</p><p>By understanding how these elements work we can easily use these elements in various design and animation effects. ::after and ::before where introduced in css to append contents to an element with css. But we know these elements are used in designing for what they are not intended to do and that is the main problem why most of the people don’t even know how to use these elements.</p><p>At first, I am going to tell about what these where actualy intended to do then I will show you how to use these elements other than what they are intended to do.</p><h3>What are ::after and ::before pseudo elements?</h3><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::before">::before</a> is a pseudo element used to append data infront of the element where style is applied and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::after">::after</a> is used to append data to end of the element.</p><pre>&lt;p class=&quot;data&quot;&gt;Element&lt;/p&gt;</pre><pre>.data::before { content: &quot;&lt; &quot;; color: red; } .data::after { content: &quot; &gt;&quot;; color: green; }</pre><p><strong>Result:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/0*NZWlRKw7M3TTfxP4.png" /></figure><p>As seen in the example a red “&lt; “ is appended before the element text and a green “ &gt;” is appended after the element text. The content given in the style is appended to the text. This was what ::after and ::before were intended to do when they were introduced to css.</p><h3>What can we do with ::before and ::after pseudo-elements?</h3><p>We can do many designs and animations with pseudo elements. These are basicaly done by setting our element to a relative positioning position:relative and our pseudo-elements to an absolute positioning position:absolute</p><p>As an example we can create a nav icon using these method. Consider an element with background black and a height of 4px and width of 30px and set it with a relative postioning so that our pseudo-elements will be positioned relative to this element.</p><pre>&lt;div class=&quot;nav-icon&quot;&gt;&lt;/div&gt;</pre><pre>.nav-icon { position:relative; width: 30px; height: 4px; background: #000; }</pre><p><strong>Result:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/115/0*z14_KK0BLozI7xpw.png" /></figure><p>Now we have got one small rectangle for our nav icon. We need two more rectangle for the nav icon to be completed and we can add this using pseudo-elements. To do this create a ::before and ::after pseudo-element for .nav-icon class and give them absolute postion position: absolute. Please don&#39;t forget to give a content to the pseudo-element otherwise it won&#39;t work. Give an empty content to our pseudo-elements content: &quot;&quot;.</p><pre>.nav-icon::before,.nav-icon::after { position: absolute; content: &quot;&quot;; width: 30px; height: 4px; background: #000; }</pre><p><strong>Result:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/115/0*liZC49nQ_eHU2Q-g.png" /></figure><p>Don’t worry if you don’t see our pseudo-elements actualy they are present but is not visible as they are drawn above our element. To make them visible we need to translate our ::before element a little bit upwards and our ::after element little bit downwards. We can achive this by transform: translateY().</p><pre>.nav-icon::before { transform: translateY(-10px); } .nav-icon::after { transform: translateY(10px); }</pre><p><strong>Result:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/133/0*MZh_UHHZXNziL3mP.png" /></figure><p>Now we have got a nav icon with css and pseudo elements. What if we need to make it a cross. Just hide our ::before element and transform: rotate() our ::after and main element.</p><pre>&lt;div class=&quot;nav-icon crossed&quot;&gt;&lt;/div&gt;</pre><pre>.crossed { transform:rotate(45deg) } .crossed::before { opacity: 0; } .crossed::after { transform:rotate(-90deg) }</pre><p><strong>Result:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/121/0*2Vfjuigi2kBYkwgA.png" /></figure><p>This was just an intro you can do many designs using the pseudo-elements. Just try to do something different and post your designs as comments so that it will help someone.</p><p>All the code is available in <a href="https://codepen.io/shamin616/pen/xYyaew">Codepen</a>.</p><p><em>Originally published at </em><a href="https://mrdevops.xyz/how-to-use-after-and-before-in-css/"><em>mrdevops.xyz</em></a><em> on February 27, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd76ed17b7f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mr-devops-blog/https-medium-com-mr-devops-blog-how-to-use-after-and-before-pseudo-elements-in-css-dd76ed17b7f0">How to use ::after and ::before pseudo-elements in CSS?</a> was originally published in <a href="https://medium.com/mr-devops-blog">Mr Devops Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>