aboutsummaryrefslogtreecommitdiff
path: root/build/fake-3d-elements-with-css
diff options
context:
space:
mode:
Diffstat (limited to 'build/fake-3d-elements-with-css')
-rw-r--r--build/fake-3d-elements-with-css/index.html21
1 files changed, 2 insertions, 19 deletions
diff --git a/build/fake-3d-elements-with-css/index.html b/build/fake-3d-elements-with-css/index.html
index d04f852..a3e8319 100644
--- a/build/fake-3d-elements-with-css/index.html
+++ b/build/fake-3d-elements-with-css/index.html
@@ -3,11 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="color-scheme" content="dark light">
<link rel="icon" href="data:,">
<title>Faking 3D Elements with CSS</title>
<link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
<link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" />
-<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
+<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{background:rgba(0,0,0,0.1);border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
</head>
<nav>
@@ -16,32 +17,20 @@
<main>
<h1 id="faking-3d-elements-with-css">Faking 3D Elements with CSS</h1>
-
<p>2020-04-29</p>
-
<p>Although not always practical, creating the illusion that some of your web elements are 3D can be a fun experiment. I set out to see if I was able to create such an illusion with only 2 HTML elements and as little CSS as possible.</p>
-
<p>This is what I ended up creating:</p>
-
<p><img src="/public/images/css-orb.png" alt="Blue 3D orb made out pure CSS" /></p>
-
<p><a href="https://codepen.io/bradleytaunt/pen/VwvzKyb">Live CodePen Example</a></p>
-
<h2 id="the-html">The HTML</h2>
-
<p>Prepare for your mind to be blown:</p>
-
<pre><code>&#60;div class="main-orb"&#62;
&#60;div class="inner-orb"&#62;&#60;&#47;div&#62;
&#60;&#47;div&#62;
</code></pre>
-
<p>That&#8217;s it - I wasn&#8217;t kidding when I said we would use only 2 HTML elements. The <code>.main-orb</code> is the core shape (set to 400x400) and the <code>.inner-orb</code> is placed on top of it&#8217;s parent at a slightly smaller size (360x360) - but more on that below in the CSS portion.</p>
-
<h2 id="the-css">The CSS</h2>
-
<p>First we give the bigger orb element (<code>.main-orb</code>) the default styling needed to represent a 2D circle:</p>
-
<pre><code>.main-orb {
background: linear-gradient(#fff 0%, #eee 10%, #2E86FB 50%, #1A237E 100%);
border-radius: 9999px;
@@ -51,9 +40,7 @@
width: 400px;
}
</code></pre>
-
<p>Next, we include both <code>:before</code> and <code>:after</code> pseudo elements for our orb&#8217;s drop shadow. You <em>could</em> do this with a simple <code>box-shadow</code> property on the <code>.main-orb</code> itself, but I&#8217;ve explained in a previous post why <a href="/blog/better-box-shadows.html">that&#8217;s not the best approach</a>.</p>
-
<pre><code>&#47;* Shared styling for both pseudo elements - Remember DRY *&#47;
.main-orb:before, .main-orb:after {
border-radius: 200px 200px 9999px 9999px;
@@ -79,9 +66,7 @@
width: 60%;
}
</code></pre>
-
<p>With our main orb complete we can move on to the <code>.inner-orb</code> element to help bring slightly more depth to our floating ball of CSS:</p>
-
<pre><code>.inner-orb {
background: linear-gradient(#fff 0%, #2E86FB 60%, #283593 100%);
border-radius: 9999px;
@@ -94,9 +79,7 @@
width: 360px;
}
</code></pre>
-
<h2 id="poor-mans-3d-elements">Poor-man&#8217;s 3D elements</h2>
-
<p>Clearly implementing something like this will never come close to generating true 3D renders on a website, but it is a fun exercise to see how much further we can push simple CSS. Feel free to fork the above CodePen to play around with different colors and shadow placements.</p>
<footer role="contentinfo">
<h2>Menu Navigation</h2>