Skip to content

Instantly share code, notes, and snippets.

View goodreds's full-sized avatar
🎯
Focusing

Allen Goodreds goodreds

🎯
Focusing
View GitHub Profile
@goodreds
goodreds / index.html
Last active August 3, 2023 23:29
Warn user before leaving current page
<script>window.onbeforeunload = function () {
return "Two buttons will be below this message asking if the user wants to stay on this page or leave.";
}
</script>
@goodreds
goodreds / index.html
Created April 26, 2023 05:45
TW: Overlapping elements
<div class="flex flex-col justify-center items-center max-w-sm mx-auto my-8">
<div style="background-image: url(https://images.unsplash.com/photo-1539185441755-769473a23570?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1951&q=80"
class="bg-gray-300 h-64 w-full rounded-lg shadow-md bg-cover bg-center"></div>
<div class="w-56 md:w-64 bg-white -mt-10 shadow-lg rounded-lg overflow-hidden">
<div class="py-2 text-center font-bold uppercase tracking-wide text-gray-800">Nike Revolt</div>
<div class="flex items-center justify-between py-2 px-3 bg-gray-400">
<h1 class="text-gray-800 font-bold ">$129</h1>
<button class=" bg-gray-800 text-xs text-white px-2 py-1 font-semibold rounded uppercase hover:bg-gray-700">Add to cart</button>
</div>
</div>
@goodreds
goodreds / index.html
Created April 26, 2023 05:37
Rocker Switches
<main>
<div class="col">
<label>
<span class="switch">
<input class="switch__input" type="checkbox" role="switch">
<span class="switch__surface">
<span class="switch__surface-glare"></span>
</span>
<span class="switch__inner-shadow"></span>
<span class="switch__inner">
@goodreds
goodreds / Image Source Set.html
Created December 8, 2022 01:54
This is the default image source set to use whenever there is call for an image
<picture>
<source media=("max-width: 600px") srcset="/images/service-mobile.webp">
<source media=("min-width: 601px") srcset="/images/service.webp">
<img aria-hidden="true" loading="lazy" decoding="async" src="/images/service.webp" alt="appliance" width="275" height="132">
</picture>

I’ve simplified their markup slightly, but the structure’s the same. A picture element contains any number of source elements, and exactly one img. On each source, there’s a media query inside the media attribute. The browser loops through each of the source elements until it finds one whose media query matches the conditions in the browser. Upon finding a match, it will send that source’s srcset to the img element and load it.

That relationship between the source and the img is actually quite important: the matching source is never rendered by the browser. In fact, neither is the picture element: the srcset of the relevant source element is sent to the innermost img, and that’s what gets displayed. So on widescreen displays, the source with (min-width: 990px) will send the largest version of the photo to the img; on midsize breakpoints, [email protected] will get rendered, thanks to the (min-width: 750px) query. And finally, if none of the media queries match, the browser will just load the img.

I

@goodreds
goodreds / hero-image-photo-improvement.markdown
Created June 18, 2021 22:14
Hero image (photo improvement)
@goodreds
goodreds / index.html
Created June 18, 2021 22:14
Preview card
<body class="antialiased bg-gray-200 font-sans">
<div class="flex items-center justify-center min-h-screen">
<div class="max-w-md md:max-w-2xl px-2">
<div class="bg-white shadow-xl rounded-lg overflow-hidden md:flex">
<div class="bg-cover bg-bottom h-56 md:h-auto md:w-56" style="background-image: url(https://images.unsplash.com/photo-1517736996303-4eec4a66bb17?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1268&q=80)">
</div>
<div>
<div class="p-4 md:p-5">
<p class="font-bold text-xl md:text-2xl">Amsterdam Walking Tour</p>
<p class="text-gray-700 md:text-lg">Explore popular tourist destinations as well as hidden local favourites.</p>