Skip to content

Instantly share code, notes, and snippets.

View tomhodgins's full-sized avatar
😍
Writing CSS

Tommy Hodgins tomhodgins

😍
Writing CSS
View GitHub Profile
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Count Down Element</title>
<script type=module>
import html from 'https://v2.crocdn.com/_plugins/html.js'
class CountDown extends HTMLElement {
constructor() {
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Aspect Ratio Custom Property</title>
<script type=module>
// Run on load, resize, and 'reprocess' events
[
'load',
'resize',
let start = performance.now()
for (
let count = 250 * 1000;
count --> 0;
) {
console.error('oops')
}
let end = performance.now()
import {Document, DOMParser} from './deno-dom-wasm.ts'
import {assert} from 'https://deno.land/std@0.67.0/testing/asserts.ts'
const parseIntoHTMLDocument = (string = '') => new DOMParser().parseFromString(
String(string),
'text/html'
)
const html = `
<h1>Dummy HTML Content</h1>
// Deno Support
if ('Deno' in globalThis) {
globalThis.DOMParser = (await import('https://deno.land/x/deno_dom/deno-dom-wasm.ts')).DOMParser
}
// Node Support
if ('process' in globalThis) {
const jsdom = (await import('jsdom')).default.JSDOM
globalThis.DOMParser = class {
@tomhodgins
tomhodgins / to-string-to-json.js
Created August 28, 2020 15:11
You can define how an object stringifies with String() and toString(), and how it represents itself when converted to JSON
({
value: 'hello world',
toString() { return `stringified that's: ${this.value}` }
}).toString()
// "stringified that's: hello world"
JSON.stringify({
value: 'hello world',
toJSON() { return [{JSONified_thats: this.value}] }
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Deep Combinator</title>
<style>
[--deep] h1,
[--deep] span {
color: red;
}

here's an example of some text content, and a variety of markups for it:

This is a headline
This is a paragraph

troff

There are scalable units, like vw and vh etc that are 1% of the browser's viewport, vw is like innerWidth / 100. So something like:

h1 {
  font-size: 10vw;
}

This means 10vw is going to be 50px when the browser is 500px wide, and 100px when the browser is 1000px wide for example. Using scalable units by themselves can sometimes lead to things being too-big or too-small, so some people use them with @media queries to 'switch them off' to some other unit at a certain size.

@tomhodgins
tomhodgins / example.css
Created August 6, 2020 23:43
The sort of CSS we write at work
.home-popup:--has(test-24) {
padding: 1em 2em .75em;
}
.home-popup test-24 ~ * {
display: none;
}
@--reset test-24;