Monday, October 27

Tag: css

CSS Tricks

A Tale of Two Buttons

I enjoy front-end developer thought progression articles like this one by James Nash. Say you have a button which needs to work in "normal" conditions (light backgrounds) and one with reverse-colors for going on dark backgrounds. Do you have a modifier class on the button itself? How about on the container? How can inheritance and the cascade help? How about custom properties? I think embracing CSS’s cascade can be a great way to encourage consistency and simplicity in UIs. Rather than every new component being a free for all, it trains both designers and developers to think in terms of aligning with and re-using what they already have. Direct Link to Article — PermalinkThe post A Tale of Two Buttons appeared first on CSS-Tricks. Source: CSS-tricks.com
CSS Tricks

A native lazy load for the web platform

A new Chrome feature dubbed "Blink LazyLoad" is designed to dramatically improve performance by deferring the load of below-the-fold images and third-party <iframe>s. The goals of this bold experiment are to improve the overall render speed of content that appears within a user’s viewport (also known as above-the-fold), as well as, reduce network data and memory usage. ✨ ?‍? How will it work? It’s thought that temporarily delaying less important content will drastically improve overall perceived performance. If this proposal is successful, automatic optimizations will be run during the load phase of a page: Images and iFrames will be analysed to gauge importance. If they’re seen to be non-essential, they will be deferred, or not loaded at all: Deferred items will only be loaded if t...
CSS Tricks

Using CSS Clip Path to Create Interactive Effects, Part II

One of the biggest drawbacks of CSS clipping, at the time of writing, is browser support. Not having 100% browser coverage means different experiences for viewers in different browsers. We, as developers, can’t control what browsers support — browser vendors are the ones who implement the spec and different vendors will have different agendas. One thing we can do to overcome inconsistencies is use alternative technologies. The feature set of CSS and SVG sometimes overlap. What works in one may work in the other and vice versa. As it happens, the concept of clipping exists in both CSS and SVG. The SVG clipping syntax is quite different, but it works the same. The good thing about SVG clipping compared to CSS is its maturity level. Support is good all the way back to old IE browsers. Most...
CSS Tricks

::before vs :before

Note the double-colon ::before versus the single-colon :before. Which one is correct? Technically, the correct answer is ::before. But that doesn't mean you should automatically use it. The situation is that: double-colon selectors are pseudo-elements. single-colon selectors are pseudo-selectors. ::before is definitely a pseudo-element, so it should use the double colon. The distinction between a pseudo-element and pseudo-selector is already confusing. Fortunately, ::after and ::before are fairly straightforward. They literally add something new to the page, an element. But something like ::first-letter is also a pseudo-element. The way I reason that out in my brain is that it's selecting a part of something in which there is no existing HTML element for. There is no <span> around ...
A Basic WooCommerce Setup to Sell T-Shirts
CSS Tricks

A Basic WooCommerce Setup to Sell T-Shirts

WooCommerce is a powerful eCommerce solution for WordPress sites. If you're like me, and like working with WordPress and have WordPress-powered sites already, WooCommerce is a no-brainer for helping you sell things online on those sites. But even if you don't already have a WordPress site, WooCommerce is so good I think it would make sense to spin up a WordPress site so you could use it for your eCommerce solution. Personally, I've used WooCommerce a number of times to sell things. Most recently, I've used it to sell T-Shirts (and hats) over on CodePen. We use WordPress already to power our blog, documentation, and podcast. Makes perfect sense to use WordPress for the store as well! What I think is notable about our WooCommerce installation at CodePen is how painless it was, while doing...
Using feature detection to write CSS with cross-browser support
CSS Tricks

Using feature detection to write CSS with cross-browser support

In early 2017, I presented a couple of workshops on the topic of CSS feature detection, titled CSS Feature Detection in 2017. A friend of mine, Justin Slack from New Media Labs, recently sent me a link to the phenomenal Feature Query Manager extension (available for both Chrome and Firefox), by Nigerian developer Ire Aderinokun. This seemed to be a perfect addition to my workshop material on the subject. However, upon returning to the material, I realized how much my work on the subject has aged in the last 18 months. The CSS landscape has undergone some tectonic shifts: The Atomic CSS approach, although widely hated at first, has gained some traction through libraries like Tailwind, and perhaps influenced the addition of several new utility classes to Bootstrap 4. CSS-in-JS exploded in p...
CSS Tricks

CSS Logical Properties

A property like margin-left seems fairly logical, but as Manuel Rego Casasnovas says: Imagine that you have some right-to-left (RTL) content on your website your left might be probably the physical right, so if you are usually setting margin-left: 100px for some elements, you might want to replace that with margin-right: 100px. Direction, writing mode, and even flexbox all have the power to flip things around and make properties less logical and more difficult to maintain than you'd hope. Now we'll have margin-inline-start for that. The full list is: margin-{block,inline}-{start,end} padding-{block,inline}-{start,end} border-{block,inline}-{start,end}-{width,style,color} Manuel gets into all the browser support details. Rachel Andrew also explains the logic: ... these values have moved aw...
ABeamer: a frame-by-frame animation framework
CSS Tricks

ABeamer: a frame-by-frame animation framework

