A reader wrote in asking specifically how to build this layout in CSS Flexbox:
My answer: That’s not really a layout for CSS Flexbox. You could pull it off if you had to, but you’d need some kind of conceit, like grouping the nav and article together in a parent element (if not more grouping). CSS Grid was born to describe this kind of layout and it will be far easier to work with, not to mention that the browser support for both is largely the same these days.
What do you mean by “Holy Grail”?
See, kids, layout on the web used to be so janky that the incredible simple diagram above was relatively difficult to pull off, particularly if you needed the “columns” there to match heights. I know, ridiculous, but that was the deal. We used super weird hacks to get it done (like huge negative margins paired with positive padding), which evolved over time to cleaner tricks (like background images that mimicked columns). Techniques that did manage to pull it off referred to it as the holy grail. (Just for extra clarity, usually, holy grail meant a three-column layout with content in the middle, but the main point was equal height columns).
CSS is much more robust now, so we can use it without resorting to hacks to do reasonable things, like accomplish this basic layout.
Here it is in CSS Grid
This grid is set up both with grid-template-columns and grid-template-rows. This way we can be really specific about where we want these major site sections to fall.
I slipped in some extra stuff
I had another question come my way the other day about doing 1px lines between grid areas. The trick there is as simple as the parent having a background color and using gap: 1px;, so I’ve done that in the demo above.
It’s likely that small screens move down to a single-column layout. I’ve done that at a media query above. Sometimes I use display: block; on the parent, turning off the grid, but here I’ve left grid on and reset the columns and rows. This way, we still get the gap, and we can shuffle things around if needed.
Another recent question I was asked about is the subtle “body border” effect you can see in the demo above. I did it about as simple as possible, with a smidge of padding between the body and the grid wrapper. I originally did it between the body and the HTML element, but for full-page grids, I think it’s smarter to use a wrapper div than use the body for the grid. That way, third-party things that inject stuff into the body won’t cause layout weirdness.
It’s a common misunderstanding that working with a small budget for SEO means you can’t generate results. How can you possibly make enough improvements to the site in so few hours per month?
Well, for us at Tao Digital Marketing, our work with Fleetcover goes to show that results can be achieved by focusing on the most important changes in the little time you have.
In this case study, we’ll break down how we increased leads by 751%, keywords by 259% and impressions by 535% on a budget of less than £1,000 / $1,347 per month, equating to one day’s work. That’s a small spend for SEO, but making the right changes at the right time, and focusing our efforts on the most important aspects, generated these positive results.
Objectives
Our objectives were similar to what every website ultimately wants to achieve: generate leads for the business and increase online visibility for relevant search terms.
To be a little more specific, we picked this client up in March 2019, but of course, results generally started to pick up from November 2019 as Google started to crawl the site more regularly.
Our targets/KPIs for the next 12 months were based on numbers from April-November 2019, as below:
Increase leads from 175 to 500
Install a new chat function on the site and gain 50 leads through it
Increase site clicks from 2,200 to 5,000
Increase keywords ranked for from 229 to 500
The target audience was businesses that need fleet insurance. This spans a wide range of industries, from those operating coaches and taxis through to motor trade.
Our strategy focused on technical SEO and content creation. There was one big issue, though: we didn’t build the site ourselves, nor did we have the level of access that would allow us to make any design or fundamental changes that could support SEO and lead generation. In turn, our strategy had to be heavily content-driven.
Our strategy
1. Add a chat function
In November 2019, we added the ‘TawkTo’ chat function to the site which has helped generate leads. After analyzing when their audience was visiting the website, we found that most users were on the site late at night and on weekends.
With their team being out of the office and unable to answer any phone calls during these timeframes, we thought it would be of value to offer an online chat function to help capture inquiries so potential customers wouldn’t be put off or frustrated! This would put them at an advantage compared to their competitors who were not doing this.
We implemented the bot so it appears on the tab as a message notification, drawing people’s attention to the page even when it isn’t the active tab. So far, 330 inquiries have been made through this function.
Fleetcover Chat Bot
2. Implement technical SEO
Tweaks that support technical SEO are perhaps some of the most important changes you can make to see real results. We implemented this by:
Optimizing page titles
Creating meta descriptions that were between 100-155 characters, using keywords that naturally fit
Using the optimal image sizes that each website required
Using alt text for images
Implementing internal and external links where possible
Utilizing FAQ schema on the more frequently searched questions
Optimizing the sitemap by getting rid of URLs that wouldn't support organic search
Using the robots.txt file to point search crawlers in the right direction
Creating 301 redirects. There were a number of outdated pages as well as 404 errors that needed to be addressed
Making usability tweaks to the design. We were very limited in what we could achieve on the site as the incumbent were not massively helpful in terms of the access they would give us. We were able to get round this in certain areas, an example being the ‘Get a Quote’ buttons. We had a feeling user metrics mattered in this competitive market, so we did our utmost to capitalise on this.
3. Optimize the “Get a Quote” form
We added heat mapping and anonymized visitor recording to the site. When we analyzed the data, it became very apparent that many people weren’t filling out the “Get a Quote'' form due to it being too long — like standing at the bottom of a mountain, trying to work out the right route to the top! The original form had almost 10 questions, which overwhelmed the user and resulted in low conversion rates.
Step one of Fleetcover Quote formStep two of Fleetcover Quote form
We’ve had great success using multi-step forms on other client’s sites, so we decided to create one for Fleetcover. We had all the questions needed to provide a full quotation, but split it all up into easier-to-digest tabs and user-designed icons, rather than just text.
Our new form was built creatively and had four steps, making the process easier. With this change alone, leads from the form grew from 175 before November 2019 to 1,489 over the past 12 months (751% increase).
4. Focus heavily on content creation
Example of Fleetcover service page (HGV fleet insurance)
Service pages
Content creation is an area where we really got the chance to demonstrate creative flair alongside data analysis. We started by reviewing Fleetcover’s service pages, and fleshed out the content to make it more engaging.
Example of Fleetcover service page (FAQs)
Keyword research and search intent
Over time, we continued to research keywords, focusing heavily on understanding the search intent behind them, and creating detailed content and FAQs to meet the audience’s needs and Google's understanding of those intents.
One topic we’ve been focusing on is the rise of electric vehicles and how this will grow and affect the insurance industry. As the development and popularity of these vehicles progresses, we’re going to look at how we can use this in our content strategy.
Formatting and style
Including clear, natural CTAs at the end of each piece was really important, not only to round out the articles, but also to encourage readers to use Fleetcover’s broker service. See an example from our piece about business car insurance below.
In addition, utilizing a simple but effective tone of voice helped to meet the needs of potential consumers and give them the information they need in a straightforward way. When focusing on keywords/phrases that contain industry jargon, we always include information about what the word or phrase means for those with informational intent about a particular topic, for example ‘fleet breakdown cover’.
Results
Sales
We achieved the goal of gaining more sales, as website conversion rates jumped from 3% to 14%, and leads increased from 175 to 1,489 (751%). This massive increase (pleasantly) surprised us as we are working with a site with a domain authority of 22 in a competitive industry, so to achieve these results so quickly was a great boost for both ourselves and Fleetcover.
Fleetcover was previously spending a considerable amount on purchasing leads from other companies, whereas now they have invested into SEO, which has significantly increased the number of leads they generate. With SEO, these leads are of a higher quality than PPC leads, and are therefore more likely to use their services. There is little need for Fleetcover to purchase leads now, as the business is becoming its own profitable arm of Walmsleys Insurance Brokers.
Rankings
We’ve helped Fleetcover gain online visibility for certain keywords such as “fleet insurance brokers” (#1) and “fleet insurance quote” (#2). Their positioning for “Fleet breakdown cover” has also moved from #15 to #4, and “fleet insurance quote” has moved from #10 to #2. The main benefit of these ranking improvements is the huge increase in traffic!
We also gained top spot for the main keyword of “fleet insurance”, but this has since been taken by one of the juggernauts (excuse the pun) of the industry. We’ll be back, but for now, domain authority reigned supreme.
In April 2019, Fleetcover was only ranking for 229 keywords, and they now rank for 824, a 259% increase.
Traffic
As mentioned, we saw results beginning in November as Google crawled the site more actively and found more relevant content. Therefore, April - November 2019 is our “before” comparison for what we’ve managed to achieve over the past 12 months:
April - November 2019:
Impressions: 296,000
Clicks: 2,220
November 2019 - November 2020:
Impressions: 1,880,000 (up 322%)
Clicks: 6,470 (up 194%)
Thanks to more than exceeding our set KPI goals, we were shortlisted for three SEO awards this year, and Fleetcover’s CEO had only good things to say:
“For years we’ve been looking for a company to do exactly what you have done and I can honestly say in 12 years of being involved in marketing, this is the first time that any marketing company has proactively gone ahead and done something for us in this way. I’ve whinged about it for so long that it made my day when it dropped in my inbox. Really chuffed.”
Well, that just speaks for itself, doesn’t it?
Sign up for The Moz Top 10, a semimonthly mailer updating you on the top ten hottest pieces of SEO news, tips, and rad links uncovered by the Moz team. Think of it as your exclusive digest of stuff you don't have time to hunt down but want to read!
from The Moz Blog https://ift.tt/3qSNq6A
via IFTTT
I’m not exactly a large-scale DevOps guy, but I can tell ya we’ve been moving back toward a monorepo at CodePen and it’s rife with advantages over a system with lots of smaller repos. For us, I mean. It’s very likely that you have entirely different challenges and have come to entirely different conclusions at your place. 🤙
Microservices Solve Both Technical and People Problems
A technical problem is one in which an aspect of the application is putting an undue burden on the infrastructure; which, in turn, is likely causing a poor user experience (UX). For example, image processing requires a lot of CPU. If this CPU load becomes too great, it could start starving the rest of the application of processing resources. This could affect system latency. And, if it gets bad enough, it could start affecting system availability.
A people problem, on the other hand, has little to do with the application at all and everything to do with how your team is organized. The more people you have working in any given part of the application, the slower and more error-prone development and deployment becomes. For example, if you have 30 engineers all competing to “Continuously Deploy” (CD) the same service, you’re going to get a lot of queuing; which means, a lot of engineers that could otherwise be shipping product are actually sitting around waiting for their turn to deploy.
Advantages of the Monorepo (for us)
One ring to rule them all. You git pullone repo and you are 100% up to date with everyone else and have everything you need for a complete dev environment.
No stray puppies. There is no confusion on where the action happens on GitHub. You do pull requests against the monorepo. You open issues on the monorepo. This avoids scattered activity that gets lost.
Kumbaya. You can share code. It can be particularly helpful to share utilities or components anywhere in the codebase. We poked at ideas like publishing shared bits to npm for other repos to use, but that workflow was janky compared to having the code together in on place.
Growing old together. There are no old and neglected repos, because it’s just one. For our small team, having dozens of repos meant some of them had old outdated dependencies, ancient versions of Node, linting and formatting rules that were out of sync with other repos, etc.
Disadvantages of the Monorepo (for us)
Deployment trickiness. I think the main reason we split off repos originally is that the code in those repos needed to go to unique places. They might have represented an individual Lambda or individual service on some other server. An individual repo means it’s easier to hook up stuff that is unique to that server/service, like CI/CD.
Yes, I get that this is controversial.
I actually don’t care that much. I’m not gonna get all intense about this like air fryer people and CrossFit zealots. Here’s a full-throated argumentagainst monorepos from Matt Klein.
I’m just saying: it’s been clearly useful for us. I can see how things play out differently for other companies. I can see how a company that works with contractors might want to limit their access to something less than an entire monorepo. I can see how a git repo might become unwieldy and large. Those aren’t problems for us at CodePEn right now, so the advantages of a monorepo win.
Backlinks continue to be especially valuable for SEO, acting as a signal to search engines that vouches for both the value of your content and the worthiness of your website.
In measuring the success of your backlink efforts and informing your future SEO priorities, the data matters. Depending on the tool you use, your results can vary greatly and — in this case — the more data the better.
With this in mind, we’re excited to share that Moz has the largest link data set, according to a study done by Perficient.
The study compared 3,000 search queries across the Technology, Health, and Finance market sectors to evaluate the link indexes of Moz, Ahrefs, SEMrush, and Majestic. The queries were evenly split across the sectors, and then used to pull results from Google for the top 100 domains. This led to the statistically significant sample size of 85,308 domains. Perficient then used the APIs for all four link indexes and evaluated the results. Perficient also performed manual checks to validate results.
Full disclosure: Moz financed the study, but Perficient conducted it independently — the conclusions are 100% their own, with no influence from Moz.
"The link graph — the sum total of all of the links that connect the pages on the worldwide web — is the foundation of PageRank and the original Google algorithm. While a lot has changed in 20 years, high-authority links are still a driving force in how Google values and surfaces content. Our goal is to reveal as much of the link graph as possible to understand how Google sees the web and rewards authoritative content, while at the same time helping people focus on the highest quality and most actionable links." — Dr. Pete Meyers
Results
The Moz link index reported approximately 90% more links than Majestic, which reported the second-largest. Moz reported the most links per domain 72% of the time.
In link research, size matters. Whether you’re launching a link building campaign, performing competitive analysis, or creating a Google disavow file, finding the most complete set of links to any URL or domain directly impacts the quality of your work as an SEO.
Moz reported the most linking domains 60% of the time.
When performing link research, the number of raw links isn't always as important as the number of unique linking domains. A tool that reports a million links, but all from the same domain, isn't nearly as valuable as a tool that reports 1,000 links from 100 different domains. Links often repeat across the same domain (think footer or sidebar links), so finding the most unique linking domains — as opposed to raw link counts — is often a more useful metric for SEOs.
Moz narrowly trailed Majestic by 0.2% as having the lowest percent of duplicate links.
Link counts can be inflated when tools report duplicate links. For example, some tools might report a link found with both HTTP:// and HTTPS:// as two separate links, even though one canonicals to the other. A lower percentage of duplicate links can indicate better data quality.
This is the second study in recent months to determine that Moz link data stands above the rest. In October of 2020, Search Engine Land compared eight SEO tools, and also noted that Moz reports a significantly higher number of linking domains.
Reviews
Perhaps just as important as the breadth of the data is that Moz tools make managing SEO easier, as these reviews mention:
Carly Schoonhoven, Senior SEO Manager at Obility: “Moz makes my life easier in so many ways. When doing link building, particularly, I absolutely love the link intersect tool. It’s a really great way to find linking opportunities quickly without having to put in a lot of extra effort. I also love that, you know, any data you need is really only just a couple of clicks away, whether it be site errors or backlinks or keywords. It just really is intuitive and makes finding data really fast.”
Kristina Kledzik, SEO Manager at Rover: “Moz has been a critical part of my link building strategies and competitive analysis for five years now, through agency work and in-house SEO. It’s easy to use, easy to understand, and adds an extra layer of information to every website you visit. Definitely a must have for any SEO.”
Lily Ray, SEO Director at Path Interactive: “I love using Moz Link Explorer to see how potential clients are doing compared to their competitors. You can get as granular as looking at the individual URL level, which is really helpful.”
Sign up for The Moz Top 10, a semimonthly mailer updating you on the top ten hottest pieces of SEO news, tips, and rad links uncovered by the Moz team. Think of it as your exclusive digest of stuff you don't have time to hunt down but want to read!
from The Moz Blog https://ift.tt/2LYm7ZW
via IFTTT
You know, Porky Pig coming out of those red rings announcing the end of a Looney Tunes cartoon. We’ll get there, but first we need to cover some CSS concepts.
Everything in CSS is a box, or rectangle. Rectangles stack, and can be displayed on top of, or below, other rectangles. Rectangles can contain other rectangles and you can style them such that the inner rectangle is visible outside the outer rectangle (so they overflow) or that they’re clipped by the outer rectangle (using overflow: hidden). So far, so good.
What if you want a rectangle to be visible outside its surrounding rectangle, but only on one side. That’s not possible, right?
Perhaps, when you look at the image above, the wheels start turning: What if I copy the inner rectangle and clip half of it and then position it exactly?. But when it comes down to it, you can’t choose to have an element overflow at the top but clip at the bottom.
Or can you?
3D transforms
Using 3D transforms you can rotate, transform, and translate elements in 3D space. Here’s a group of practical examples I gathered showcasing some possibilities.
For 3D transforms to do their thing, you need two CSS properties:
perspective, using a value in pixels, to determine how pronounced the 3D effect is
transform-style: preserve-3d, to tell the browser to keep elements positioned in 3D space.
Even with the good support that 3D transforms have, you don’t see 3D transforms ‘in the wild’ all that much, sadly. Websites are still a “2D” thing, a flat page that scrolls. But as I started playing around with 3D transforms and scouting examples, I found one that was by far the most interesting as far as 3D transforms go:
The image clearly shows three planes but this effect is achieved using a single <div>. The two other planes are the ::before and ::after pseudo-elements that are moved up and down respectively, using translate(), to stack on top of each other in 3D space. What is noticeable here is how the ::after element, that normally would be positioned on top of an element, is behind that element. The creator was able to achieve this by adding transform: translateZ(-1px);.
Even though this was one of many 3D transforms I had seen at this point, it was the first one that made me realize that I was actually positioning elements in 3D space. And if I can do that, I can also make elements intersect:
I couldn’t think of how this sort of thing would be useful, but then I saw the Porky Pig cartoon animation. He emerges from behind the bottom frame, but his face overlaps and stacks on top of the top edge of the same frame — the exact same sort of clipping situation we saw earlier. That’s when my wheels started turning. Could I replicate that effect using just CSS? And for extra credit, could I replicate it using a single <div>?
I started playing around and relatively quickly had this to show for it:
Here we have a single <div> with its ::before and an ::after pseudo-elements. The div itself is transparent, the ::before has a blue border and the ::after has been rotated along the x-axis. Because the div has perspective, everything is positioned in 3D and, because of that, the ::after pseudo-element is above the border at the top edge of the frame and behind the border at the bottom edge of the frame.
With perspective, we can determine how far a viewer is from “z=0” which we can consider to be the “horizon” of our CSS 3D space. The larger the perspective, the less pronounced the 3D effect, and vice versa. For most 3D scenes, a perspective value between 500 and 1,000 pixels works best, though you can play around with it to get the exact effect you want. You can compare this with perspective drawing: If you draw two horizon points close together, you get a very strong perspective; but if they’re far apart, then things appear flatter.
From rectangles to cartoons
Rectangles are fun, but what I really wanted to build was something like this:
I couldn‘t find or create a nicely cut-out version of Porky Pig from that image, but the Wikipedia page contains a nice alternative, so we’ll use that.
First, we need to split the image up into three parts:
<div>: the blue background behind Porky
::after: all the red circles that form a sort of tunnel
::before: Porky Pig himself in all his glory, set as a background image
We’ll start with the <div>. That will be the background as well as the base for the rest of the elements. It’ll also contain the perspective and transform-style properties I called out earlier, along with some sizes and the background color:
Alright, next up, we‘ll move to the red circles. The element itself has to be transparent because that’s the opening where Porky emerges. So how shall we go about it? We can use a border just like the example earlier in this article, but we only have one border and that can have a solid color. We need a bunch of circles that can accept gradients. We can use box-shadow instead, chaining multiple shadows in the property values. This gets us all of the circles we need, and by using a blur radius value of 0 with a large spread radius, we can create the appearance of multiple “borders.”
We‘ll use a border-radius that‘s as large as the <div> itself, making the ::before a circle. Then we’ll add the shadows. When we add a few red circles with a large spread and add blurry white, we get an effect that looks very similar to the Porky’s tunnel.
Here, we’re adding five circles, where each is 30px wide. Each circle has a solid red background. And, by using white shadows with a blur radius of 20px on top of that, we create the gradient effect.
With the background and the circles sorted, we’re now going to add Porky. Let’s start with adding him at the spot we want him to end up, for now above the circles.
You might have noticed that slash in “center/contain” for the background. That’s the syntax to set both the position (center) and size (contain) in the background shorthand CSS property. The slash syntax is also used in the font shorthand CSS property where it’s used to set the font-size and line-height like so: <font-size>/<line-height>.
The slash syntax will be used more in future versions of CSS. For example, the updated rgb() and hsl() color syntax can take a slash followed by a number to indicate the opacity, like so: rgb(0 0 0 / 0.5). That way, there’s not need to switch between rgb() and rgba(). This already works in all browsers, except Internet Explorer 11.
Both the size and positioning here is a little arbitrary, so play around with that as you see fit. We’re a lot closer to what we want, but now need to get it so the bottom portion of Porky is behind the red circles and his top half remains visible.
The trick
We need to transpose both the circles as well as Porky in 3D space. If we want to rotate Porky, there are a few requirements we need to meet:
He should not clip through the background.
We should not rotate him so far that the image distorts.
His lower body should be below the red circles and his upper body should be above them.
To make sure Porky doesn‘t clip through the background, we first move the circles in the Z direction to make them appear closer to the viewer. Because preserve-3d is applied it means they also zoom in a bit, but if we only move them a smidge, the zoom effect isn’t noticeable and we end up with enough space between the background and the circles:
transform: translateZ(20px);
Now Porky. We’re going to rotate him around the X-axis, causing his upper body to move closer to us, and the lower part to move away. We can do this with:
transform: rotateX(-10deg);
This looks pretty bad at first. Porky is partially hidden behind the blue background, and he’s also clipping through the circles in a weird way.
We can solve this by moving Porky “closer” to us (like we did with the circles) using translateZ(), but a better solution is to change the position of our rotation point. Right now it happens from the center of the image, causing the lower half of the image to rotate away from us.
If we move the starting point of the rotation toward the bottom of the image, or even a little bit below that, then the entirety of the image rotates toward us. And because we already moved the circles closer to us, everything ends up looking as it should:
transform: rotateX(-10deg);
transform-origin: center 120%;
To get an idea of how everything works in 3D, click “show debug” in the following Pen:
Animation
If we keep things as they are — a static image — then we wouldn’t have needed to go through all this trouble. But when we animate things, we can reveal the layering and enhance the effect.
Here‘s the animation I’m going for: Porky starts out small at the bottom behind the circles, then zooms in, emerging from the blue background over the red circles. He stays there for a bit, then moves back out again.
We’ll use transform for the animation to get the best performance. And because we’re doing that, we need to make sure we keep the rotateX in there as well.
Soon, we’ll be able to directly set different transforms, as browsers have started implementing them as individual CSS properties. That means that repeating that rotateX(-10deg) will eventually be unnecessary; but for now, we have a little bit of duplication.
We zoom in and out using the scale() function and, because we’ve already set a transform-origin, scaling happens from the center-bottom of the image, which is precisely the effect we want! We’re animating the scale up to 60% of Porky’s actual size, we have the little break at the largest point, where he fully pops out of the circle frame.
The animation goes on the ::before pseudo-element. To make the animation look a little more natural, we’re using an ease-in-out timing function, which slows down the animation at the start and end.
Glad you asked! For people who are sensitive to animations and prefer reduced or no motion, we can reach for the prefers-reduced-motion media query. Instead of removing the full animation, we’ll target those who prefer reduced motion and use a more subtle fade effect rather than the full-blown animation.
By overwriting the @keyframes inside a media query, the browser will automatically pick it up. This way, we still accentuate the effect of Porky emerging from the circles. And by setting animation-iteration-count to 1, we still let people see the effect, but then stop to prevent continued motion.
Finishing touches
Two more things we can do to make this a bit more fun:
We can create more depth in the image by adding a shadow behind Porky that grows as he emerges and appears to zoom in closer to the view.
We can turn Porky as he moves, to embellish the pop-out effect even further.
That second part we can implement using rotateZ() in the same animation. Easy breezy.
But the first part requires an additional trick. Because we use an image for Porky, we can’t use box-shadow because that creates a shadow around the box of the ::before pseudo-element instead of around the shape of Porky Pig.
That’s where filter: drop-shadow()comes to the rescue. It looks at the opaque parts of the element and adds a shadow to that instead of around the box.
My stack requires no maintenance, has perfect Lighthouse scores, will never have any security vulnerability, is based on open standards, is portable, has an instant dev loop, has no build step and… will outlive any other stack.
Instead of reaching for all-singing all-dancing toolchain by default, I’m going to start with a boring baseline. If and when that becomes too painful or unwieldy, then I’ll throw in a task manager. But every time I add a dependency, I’ll be limiting the lifespan of the project.
I like both of those sentiments.
Steren’s “stack” is HTML and CSS only. Will HTML and CSS “last” in the sense of that website being online and working for a long time. I’d say certainly yes. HTML and CSS were around before I got here, are actively developed, and no other technologies are really even trying to unseat them. The closest threats are native platforms, but those are so fractured, closed, while lacking the worldwide utility of the URL and open standards, that it doesn’t look like that any native platform will unseat the web. It’s more likely (and we see this happening, even if it’s slow and fraught) that native platforms embrace the web.
Will an HTML and CSS website be perfectly functional in, say, 2041? I’d say certainly. I’ll bet ya a dollar.
Steren doesn’t mean that HTML and CSS is just the output, but there is still other tooling to get there. No build process either. No templating. Need to update the navigation?
So… if I don’t use any templating system, how do I update my header, footer or nav? Well, simply by using the “Replace in files” feature of any good text editor. They don’t need frequent updates anyway. The benefits of using a templating system is not worth the cost of introducing the tooling it requires.
I admit this is drawing the line further back than I would. This feels just like trading one kind of technical debt for another. Now you’ll need to write scripts or an elaborate find-and-replace RegEx to do what you want to do, rather than reach for some form of HTML include, which there are a ton of ways to handle lightly.
But I get it. Especially since once you do add that one templating language (or whatever), the temptation is strong to keep adding to the system, introducing more and more liabilities with less consideration on how they may be “limiting the lifespan” of the project.
I don’t actually think the stack matters that much.
You know what technology stack will build the longest-lasting websites?
It isn't one.
The trick is caring about and being invested in what you're building.
In thinking about sites I work on (and have worked on), the longevity of the site doesn’t feel particularly related to the stack. Like, at all. The sites with the longest lifespans (like this one) have long lifespans because I care about them, and they have all sorts of moving parts in the stack.
I pick technology to help with what I want to do. If my needs change, I change the technology. I don’t just say, ooops, my stack is off, I guess I’ll shut down the website forever.
If we’re talking about website longevity, I think the breakdown of how much things matter is more like this:
80% How much I care about the website
10% The website isn’t a financial burden
5% The website isn’t a mental burden (“the stack” being some small part of this)
5% I have access to the registrant and didn’t forget to renew the domain name before a squatter nabs it
Back when I was 10, I remember my cousin visiting our house. He was (and still is) a cool kid, the kind who’d bring his own self-programmed chess game on a floppy disk. And his version of chess was just as cool as him because a piece of the board would disappear after each move.
Even cooler? Each disappearing piece of the game board revealed a pretty slick picture.
It was a really hard game.
I thought that same sort of idea would make for some pretty slick UI. Except, maybe instead of requiring user interaction to reveal the background, it could simply play as an animation. Here’s where I landed:
The idea’s pretty simple and there are lots of other ways to do it, but here’s the rabbit trail I followed…
First, I created some markup
The image can be handled as a background in CSS on the <body>, or some <div> that’s designed to be a specific size. So, no need to deal with that just yet.
But the checkerboard is interesting. That’s a pattern that has CSS Grid written all over it, so I went with an element to act as a grid container with a bunch of other <div> elements right inside it. I don’t know how many tiles/squares/whatever a legit chess board has, so I just chose the number seven out of thin air and squared it to get 49 total squares.
<div class="grid">
<div></div>
<!-- etc. -->
<div></div>
</div>
Yeah, writing out all those divs is a pain and where JavaScript could certainly help. But if I’m just experimenting and only need the developer convenience, then that’s where using Haml can help instead:
.grid
- 49.times do
%div
It all comes out the same in the end. Either way, that gave me all the markup I needed to start styling!
Setting the background image
Again, this can happen as a background-image on the <body> or some other element, depending on how this is being used — just as long as it covers the entire space. Since I needed a grid container anyway, I decided to use that.
.checkerboard {
background-image: url('walrus.jpg');
background-size: cover;
/* Might need other properties to position the image just right */
}
The gradient is part of the raster image file, but I could’ve gotten clever with some sort of overlay on the <body> using a pseudo-element, like :after. Heck, that’s a widely used technique right here on the current design of CSS-Tricks.
Styling the grid
And yes, I went with CSS Grid. Making a 7×7 grid is pretty darn easy that way.
I imagine this will be a lot better once we see aspect-ratio widely supported, at least if I correctly understand it. The problem I have right now is that the grid doesn’t stay in any sort of proportion. That means the checkerboard’s tiles get all squishy and such at different viewport sizes. Boo. There are hacky little things we can do in the meantime, if that’s super important, but I decided to leave it as is.
Styling the tiles
They alternate between white and a dark shade of grey, so:
Yes, I could have used the animation shorthand property here, but I often find it easier to break its constituent properties out individually because… well, there’s so gosh darn many of them and things get hard to read and identify on a single line.
If you’re wondering why animation-fill-mode is needed here, it’s because it prevents the animation from looping back to the start of the animation when set to forwards. In other words, each tile will stay at opacity: 0; when the animation finishes rather than coming back into view.
I really, really wanted to do something smart and clever to stagger the animation-delay of the tiles, but I hit a bunch of walls and ultimately decided to ditch my effort to go 100% vanilla CSS for some light SCSS. That way, I could loop through all of the tiles and offset the animation for each one with a pretty standard function. So, sorry for the abrupt switch! That was just part of the journey.
There are variables for the number of grid columns ($columns), grid rows ($rows), and total number of cells ($cells). That last one is the product of multiplying the first two. If we know we are always working in with a grid that’s a perfect square, then we could refactor that a bit to calculate the number cells with exponents.
Then for every instance of cells between 1 and the total number of $cells (which is 49 in this case), each individual tile gets an animation-delay based on its :nth-child() value. So, the first tile is div:nth-child(1), then div:nth-child(2), and so on. View the compiled CSS in the demo and you’ll see how it all breaks out.
Finally, the animation-delay is a calculation that takes a random number between 1 and the total number of $cells, divided by the number of $columns with seconds appended to the value. Is this the best way to do it? I dunno. It comes down to playing around with things a bit and landing on something that feels “right” to you. This felt “right” to me.
I really, really wanted to get creative and use CSS Custom Properties instead of resorting to SCSS. I like that custom properties and values can be updated client-side, as opposed to SCSS where the calculated values are compiled on build and stay that way. Again, this is exactly where I would be super tempted to reach for JavaScript instead. But, I made my bed and have to lie in it.
If you peeked at the compiled CSS earlier, then you would have seen the calculated values:
Some folks are sensitive to motion and movement, so it’s probably a good idea to switch things up so the tiles are only styled and animation if — and only if — a user prefers it. We have a media query for that!