<?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: The Anonymous Koder</title>
    <description>The latest articles on DEV Community by The Anonymous Koder (@theanonymouskoder).</description>
    <link>https://dev.to/theanonymouskoder</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%2F667616%2F9e00749d-7666-4c85-8121-d6c54aa0e404.jpeg</url>
      <title>DEV Community: The Anonymous Koder</title>
      <link>https://dev.to/theanonymouskoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theanonymouskoder"/>
    <language>en</language>
    <item>
      <title>Create a pure CSS sphere</title>
      <dc:creator>The Anonymous Koder</dc:creator>
      <pubDate>Wed, 21 Jul 2021 12:47:41 +0000</pubDate>
      <link>https://dev.to/theanonymouskoder/create-a-pure-css-sphere-57l2</link>
      <guid>https://dev.to/theanonymouskoder/create-a-pure-css-sphere-57l2</guid>
      <description>&lt;p&gt;Css spheres may sound impossible (or at least very tedious) considering that we need to position hundreds of divs and everything but that is not actually the truth. In fact, we can make a realistic CSS sphere using only one div and minimal CSS! In fact, we don’t even need to make a real sphere, we can just make a div that looks like a sphere using a &lt;a href="https://www.w3schools.com/cssref/func_radial-gradient.asp" rel="noopener noreferrer"&gt;radial gradient&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create the div
&lt;/h2&gt;

&lt;p&gt;We will start slow. We will just add a simple div and give it a class “sphere”.&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 = 'sphere'&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Add a bit of CSS
&lt;/h2&gt;

