aboutsummaryrefslogtreecommitdiff
path: root/build/animated-card-tiles
diff options
context:
space:
mode:
Diffstat (limited to 'build/animated-card-tiles')
-rw-r--r--build/animated-card-tiles/index.html217
1 files changed, 125 insertions, 92 deletions
diff --git a/build/animated-card-tiles/index.html b/build/animated-card-tiles/index.html
index 0ef7448..699610d 100644
--- a/build/animated-card-tiles/index.html
+++ b/build/animated-card-tiles/index.html
@@ -1,54 +1,61 @@
<!doctype html>
-<html lang="en" id="top">
+<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>Animated Card Tiles</title>
- <link href="https://bt.ht/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
- <style>*{box-sizing:border-box;}body{font-family:sans-serif;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{overflow:auto;}table{text-align:left;width:100%;}</style>
+ <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>
</head>
<nav>
- <a href="#menu">Menu &darr;</a>
+ <a href="#menu">Menu &darr;</a>
</nav>
<main>
-<h1>Animated Card Tiles</h1>
+<h1 id="animated-card-tiles">Animated Card Tiles</h1>
+
<p>2019-02-27</p>
-<p><em>The design trend of using "cards" or "tiles" to display interactive</em> sections/article headings in an app or website remains a popular choice among designers. So, let's build a set of animated cards with only HTML &amp; CSS. </p>
-<h2>What we will be building (live demo)</h2>
+
+<p><em>The design trend of using &#8220;cards&#8221; or &#8220;tiles&#8221; to display interactive</em> sections&#47;article headings in an app or website remains a popular choice among designers. So, let&#8217;s build a set of animated cards with only HTML &#38; CSS. </p>
+
+<h2 id="what-we-will-be-building-live-demo">What we will be building (live demo)</h2>
+
<p>This is the set of animated card tiles we will be creating:</p>
+
<p><em>(try hovering)</em></p>
+
<p><a href="https://codepen.io/bradleytaunt/pen/rNjBpob">Live CodePen</a></p>
-<h2>The HTML</h2>
+
+<h2 id="the-html">The HTML</h2>
+
<p>For the base skeleton of these cards we only need:</p>
+
<ul>
-<li>a <code>flexbox</code> main container to hold everything</li>
-<li>a <code>.card-tile</code> parent element</li>
-<li>the inner child element that will display on <code>:hover</code></li>
-<li>proper <code>h4</code> and <code>p</code> tags inside that child element</li>
+<li><p>a <code>flexbox</code> main container to hold everything</p></li>
+<li><p>a <code>.card-tile</code> parent element</p></li>
+<li><p>the inner child element that will display on <code>:hover</code></p></li>
+<li><p>proper <code>h4</code> and <code>p</code> tags inside that child element</p></li>
</ul>
-<pre><code>&lt;div class=&quot;card-tiles-container&quot;&gt;
- &lt;div class=&quot;card-tile&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
-&lt;/div&gt;
-</code></pre>
-<p>That's all that is needed - for now. We will be returning to this code shortly to add some extra classes to make our lives easier.</p>
-<h2>The CSS</h2>
+
+<p>That&#8217;s all that is needed - for now. We will be returning to this code shortly to add some extra classes to make our lives easier.</p>
+
+<h2 id="the-css">The CSS</h2>
+
<p>First we set the main housing container to use <code>flex</code> so we save ourselves the headache of aligning all the cards in a nice row:</p>
+
<pre><code>.card-tiles-container {
display: flex;
font-size: 14px;
margin: 20px 0;
}
</code></pre>
+
<p>Next we create the default styling for our tile cards and set the <code>transform</code> property to scale the card on <code>:hover</code>:</p>
-<pre><code>/* Default card tile styles */
+
+<pre><code>&#47;* Default card tile styles *&#47;
.card-tile {
border: 1px solid;
border-radius: 10px;
@@ -63,11 +70,16 @@
transform: scale(1.1);
}
</code></pre>
-<h3>Where are my cards?!</h3>
-<p>Don't panic if you can't <em>visually</em> see any card elements in your demo yet - that's to be expected. We will be styling these card elements momentarily.</p>
-<p>Our next step is to hide the default inner <code>text-content</code> and only show it on hover. We achieve this by setting it's position to <code>absolute</code>, placing it's opacity at 0 and pushing it's z-index back to -1.</p>
+
+<h3 id="where-are-my-cards">Where are my cards?!</h3>
+
+<p>Don&#8217;t panic if you can&#8217;t <em>visually</em> see any card elements in your demo yet - that&#8217;s to be expected. We will be styling these card elements momentarily.</p>
+
+<p>Our next step is to hide the default inner <code>text-content</code> and only show it on hover. We achieve this by setting it&#8217;s position to <code>absolute</code>, placing it&#8217;s opacity at 0 and pushing it&#8217;s z-index back to -1.</p>
+
<p>When the user hovers over a main card tile, we change the <code>text-content</code> values of both the opacity and z-index to 1.</p>
-<pre><code>/* Card tile text content */
+
+<pre><code>&#47;* Card tile text content *&#47;
.card-tile .text-content {
background: linear-gradient(rgba(0,0,0,0.4) 0%, rgba(0,0,0,0.6) 100%);
bottom: 10px;
@@ -88,7 +100,9 @@
z-index: 1;
}
</code></pre>
+
<p>Finally we add some minor styling for the inner header and paragraph tags:</p>
+
<pre><code>.card-tile .text-content h4,
.card-tile .text-content p {
color: #fff;
@@ -96,8 +110,11 @@
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
}
</code></pre>
-<h3>Don't forget mobile</h3>
+
+<h3 id="dont-forget-mobile">Don&#8217;t forget mobile</h3>
+
<p>We want out UI to stack the cards if users are viewing them on smaller devices:</p>
+
<pre><code>@media(max-width: 600px) {
.card-tiles-container {
flex-direction: column;
@@ -108,34 +125,39 @@
}
}
</code></pre>
-<h2>Customizing each card</h2>
-<p>Remember how I mentioned that we would be adding more classes to the original HTML? Now is the time. We will be including a simple class on each card tile to provide it's own custom coloring:</p>
-<pre><code>&lt;div class=&quot;card-tiles-container&quot;&gt;
- &lt;!-- `Blue` class --&gt;
- &lt;div class=&quot;card-tile blue&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
- &lt;!-- `Orange` class --&gt;
- &lt;div class=&quot;card-tile orange&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
- &lt;!-- `Green` class --&gt;
- &lt;div class=&quot;card-tile green&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
-&lt;/div&gt;
+
+<h2 id="customizing-each-card">Customizing each card</h2>
+
+<p>Remember how I mentioned that we would be adding more classes to the original HTML? Now is the time. We will be including a simple class on each card tile to provide it&#8217;s own custom coloring:</p>
+
+<pre><code>&#60;div class="card-tiles-container"&#62;
+ &#60;!-- `Blue` class --&#62;
+ &#60;div class="card-tile blue"&#62;
+ &#60;div class="text-content"&#62;
+ &#60;h4&#62;Card Title&#60;&#47;h4&#62;
+ &#60;p&#62;Inner card content text&#60;&#47;p&#62;
+ &#60;&#47;div&#62;
+ &#60;&#47;div&#62;
+ &#60;!-- `Orange` class --&#62;
+ &#60;div class="card-tile orange"&#62;
+ &#60;div class="text-content"&#62;
+ &#60;h4&#62;Card Title&#60;&#47;h4&#62;
+ &#60;p&#62;Inner card content text&#60;&#47;p&#62;
+ &#60;&#47;div&#62;
+ &#60;&#47;div&#62;
+ &#60;!-- `Green` class --&#62;
+ &#60;div class="card-tile green"&#62;
+ &#60;div class="text-content"&#62;
+ &#60;h4&#62;Card Title&#60;&#47;h4&#62;
+ &#60;p&#62;Inner card content text&#60;&#47;p&#62;
+ &#60;&#47;div&#62;
+ &#60;&#47;div&#62;
+&#60;&#47;div&#62;
</code></pre>
+
<p>And these color classes correlate to some new CSS styling:</p>
-<pre><code>/* Blue Card */
+
+<pre><code>&#47;* Blue Card *&#47;
.card-tile.blue {
background-color: #0093E9;
background-image: linear-gradient(0deg, #0093E9 0%, #80D0C7 100%);
@@ -147,8 +169,8 @@
box-shadow: 0 8px 18px rgba(128,208,199,0.4),
inset 0 2px 1px rgba(255,255,255,0.6);
}
-</code></pre>
-<pre><code>/* Orange Card */
+
+&#47;* Orange Card *&#47;
.card-tile.orange {
background-color: #FAD961;
background-image: linear-gradient(180deg, #FAD961 0%, #F76B1C 100%);
@@ -160,8 +182,8 @@
box-shadow: 0 8px 18px rgba(247,107,28,0.4),
inset 0 2px 1px rgba(255,255,255,0.6);
}
-</code></pre>
-<pre><code>/* Green Card */
+
+&#47;* Green Card *&#47;
.card-tile.green {
background-color: #096e40;
background-image: linear-gradient(0deg, #096e40 0%, #2AF598 100%);
@@ -174,52 +196,63 @@
inset 0 2px 1px rgba(255,255,255,0.6);
}
</code></pre>
-<h3>Adding transitions</h3>
-<p>We can now see the actual cards visually and have the ability to interact with them, but there is a problem - they don't animate.</p>
+
+<h3 id="adding-transitions">Adding transitions</h3>
+
+<p>We can now see the actual cards visually and have the ability to interact with them, but there is a problem - they don&#8217;t animate.</p>
+
<p>Lucky we can target all elements we wish to animate with the <code>transition</code> property, like so:</p>
-<pre><code>/* Shared transitions */
+
+<pre><code>&#47;* Shared transitions *&#47;
.card-tile,
.card-tile .text-content {
transition: .3s ease all;
}
</code></pre>
+
<p>Done and done.</p>
-<h2>The final code</h2>
+
+<h2 id="the-final-code">The final code</h2>
+
<p>To make things easier for reference, I have included all the <code>html</code> and <code>css</code> below. Please feel free to use these cards anywhere you like and change them as you see fit!</p>
-<h3>HTML</h3>
-<pre><code>&lt;div class=&quot;card-tiles-container&quot;&gt;
- &lt;div class=&quot;card-tile blue&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
- &lt;div class=&quot;card-tile orange&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
- &lt;div class=&quot;card-tile green&quot;&gt;
- &lt;div class=&quot;text-content&quot;&gt;
- &lt;h4&gt;Card Title&lt;/h4&gt;
- &lt;p&gt;Inner card content text&lt;/p&gt;
- &lt;/div&gt;
- &lt;/div&gt;
-&lt;/div&gt;
+
+<h3 id="html">HTML</h3>
+
+<pre><code>&#60;div class="card-tiles-container"&#62;
+ &#60;div class="card-tile blue"&#62;
+ &#60;div class="text-content"&#62;
+ &#60;h4&#62;Card Title&#60;&#47;h4&#62;
+ &#60;p&#62;Inner card content text&#60;&#47;p&#62;
+ &#60;&#47;div&#62;
+ &#60;&#47;div&#62;
+ &#60;div class="card-tile orange"&#62;
+ &#60;div class="text-content"&#62;
+ &#60;h4&#62;Card Title&#60;&#47;h4&#62;
+ &#60;p&#62;Inner card content text&#60;&#47;p&#62;
+ &#60;&#47;div&#62;
+ &#60;&#47;div&#62;
+ &#60;div class="card-tile green"&#62;
+ &#60;div class="text-content"&#62;
+ &#60;h4&#62;Card Title&#60;&#47;h4&#62;
+ &#60;p&#62;Inner card content text&#60;&#47;p&#62;
+ &#60;&#47;div&#62;
+ &#60;&#47;div&#62;
+&#60;&#47;div&#62;
</code></pre>
-<h3>CSS</h3>
+
+<h3 id="css">CSS</h3>
+
<pre><code>.card-tiles-container {
display: flex;
font-size: 14px;
margin: 20px 0;
}
-/* Shared transitions */
+&#47;* Shared transitions *&#47;
.card-tile,
.card-tile .text-content {
transition: .3s ease all;
}
-/* Default card tile styles */
+&#47;* Default card tile styles *&#47;
.card-tile {
border: 1px solid;
border-radius: 10px;
@@ -230,7 +263,7 @@
position: relative;
width: 33.33%;
}
-/* Blue Card */
+&#47;* Blue Card *&#47;
.card-tile.blue {
background-color: #0093E9;
background-image: linear-gradient(0deg, #0093E9 0%, #80D0C7 100%);
@@ -242,7 +275,7 @@
box-shadow: 0 8px 18px rgba(128,208,199,0.4),
inset 0 2px 1px rgba(255,255,255,0.6);
}
-/* Orange Card */
+&#47;* Orange Card *&#47;
.card-tile.orange {
background-color: #FAD961;
background-image: linear-gradient(180deg, #FAD961 0%, #F76B1C 100%);
@@ -254,7 +287,7 @@
box-shadow: 0 8px 18px rgba(247,107,28,0.4),
inset 0 2px 1px rgba(255,255,255,0.6);
}
-/* Green Card */
+&#47;* Green Card *&#47;
.card-tile.green {
background-color: #096e40;
background-image: linear-gradient(0deg, #096e40 0%, #2AF598 100%);
@@ -266,7 +299,7 @@
box-shadow: 0 8px 18px rgba(9,110,64,0.4),
inset 0 2px 1px rgba(255,255,255,0.6);
}
-/* Card tile text content */
+&#47;* Card tile text content *&#47;
.card-tile .text-content {
background: linear-gradient(rgba(0,0,0,0.4) 0%, rgba(0,0,0,0.6) 100%);
bottom: 10px;
@@ -288,7 +321,7 @@
margin: 0;
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
}
-/* All animations on hover */
+&#47;* All animations on hover *&#47;
.card-tile:hover {
transform: scale(1.1);
}