Thursday, February 6
CSS Tricks

POSTing an Indeterminate Checkbox Value

There is a such thing as an indeterminate checkbox value. It's a checkbox (<input type="checkbox">) that isn't checked. Nor is it not checked. It's indeterminate. We can even select a checkbox in that state and style it with CSS! Some curious points though: It's only possible to set via JavaScript. There is no HTML attribute or value for it. It doesn't POST (or GET or whatever else) or have a value. It's like being unchecked.   So, say you had a form like this: <form action="" method="POST" id="form"> <input name="name" type="text" value="Chris" /> <input name="vegetarian" type="checkbox" class="veg"> <input type="submit" value="Submit"> </form> And, for whatever reason, you make that checkbox indeterm...
CSS Tricks

The Way We Talk About CSS

There’s a ton of very quotable stuff from Rachel Andrew’s latest post all about CSS and how we talk about it in the community: CSS has been seen as this fragile language that we stumble around, trying things out and seeing what works. In particular for layout, rather than using the system as specified, we have so often exploited things about the language in order to achieve far more complex layouts than it was ever designed for. We had to, or resign ourselves to very simple looking web pages. Rachel goes on to argue that we probably shouldn’t disparage CSS for being so weird when there are very good reasons for why and how it works — not to mention that it’s getting exponentially more predictable and powerful as time goes by: There is frequently talk about how developers whose main area...
CSS Tricks

Styling the Gutenberg Columns Block

WordPress 5.0 is quickly approaching, and the new Gutenberg editor is coming with it. There’s been a lot of discussion in the WordPress community over what exactly that means for users, designers, and developers. And while Gutenberg is sure to improve the writing experience, it can cause a bit of a headache for developers who now need to ensure their plugins and themes are updated and compatible. One of the clearest ways you can make sure your theme is compatible with WordPress 5.0 and Gutenberg is to add some basic styles for the new blocks Gutenberg introduces. Aside from the basic HTML blocks (like paragraphs, headings, lists, and images) that likely already have styles, you’ll now have some complex blocks that you probably haven’t accounted for, like pull quotes, cover images, butto...
Designing Experiences To Improve Mental Health
Web Tricks

Designing Experiences To Improve Mental Health

Did you know that a simple search for “depression” on the iPhone App Store brings up 198 results? In the Android Play Store, it brings up 239. The categories range from “Medical” to “Health & Fitness” to “Lifestyle.” The apps themselves offer everything from “depressing wallpaper” to “mood tracker” to “life coach.” We are approaching a golden age of digital therapeutics and design for mental health — if we as UX practitioners do our jobs well. Given the plethora of apps available, you might assume that there are already dozens of wonderful digital therapies available for people struggling with mental health disorders. But — according to initial studies by clinical psychologists — you would be wrong. Most apps are useless at best, and harmful at worst, due primarily to a disconnect b...
5 Secrets of Image-Rich Websites
Web Tricks

5 Secrets of Image-Rich Websites

When was the last time you visited a website with no images? As web designers, we love adding images to our designs because images are memorable and give us a direct channel of communication to the audience’s brain. Also, images are universal and processed by our brains faster than text. That’s partly why the “story” medium (short-form videos with effects and overlays) and emojis attract engagement. But something else has also been happening since “web 2.0” came along. The high usage of images all over the web, some fueled by user-generated content, is creating a problem for web designers who now must deliver rich experiences in the face of an ever-increasing number of images. In the following sections, we’ll discuss in detail five things to keep in mind when designing smart, imag...
Authenticate a Node ES6 API with JSON Web Tokens
Web Tricks

Authenticate a Node ES6 API with JSON Web Tokens

In this guide, we'll be implementing token based authentication in our own node.js A.P.I. using JSON web tokens. Plan of attack We'll begin by: Setting up our development environment and initializing our express server. Creating our first basic route and controller. Fleshing out our routes and controllers to add users and login users. Creating a route and controller that will handle getting all users. Finally, we'll Add middleware to protect our get users route by requiring a user to be an admin and to have a valid token. Validate that only an admin with a token can access the protected route. Sounds exciting? Let's get to it then. Setup Before we get started in earnest, we'll need to have a few things taken care of. Folder structure Here's what our folder...
CSS Tricks

Valid CSS Content

There is a content property in CSS that's made to use in tandem with the ::before and ::after pseudo elements. It injects content into the element. Here's an example: <div data-done="✅" class="email"> chriscoyier@gmail.com </div> .email::before { content: attr(data-done) " Email: "; /* This gets inserted before the email address */ } The property generally takes anything you drop in there. However, there are some invalid values it won't accept. I heard from someone recently who was confused by this, so I had a little play with it myself and learned a few things.   This works fine: /* Valid */ ::after { content: "1"; } ...but this does not: /* Invalid, not a string */ ::after { content: 1; } I'm not entirely sure why, but I imagi...
Web Tricks

Saving Grandma’s Recipes With Xamarin.Forms