&lt;p&gt;Now we will add a bit of CSS (below is the styling for the sphere)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.sphere {
  border-radius: 50%; /* to make it a circle */
  background: 
    radial-gradient(
      circle at 30% 30%,
      #ffff00,
      #774400
    ); /* this is the radial gradient I was talking about */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks great, right? We will have a yellow sphere with the light coming from the top right corner, at least that is what we think. After seeing &lt;a href="https://codepen.io/theanonymouskoder/pen/YzVZoWq?editors=1100" rel="noopener noreferrer"&gt;this codepen&lt;/a&gt;, we see the world’s most perfect, glorious and annoying white space. Why? What mistake did we make? It turns out that we forgot to set a width and height for the div meaning that it will be 0px X 0px since there is no content inside it.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Set the width
&lt;/h2&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%2F9co9g9159hfcwi77dn22.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%2F9co9g9159hfcwi77dn22.png" alt="Sphere"&gt;&lt;/a&gt;&lt;br&gt;
Now once we add a width and height (500px), we can see that it looks better (click &lt;a href="https://codepen.io/theanonymouskoder/pen/poPeXeO?editors=1100" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Add a shadow
&lt;/h2&gt;

&lt;p&gt;Looks pretty realistic, but It looks like it is floating in the middle of nowhere. Not the best way to make something realistic, is it? What do we do? We add a shadow. This will give the illusion that the sphere is on a surface. For now, we will add just one shadow which will be slightly transparent (in case we want to add another shadow later). The link to the codepen is &lt;a href="https://codepen.io/theanonymouskoder/pen/Exmmwee?editors=1100" rel="noopener noreferrer"&gt;here&lt;/a&gt;. We still haven’t succeeded in putting it on the ground. What we did succeed in is making it look even more like it is floating. We can use a new div to do this. We play around with the margins and background and get &lt;a href="https://codepen.io/theanonymouskoder/pen/PomjmeY?editors=1100" rel="noopener noreferrer"&gt;this&lt;/a&gt;:&lt;br&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%2Fimvxjk30pfp1mgyvlrtb.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%2Fimvxjk30pfp1mgyvlrtb.png" alt="Sphere"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Rotation
&lt;/h2&gt;

&lt;p&gt;Ok now it looks realistic, but how do we rotate it? Transforms don’t work, as we can see &lt;a href="https://codepen.io/theanonymouskoder/pen/zYwZgzo" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
If you remember that this is not an actual sphere, then you might remember why. We used a gradient for the 3d look so transforms won’t do much. Instead, we will have to change the center of the gradient. Now we use background position as shown &lt;a href="https://codepen.io/theanonymouskoder/pen/vYmxovV?editors=1100" rel="noopener noreferrer"&gt;here&lt;/a&gt;, which doesn’t work either. It is because of &lt;a href="https://stackoverflow.com/questions/51731106/using-percentage-values-with-background-position-on-a-linear-gradient/51734530#51734530" rel="noopener noreferrer"&gt;the way that browsers process background-position&lt;/a&gt;. What can we do to fix this. You can just make background-size 200%. Now the rotation works!&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Animation
&lt;/h2&gt;

&lt;p&gt;Time to animate it. For now, we want a ball rotating from left to right. A change in the location of the light source will also work. If we play around a bit with some &lt;a href="https://www.w3schools.com/css/css3_animations.asp" rel="noopener noreferrer"&gt;CSS animations&lt;/a&gt;, we can get the below result.&lt;br&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%2Flbciviaejwpbzefiabyt.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbciviaejwpbzefiabyt.gif" alt="Sphere"&gt;&lt;/a&gt;&lt;br&gt;
Looks good, right? The light is moving from left to right and back again, but something is off. The shadow is refusing to move. To fix this, we need to add a new animation for the shadow. We will only need to change the margin-left property and voilà, we will get a perfect rotating sphere animation. The link to the codepen is &lt;a href="https://codepen.io/theanonymouskoder/pen/oNWwXoa?editors=0100" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
You can view the snippets on github &lt;a href="https://github.com/theanonymouskoder/CSS-Spheres" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>3d</category>
    </item>
    <item>
      <title>7 cool things that you didn’t know about CSS.</title>
      <dc:creator>The Anonymous Koder</dc:creator>
      <pubDate>Wed, 21 Jul 2021 12:36:36 +0000</pubDate>
      <link>https://dev.to/theanonymouskoder/7-cool-things-that-you-didn-t-know-about-css-31gj</link>
      <guid>https://dev.to/theanonymouskoder/7-cool-things-that-you-didn-t-know-about-css-31gj</guid>
      <description>&lt;h2&gt;
  
  
  1. calc()
&lt;/h2&gt;

&lt;p&gt;Calc is one of the CSS tools which not everyone knows about. It allows you to add calculations in your CSS code. This can be used to make your website more responsive and also remove some annoying overflows: &lt;a href="https://codepen.io/theanonymouskoder/pen/eYWvZRr"&gt;example&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;width: calc(100vw - 16px);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. cubic-bezier()
&lt;/h2&gt;

&lt;p&gt;This is another useful way to make your css animations come to life. Most of the time, we use linear, ease, ease-in-out, and other pre-defined beziers wasting half of the day finding the perfect bezier. The cubic-bezier() function allows us to create a custom bezier. At first, the numbers may seem randon but the moment you get a &lt;a href="https://cubic-bezier.com/"&gt;visual representation&lt;/a&gt;, you finally get what the numbers mean. &lt;a href="https://codepen.io/theanonymouskoder/pen/OJmpNBW"&gt;Here&lt;/a&gt;’s an example showing the difference between pre-defined and custom beziers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;animation-timing-function: cubic-bezier(0.5, 0, 1, 0.75);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. @supports
&lt;/h2&gt;

&lt;p&gt;This allows you to tell if a CSS property is supported by the browser and adapt accordingly. It is used like a media query. An &lt;a href="https://codepen.io/theanonymouskoder/pen/oNWZZjG?editors=3500"&gt;example&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@supports (display: flex) or (display: block) {
  .my-class {
    margin-top: 200px;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. The turn unit
&lt;/h2&gt;

&lt;p&gt;This is one of those lesser known CSS hacks. Instead of having to calculate the number of degrees in a quarter turn, you can use the turn unit. &lt;a href="https://codepen.io/theanonymouskoder/pen/oNWZZqd?editors=3100"&gt;Another demo&lt;/a&gt;&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(0.25turn); /* this is like rotate(90deg) */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. pointer-events
&lt;/h2&gt;

&lt;p&gt;This CSS property can be used to disable a link. It can also be used for &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events"&gt;many other things&lt;/a&gt; but those are mostly experimental. Just say&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a.disabled[href] {
  pointer-events: none;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codepen.io/theanonymouskoder/pen/PompbpZ"&gt;Example&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. caret
&lt;/h2&gt;

&lt;p&gt;This is the style of the caret (also called cursor). It allows you to change the shape and color of the caret. The color is only supported by some browsers and the shape is supported by &lt;a href="https://css-tricks.com/almanac/properties/c/caret-shape/#browser-support"&gt;none&lt;/a&gt;. The syntax is like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;caret: color shape;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As usual, an &lt;a href="https://codepen.io/theanonymouskoder/pen/jOmBBvW?editors=1100"&gt;example&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. ::selection
&lt;/h2&gt;

&lt;p&gt;This is one of those cool properties which can really improve the look of your website. This is a pseudo-element which (as the name suggests) is the part of the selected text on a webpage. You can just add a&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;::selection {
  background: darkblue;
  color: lightgreen;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and be satisfied with the background of the selected text being dark blue and the text being light green like in &lt;a href="https://codepen.io/theanonymouskoder/pen/XWRMRaB?editors=1100"&gt;this&lt;/a&gt; example or you can get creative and take it one step further like in &lt;a href="https://codepen.io/theanonymouskoder/pen/OJmpmwb?editors=1100"&gt;this&lt;/a&gt; example. It turns out that most browsers support multiple styles for different selections. We can take advantage of this fact and make the background of h1 and h2 elements red. We can use this to make some elements more noticeable than others resulting in a better user experience.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
    </item>
  </channel>
</rss>
