Animate in Ajax’d Content to its Natural Height

Let’s combine three things we just learned here on CSS-Tricks: One, transitioning to auto dimensions. Two, Ajaxing for stuff in a modern way. Three, waiting for images to be loaded to measure them. With all these three things in our toolbox, we can Ajax for some arbitrary content and insert it onto the page with a revealing height animation. Tricky tricky! Here’s the final demo: See the Pen Slide in Ajax Content by Chris Coyier (@chriscoyier) on CodePen. The thinking here is that since we’re guaranteed to be using JavaScript anyway, since we’re Ajaxing for some content, we might as well keep using JavaScript to help us make a smooth… Read More

Continue Reading

Need to do Dependency-Free Ajax?

One of the big reasons to use jQuery, for a long time, was how easy it made Ajax. It has a super clean, flexible, and cross-browser compatible API for all the Ajax methods. jQuery is still mega popular, but it’s becoming more and more common to ditch it, especially as older browser share drops and new browsers have a lot of powerful stuff we used to learn on jQuery for. Even just querySelectorAll is often cited as a reason to lose the jQuery dependency. How’s Ajax doing? Let’s say we needed to do a GET request to get some HTML from a URL endpoint. We aren’t going to do any… Read More

Continue Reading

Measuring Image Widths in JavaScript (Carefully!)

Let’s say you want to find an on the page and find out how wide it is in JavaScript. Maybe you need to make some choices based on that width (or height, or both) You can definitely do that. The DOM will even give you a variety of dimensions to choose from depending on what you need. There is definitely a catch though. Here’s the image: And here’s us selecting it, by finding the first JavaScript can find in the DOM: var img = document.querySelector(« img »); Let’s just log the width: // How wide the image is rendered at (which could be affected by styles) console.log(img.width); // How wide the image… Read More

Continue Reading
minesweeper-webvr-demo

Minecraft in WebVR with HTML Using A-Frame

I’m Kevin Ngo, a virtual reality web developer on the Mozilla VR team and a core developer of A-Frame. Today, we’ll go over how to build a room scale WebVR Minecraft demo that works on HTC Vive, Oculus Rift, Samsung GearVR, Google Cardboard, desktop, and mobile. The demo will be built with A-Frame in just 11 HTML elements! A-Frame A few years ago, Mozilla invented and pioneered WebVR, a JavaScript API for creating immersive VR experiences in your browser, in an experimental build of Firefox. Since then, WebVR has gained wide support from other companies such as Google, Microsoft, Samsung, and Oculus. And it’s now set to release enabled by… Read More

Continue Reading

Scrolling on the Web: A Primer

Scrolling is complicated. Nolan Lawson: User scrolls with two fingers on a touch pad User scrolls with one finger on a touch screen User scrolls with a mouse wheel on a physical mouse User clicks the sidebar and drags it up and down User presses up, down, PageUp, PageDown, or spacebar keys on a keyboard As it turns out, all five of these input methods have vastly different characteristics, especially when it comes to performance and cross-browser behavior. Some of them (such as touch screen scrolling) are likely to be smooth even on a page with heavy JavaScript usage, whereas others (such as keyboard scrolling) will make the same page… Read More

Continue Reading

Hassle-free Full Bleed with *:not()

Common situation documented by Dave Rupert: Let’s say you’re making a blog post layout. Content is entered into a CMS inside a WYSIWYG editor field. You echo that content to the page. You pull it up on a mobile device and notice the paragraphs go edge-to-edge. Yikes, it’s a little uncomfortable. So you add some kind of left/right padding maybe using a div.container. This works great until the client asks for the images and video to go full bleed. Your universal padding solution no longer works well. You got options. Containerizing isn’t great in any scenario. So how do you yank out those full bleed elements? Dave does it with… Read More

Continue Reading
no-cloud

“Serverless”

