Friday, April 19

CSS Tricks

CSS Tricks

​Truly understand your site visitors’ behavior

(This is a sponsored post.)Hotjar is a quick and easy way to truly understand your visitors and identify opportunities for improvement and growth. Try the all-in-one analytics and feedback tool for free. Direct Link to Article — PermalinkThe post ​Truly understand your site visitors’ behavior appeared first on CSS-Tricks. Source: CSS-tricks.com
Understanding the Almighty Reducer
CSS Tricks

Understanding the Almighty Reducer

I was recently mentoring someone who had trouble with the .reduce() method in JavaScript. Namely, how you get from this: const nums = [1, 2, 3] let value = 0 for (let i = 0; i < nums.length; i++) { value += nums[i] } ...to this: const nums = [1, 2, 3] const value = nums.reduce((ac, next) => ac + next, 0) They are functionally equivalent and they both sum up all the numbers in the array, but there is a bit of paradigm shift between them. Let's explore reducers for a moment because they're powerful, and important to have in your programming toolbox. There are literally hundreds of other articles on reducers out there, and I'll link up some of my favorites at the end. What is a reducer? The first and most important thing to understand about a reducer is that it will always only retu...
Your Brain on Front-End Development
CSS Tricks

Your Brain on Front-End Development

Part of the job of being a front-end developer is applying different techniques and technologies to pull of the desired UI and UX. Perhaps you work with a design team and implement their designs. I know when I look at a design (heck, even if I know I'm not going to be building it), my front-end brain starts triggering all sorts of things I know will be related to the task. Let's take a look at what I mean. Check out this lovely Dribbble shot for a Food Recipe Website from Riko Sapto Dimo. It's a very appealing design, and there is loads in there to think about from a front-end web design and development standpoint. We're going to mostly be talking about design pattern choices and HTML/CSS tech choices. There is much more to the job of front-end development. Accessibility! Performance! Se...
CSS Tricks

A Quick Roundup of Recent React Chatter

Like many, many others, I'm in the pool of leveling up my JavaScript skills and learning how to put React to use. That's why Brad Frost resonated with me when he posted My Struggle to Learn React." As Brad does, he clearly outlines his struggles point-by-point: I have invested enough time learning it React and ES6 travel together Syntax and conventions Getting lost in this-land I haven’t found sample projects or tutorials that match how i tend to work I'm less competent at JS than HTML and CSS It seems that Brad's struggles resonated with others as well, inspiring empathy and help from the community. For example, Kevin Ball touches on the second and third frustrations by supplying a distinction between React and ES6 and examples of the syntax and conventions of each: For each feature, I s...
Creating a Bar Graph with CSS Grid
CSS Tricks

Creating a Bar Graph with CSS Grid

If you’re looking for more manageable ways to create bar graphs, or in search of use cases to practice CSS Grid layout, I got you! Before we begin working on the graph, I want to talk about coding the bars, when Grid is a good approach for graphs, and we’ll also cover some code choices you might consider before getting started. Preface The bar is a pretty basic shape: you can control its dimensions with CSS width, height, number of grid or table cells, etc. depending on how you’ve coded it. As far as graphs go, the main thing we want to control is the height of the bars in the graph. Controlling height with Grid cells (like here) is convenient for designs where the height is incremental by a fixed value — no in-betweens. For example, signal bars in phones or when you don’t mind setting a ...
CSS Tricks

​​Build live comments with sentiment analysis using Nest.js

(This is a sponsored post.)Interestingly, one of the most important areas of a blog post is the comment section. This plays an important role in the success of a post or an article, as it allows proper interaction and participation from readers. This makes it inevitable for every platform with a direct comments system to handle it in realtime. In this post, we’ll build an application with a live comment feature. This will happen in realtime as we will tap into the infrastructure made available by Pusher Channels. We will also use the sentiment analysis to measure whether comments are positive or negative, and display this information on an admin panel. Direct Link to Article — PermalinkThe post ​​Build live comments with sentiment analysis using Nest.js appeared first on CSS-Tricks. ...
CSS Tricks

Versioning Interview

Adam Roberts (who you might recognize from our interview with him), interviewed me for the Versioning newsletter. I'm publishing my answers here for y'alls perusal as well! Which dev/tech idea or trend excites you the most at the moment, and why? I love that new JavaScript has arrived. I don’t know if "new JavaScript" is really the word for it, but that’s what it feels like. Major syntax improvements coupled with state and component-based thinking, coupled with powerful frameworks tying it all together: React, Angular, Vue, Ember, etc. Plus the ecosystem they live in, which often includes ES6+ processing, building/bundling, state management tools, and more. Particularly impressive are tools like Create React App that get you cooking on a whole fancy setup like that in seconds. Vue CLI is...
Digging Into React Context
CSS Tricks

Digging Into React Context

You may have wondered lately what all the buzz is about Context and what it might mean for you and your React sites. Before Context, when the management of state gets complicated beyond the functionality of setState, you likely had to make use of a third party library. Thanks to recent updates by the awesome React team, we now have Context which might help with some state management issues. What Does Context Solve? How do you move the state from a parent component to a child component that is nested in the component tree? You know that you can use Redux to manage state, but you shouldn’t have to jump to Redux in every situation. There's a way to do this without Redux or any other third party state management tool. You can use props! Say the feature you want to implement has a tree struct...
Creating a VS Code Theme
CSS Tricks

Creating a VS Code Theme

Everyone has special and perhaps, particular, tastes when it comes to their code editor. There are literally thousands of themes out there, and for good reason: a thing of beauty and enhancement to productivity for one can be a hindrance to another. It’s been an item on my bucket list to create my own theme. I was coding very late the one night, well into the small hours of the morning. Everyone in my house was sleeping and so, as usual, the only light was the glow of my screen. I know it’s not necessarily healthy to code like this, but it’s literally the time I’m most productive: there are minimal distractions, I’m not dealing with work stuff, family stuff, friend stuff, or puppy stuff. I can focus. I had some preferences set for the theme I had been using and, though they all worked well...
Manipulating Pixels Using Canvas
CSS Tricks, Web Tricks

Manipulating Pixels Using Canvas

  Modern browsers support playing video via the <video> element. Most browsers also have access to webcams via the MediaDevices.getUserMedia() API. But even with those two things combined, we can’t really access and manipulate those pixels directly. Fortunately, browsers have a Canvas API that allows us to draw graphics using JavaScript. We can actually draw images to the <canvas> from the video itself, which gives us the ability to manipulate and play with those pixels. Everything you learn here about how to manipulate pixels will give you a foundation to work with images and videos of any kind or any source, not just canvas. Adding an image to canvas Before we start playing with video, let’s look at adding an image to canvas. <img id="SourceImage" src="ima...
Animate Images and Videos with curtains.js
CSS Tricks, Web Tricks

Animate Images and Videos with curtains.js

  While browsing the latest award-winning websites, you may notice a lot of fancy image distortion animations or neat 3D effects. Most of them are created with WebGL, an API allowing GPU-accelerated image processing effects and animations. They also tend to use libraries built on top of WebGL such as three.js or pixi.js. Both are very powerful tools to create respectively 2D and 3D scenes. But, you should keep in mind that those libraries were not originally designed to create slideshows or animate DOM elements. There is a library designed just for that, though, and we’re going to cover how to use it here in this post. WebGL, CSS Positioning, and Responsiveness Say you’re working with a library like three.js or pixi.js and you want to use it to create interactions, like mous...
1 Element CSS Rainbow Gradient Infinity
CSS Tricks

1 Element CSS Rainbow Gradient Infinity

  I first got the idea to CSS something of the kind when I saw this gradient infinity logo by Infographic Paradise: The original gradient infinity. After four hours and some twenty minutes, of which over four hours were spent on tweaking positioning, edges and highlights... I finally had the result below: My version of the rainbow gradient infinity. The gradient doesn't look like in the original illustration, as I chose to generate the rainbow logically instead of using the Dev Tools picker or something like that, but other than that, I think I got pretty close—let's see how I did that!   Markup As you've probably already guessed from the title, the HTML is just one element: <div class='∞'></div> Styling Deciding on the approach The first idea that migh...
Combining the Powers of SEM and BIO for Improving CSS
CSS Tricks

Combining the Powers of SEM and BIO for Improving CSS

  CSS is easy, some might argue, but that "easiness" can cause messy code. This is especially true through power of preprocessors like Sass or Less where, if you aren’t careful, your CSS can become harder to deal with instead of easier. Sass? Harder? This Gist shows a great example of Sass nesting hell. If your Sass code looks like that, you can definitely improve your code with SEM & BIO, a CSS technique I’ll introduce you to now! In this article, I am going to use the code example below to explain how SEM and BIO works and how they can help enhance your CSS strategy. See the Pen by thebabydino (@thebabydino) on CodePen. Generally, SEM is concerned with high level CSS philosophy whereas BIO is an actual technique to help you write better CSS to achieve SEM. The main purp...
CSS Tricks, Web Tricks

Making Avengers ID Card In HTML And CSS

  Let’s suppose Tony Stark would like to redesign the ID cards of the Avengers, and he needs our help to create them in HTML and CSS. So, how can we help? In this tutorial, we’ll be using Flexbox to create the desired layout while diving into nested flexboxes for some advanced layouts. We will also be using rounded as well as transparent borders to create sci-fi arcs in CSS, and then animating them by using CSS animations around the picture of the Avenger. Last but not least, we’ll be using the box-shadow and text-shadow properties to give our ID card a final sci-fi touch. By the end of the tutorial, we will build a sci-fi animated Avengers ID card, and also learn the basics of Flexbox, nested Flexbox, CSS animations, borders, shadows, and many other frequently used CSS properties...
CSS Tricks

HSL() / HSLa() is great for programmatic color control

  If you ever need to hand-manipulate a color in native CSS, HSL is pretty much the only way. HSL (the hsl() and hsla() functions in CSS) stands for hue, saturation, lightness, and optionally, alpha. We've talked about it before but we can break it down a little more and do some interesting things with it. Hue: Think of a color wheel. Around 0o and 360o are reds. 120o is where greens are and 240o are blues. Use anything in between 0-360. Values above and below will be modulus 360. Saturation: 0% is completely desaturated (grayscale). 100% is fully saturated (full color). Lightness: 0% is completely dark (black). 100% is completely light (white). 50% is average lightness. alpha: Opacity/Transparency value. 0 is fully transparent. 1 is fully opaque. 0.5 is 50% transpare...