In a recent post, Zach Saucier demonstrated the awesome things that the DOM allows us to do, thanks to the <canvas> element. Taking a snapshot of an element and manipulating it to create an exploding animation is pretty slick and a perfect example of how far complex animations have come in the last few years. ABeamer is a new animation ecosystem that takes advantage of these new concepts. At the core of the ecosystem is the web browser animation library. But, it's not just another animation engine. ABeamer is designed to build frame-by-frame animations in the web browser and use a render server to generate a PNG file sequence, which can ultimately be used to create an animated GIF or imported into a video editor. First, a little about what ABeamer can do A key feature is its ability...
CSS Tricks

“Old Guard”

Someone asked Chris Ferdinandi what his biggest challenge is as a web developer: ... the thing I struggle the most with right now is determining when something new is going to change the way our industry works for the better, and when it’s just a fad that will fade away in a year or three. I try to avoid jumping from fad to fad, but I also don’t want to be that old guy who misses out on something that’s an important leap forward for us. He goes on explain a situation where, as a young buck developer, he was very progressive and even turned down a job where they weren't hip to responsive design. But now worries that might happen to him: I’ll never forget that moment, though. Because it was obvious to me that there was an old guard of developers who didn’t get it and couldn’t see the big ...
What I learned by building my own VS Code extension
CSS Tricks

What I learned by building my own VS Code extension

VS Code is slowly closing the gap between a text editor and an integrated development environment (IDE). At the core of this extremely versatile and flexible tool lies a wonderful API that provides an extensible plugin model that is relatively easy for JavaScript developers to build on. With my first extension, VS Code All Autocomplete, reaching 25K downloads, I wanted to share what I learned from the development and maintenance of it with all of you. Trivia! Visual Studio Code does not share any lineage with the Visual Studio IDE. Microsoft used the VS brand for their enterprise audience which has led to a lot of confusion. The application is just Code in the command line and does not work at all like Visual Studio. It takes more inspiration from TextMate and Sublime Text than Visual Stu...
CSS Tricks

Firefox Multi-Account Containers

It's an extension: Each Container stores cookies separately, so you can log into the same site with different accounts and online trackers can’t easily connect the browsing. A great idea for a feature if you ask me. For example, I have two Buffer accounts and my solution is to use different browsers entirely to stay logged into both of them. I know plenty of folks that prefer the browser version of apps like Notion, Front, and Twitter, and it's cool to have a way to log into the same site with multiple accounts if you need to — and without weird trickery. This is browsers competing on UI/UX features rather than web platform features, which is a good thing. Relevant: Opera Neon and Refresh. Direct Link to Article — PermalinkThe post Firefox Multi-Account Containers appeared first on CSS-T...
CSS Tricks

Seriously, though. What is a progressive web app?

Amberley Romo read a ton about PWAs in order to form her own solid understanding. “Progressive web app” (PWA) is both a general term for a new philosophy toward building websites and a specific term with an established set of three explicit, testable, baseline requirements. As a general term, the PWA approach is characterized by striving to satisfy the following set of attributes: Responsive Connectivity independent App-like-interactions Fresh Safe Discoverable Re-engageable Installable Linkable Direct Link to Article — PermalinkThe post Seriously, though. What is a progressive web app? appeared first on CSS-Tricks. Source: CSS-tricks.com
CSS Tricks

Level up your .filter game

.filter is a built-in array iteration method that accepts a predicate which is called against each of its values, and returns a subset of all values that return a truthy value. That is a lot to unpack in one statement! Let's take a look at that statement piece-by-piece. "Built-in" simply means that it is part of the language—you don't need to add any libraries to get access to this functionality. "Iteration methods" accept a function that are run against each item of the array. Both .map and .reduce are other examples of iteration methods. A "predicate" is a function that returns a boolean. A "truthy value" is any value that evaluates to true when coerced to a boolean. Almost all values are truthy, with the exceptions of: undefined, null, false, 0, NaN, or "" (empty string). To see .filte...
Working with refs in React
CSS Tricks

Working with refs in React

Refs make it possible to access DOM nodes directly within React. This comes in handy in situations where, just as one example, you want to change the child of a component. Let’s say you want to change the value of an <input> element, but without using props or re-rendering the whole component. That’s the sort of thing refs are good for and what we’ll be digging into in this post. How to create a ref createRef() is a new API that shipped with React 16.3. You can create a ref by calling React.createRef() and attaching a React element to it using the ref attribute on the element. class Example extends React.Component { constructor(props) { super(props) // Create the ref this.exampleRef = React.createRef() } render() { return ( <div> // Call t...
Building Battleship in CSS
CSS Tricks

Building Battleship in CSS

This is an experiment to see how far into an interactive experience I can get using only CSS. What better project to attempt than a game? Battleship seemed like a good challenge and a step up from the CSS games I’ve seen so far because it has the complexity of multiple areas that have to interact with two players. Wanna see the complete game? View Repo View Demo Oh, you wanna learn how it works? Let’s dig in. I could tell right away there was going to be a lot of repetitive HTML and very long CSS selectors coming, so I set up Pug to compile HTML and Less to compile CSS. This is what all the code from here on is going to be written in. Interactive elements in CSS In order to get the game mechanics working, we need some interactive elements. We’re going to walk through each one. HTML che...