Every time I use the word « serverless », which is somewhat regularly lately, as we’ve had a few articles using the term lately and use the concept at CodePen for a variety of things, I get some version of: CMON BRAH YOU’RE STILL USING « SERVERS ». And they aren’t wrong. Yes, when you build things on the web, there are always servers involved. Always. Whether it’s some old computer in a church basement, a computer in a rack at some big hosting company, or « The Cloud », it’s a server. Chris Wattersons’s classic sticker.I rolled my eyes at the term the first few times I heard it too. But now I’m hesitant to… Read More

Continue Reading
auto-problem

Using CSS Transitions on Auto Dimensions

We’ve all been there. You’ve got an element you want to be able to collapse and expand smoothly using CSS transitions, but its expanded size needs to be content-dependent. You’ve set transition: height 0.2s ease-out. You’ve created a collapsed CSS class that applies height: 0. You try it out, and… the height doesn’t transition. It snaps between the two sizes as if transition had never been set. After some fiddling, you figure out that this problem only happens when the height starts out or ends up as auto. Percentages, pixel values, any absolute units work as expected. But all of those require hard coding a specific height beforehand, rather than… Read More

Continue Reading

Linting HTML using CSS

Ire Aderinokun with some CSS selectors designed to catch problematic HTML elements, such as those with inline styles or missing/wrong attributes. I tossed up a repo so I could make a full page demo showing off all those selectors at work. Any red you see is a problem of sorts. Direct Link to Article — PermalinkLinting HTML using CSS is a post from CSS-Tricks

Continue Reading
Screenshot-2017-03-12-00.31.26

Getting Started with CSS Grid

This was a blockbuster week for front-end developers as CSS Grid landed in the latest versions of Firefox and Chrome without a feature flag. That’s right: we can now go and play with Grid in two of the most popular browsers right away. But why is CSS Grid a big deal and why should we care? Well, CSS Grid is the first real layout system for the web. It’s designed for organizing content both into columns and rows and it finally gives developers almost God-like control of the screens before us. That means that we can finally ditch decades of hacks and workarounds for setting elements on a web page… Read More

Continue Reading
large

Simple Little Use Case for `vmin`

Viewport units are things like 10vw (10% of the viewport width) or 2vh (2% of the viewport height). Useful sometimes, as they are always relative to the viewport. No cascading or influence by parent elements. There is also vmin, which is the lesser of vw and vh, and vmax, which is the greater. These values can be used for anything that takes a length value, just like px or em or % or whatever. Let’s take a look at a tiny design pattern that makes use of vmin. A header block! If we set the padding of an like so: header { padding: 10vmin 1rem; } We get some fixed… Read More

Continue Reading
h

The Document Outline Dilemma