My grandma makes the best, most fluffiest, go weak-in-your-knees buns that anybody has ever tasted. The problem is, there’s a ton of secret ingredients (and I’m not just talking love) that go into those buns, and those ingredients and directions are all stored in my grandma’s head.We all have family recipes like that, and instead of possibly forgetting them, in this article we’re going to create a mobile app for iOS and Android using Xamarin.Forms that will save them for myself and future generations of my family! So if you’re interested in writing mobile applications, but don’t have the time to write the same app over and over again for each platform, this article is for you! Don’t worry if you don’t know C# from a Strawberry Pretzel Salad; I’ve been writing Xamarin apps for over 8 y...
Create Sites Easily with WP Page Builder
Web Tricks

Create Sites Easily with WP Page Builder

There’s little doubt that WordPress is one of the biggest web technologies in the world, powering around a third of the web, and growing all the time. Until recently WordPress was only for the initiated, those developers who’d spent years learning how to dig into the source code and tinker, without breaking their whole site. In the last few years WordPress has been revolutionized by the introduction of page builders, applications that allow anyone—even someone with no design or coding knowledge—to create a professional standard WordPress site on the fly. Today, we’re talking about one of the most lightweight options on the market, with performance that outstrips many rival tools: WP Page Builder. WP Page Builder is the perfect tool for web professionals who want to branch into WordPr...
CSS Tricks

How to resize an Image using CSS object-fit Property

The CSS object-fit property is used to specify how an image or video should be resized to fit its container. This property tells the content to fill the container in a variety of ways; such as "preserve that aspect ratio" or "stretch up and take up as much space as possible". Example: We can use object-fit property like below. img { width: 200px; height: 400px; object-fit: cover; }   The object-fit property can have the following values: fill - This is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit contain - The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box cover - The replaced content is sized to maintain its aspect rat...
Web Tricks

Laravel Eloquent: API Resources

Introduction When creating API's, we sometimes specifying the data they want back in the various controller actions: public function show(Book $book) { return response()->json([ 'data' => [ 'title' => $book->title, 'description' => $book->description, 'author' => $book->author->name ] ]); } Notice we omitted the attributes created_at and updated_at when formatting the response? Take another scenario where we want to update a book and expect a response back. public function update(Request $request, Book $book) { $book = $book->update($response->all()); return response()->json([ 'data' => [ 'title' => $book->title, 'description...
Using Event Bus to Share Props Between Vue Components
CSS Tricks

Using Event Bus to Share Props Between Vue Components

By default, communication between Vue components happen with the use of props. Props are properties that are passed from a parent component to a child component. For example, here’s a component where title is a prop: <blog-post title="My journey with Vue"></blog-post> Props are always passed from the parent component to the child component. As your application increases in complexity, you slowly hit what is called prop drilling that is React-focused, but totally applies). Prop drilling is the idea of passing props down and down and down to child components — and, as you might imagine, it’s generally a tedious process. So, tedious prop drilling can be one potential problem in a complex. The other has to do with the communication between unrelated components. We can tackle a...
How to Create Magnetic Content
Web Tricks

How to Create Magnetic Content

I know I know: Content is king! You’re already sick to the back-teeth of hearing it.
 You’ve made your content, you know your target audience—you just want to build some links and get some darn traffic to that content, am I right? Not to rain on your parade, but what if your content really is trash?
 Will anyone actually link to it? If it is subpar, then probably not, and trying to build links to it will be a colossal waste of time. I’m borrowing this saying from a giant in the SEO field, Ryan Stewart: If you don’t have anything of value to say, don’t say anything at all Only create content which will be of real value to people. If you provide, true, honest value in your content the audience will love you. Don’t hold back! Don’t worry about things like “does providing free stuff de...
Form Design Patterns Book Excerpt: A Registration Form
Web Tricks

Form Design Patterns Book Excerpt: A Registration Form

Let’s start with a registration form. Most companies want long-term relationships with their users. To do that they need users to sign up. And to do that, they need to give users value in return. Nobody wants to sign up to your service — they just want to access whatever it is you offer, or the promise of a faster experience next time they visit. Despite the registration form’s basic appearance, there are many things to consider: the primitive elements that make up a form (labels, buttons, and inputs), ways to reduce effort (even on small forms like this), all the way through to form validation. In choosing such a simple form, we can zoom in on the foundational qualities found in well-designed forms. How It Might Look The form is made up of four fields and a submit button. Each fie...
Web Tricks

React Apps with the Google Maps API and google-maps-react

This tutorial aims at integrating the google maps API to your React components and enabling you to display maps on your website. Introduction to Google Maps API. At some point of our lives, we've all gotten a chance to use and interact with the google maps, either through finding directions, viewing our current location, ordering cabs or estimating distance and time from one point to another. Including the Google maps API in a React App is actually far much easier than expected due to its rich documentation which I highly suggest that you look into, and the npm package by Fullstack React. Prerequisite: React Knowledge (at least intermediate level) A Google Maps API Key Go on ahead and grab your API key here. Simply click on the Get Started button Tick on the maps...