For the past few weeks there has been lots of talk about HTML headings in web standards circles. Perhaps you’ve seen some of the blog posts, tweets, and GitHub issue threads. Headings have been part of HTML since the very first websites at CERN, so it might be surprising to find them controversial 25 years later. I’m going to quickly summarize why they are still worth discussing, with plenty of links to other sources, before adding my own opinions to the mix. If you’re up-to-date on the debate, you can jump straight to the « Bigger Dilemma » section. The Story So Far… HTML uses headings (, , , and so on… Read More

Continue Reading
tinymce

Build a Custom Serverless CMS: Part 2

In our previous proof-of-concept demo, we built a bare bones admin for generating a web page with the ability to edit some text on the page and set the site title and description. For this next demo, we build on our example and add rich text editing and image upload capabilities. Article Series: Build a Custom CMS for a Serverless Static Site Generator + Repo Build a Custom Serverless CMS: Part 2 (you are here!) + Repo Rich Text Editing TinyMCE is the most widely used web-based Rich Text Editor around, so let’s use it. We can add it to our admin form pretty easily. There are many configuration options… Read More

Continue Reading
workflow

Introduction to Web Audio API

Web Audio API let’s us make sound right in the browser. It makes your sites, apps, and games more fun and engaging. You can even build music-specific applications like drum machines and synthesizers. In this article, we’ll learn about working with the Web Audio API by building some fun and simple projects. Getting Started Let’s do some terminology. All audio operations in Web Audio API are handled inside an audio context. Each basic audio operation is performed with audio nodes that are chained together, forming an audio routing graph. Before playing any sound, you’ll need to create this audio context. It is very similar to how we would create a… Read More

Continue Reading
stroke-gif

Text Stroke: Stuck In The Middle With You

There is a non-standard way to stroke HTML text (SVG has a standard way). It’s not particularly new. There are -webkit- and -moz- prefixes for it. Jen Simmons recently posted about it, with an example: span { -moz-text-fill-color: #fde; -webkit-text-fill-color: #fde; -moz-text-stroke-color: #666; -webkit-text-stroke-color: #666; -moz-text-stroke-width: 2px; -webkit-text-stroke-width: 2px; } And she’s right: This CSS isn’t fully-baked or fully-supported. But it’s good enough to be used today, especially since it’s simply offering a visual enhancement. It’s not mission critical to making a website usable. I’d only perhaps add that if you were going to do something like add a stroke around white text, you could wrap it in a @supports… Read More

Continue Reading

Randomizing SVG Shapes

SVG shapes are all built from numbers. Obvious, perhaps, but also, I’m not sure we take as much advantage of that as we could with inline . For example, it’s pretty easy to generate a new pseudo-random number in JavaScript: function getRandomInt(min, max) { return Math.floor(Math.random() * (max – min + 1) + min); } Now imagine a bunch of variables set to random numbers, and using ES6 template literals to stitch them together: let newPoints = `${x1},${y1} {x2},${y2} {x3},${y3} {x3},${y3}`; Which makes a valid syntax for the points attribute of a . let polygon = document.querySelector(« polygon »); polygon.setAttribute(« points », newPoints); A more detailed example of that, and a demo, over on… Read More

Continue Reading
cathy_oneil-620x412

Weapons of Math Destruction

I think you’d do well to read Cathy O’Neils Weapons of Math Destruction: How Big Data Increases Inequality and Threatens Democracy. I saw her read at the Miami Book Fair several months ago, and immediately bought a copy. I even got her to sign it which is kinda cool ;) Cathy’s big idea is that we’re absolutely surrounded by algorithms that inform big decision making. There are lots of good algorithms that help us. Sadly, there are lots of insidiously, dangerous, bad algorithms that do serious damage, and they are lurking all about disguised as good algorithms. One aspect of a good algorithm is some kind of feedback and correctional… Read More

Continue Reading
HeroPatterns

Websites to Generate SVG Patterns

These aren’t particularly hard to web search for, but just in case you didn’t know they existed I figured I’d drop them here. I’ve used all three of these in the past and I think they do a good job of driving home how cool of patterns you can make in SVG with such little code. Hero Patterns A collection of repeatable SVG background patterns for you to use on your web projects. SVG Patterns Gallery SVG images are typically smaller than bitmap images and remain sharp on high-dpi screens. Unlike CSS3 gradients, SVG images are supported on IE9. SVGeneration Scalable Vector Graphics are crisp and clear and can be… Read More

Continue Reading
illustrator

Tools to Visualize and Edit SVG Paths (Kinda!)

It was brought up at the SVG Summit the other day, wouldn’t it be nice when working with SVG to be able to work with it both ways at once? See and edit the code, and see the results visually See and edit the visual shapes, and see the code change There might not be the perfect one true tool, but there are certainly some ideas getting there! Anthony Dugois’s SVG Path Builder I’d embed the Pen here, but you really need a bit more space to play with it. Here’s a video of how it works: It shows you the code output, but you can’t adjust the code to… Read More

Continue Reading
Sales-process-overview

PHP For Beginners: Building a Simple CRM from Scratch

Customer Relationship Management (CRM) is a system that manages customer interactions and data throughout the customer lifecycle between the customer and the company across different channels. In this tutorial, we are going to build a custom CRM in PHP, which a sales team can use to track customers through the entire sales cycle. We’ll be creating a simple CRM system for salespeople to: Access their tasks View their leads Create new tasks for each lead Create new opportunity Lose a sale Sales managers will be able to: Manage all customers Manage sales team View current sales activities Download Demo Files Building Blocks of a CRM Here is a list of… Read More

Continue Reading