### Getting Started with CSS Grid Layout
Source: https://css-tricks.com/snippets/css/complete-guide-grid
An introductory guide to CSS Grid, explaining the fundamental concepts and properties required to start building grid-based layouts. It covers the basics of defining grid containers and items.
```CSS
/* Basic CSS Grid container */
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr; /* Three equal columns */
grid-gap: 10px;
}
/* Grid item styling */
.grid-item {
background-color: lightblue;
padding: 20px;
text-align: center;
}
```
--------------------------------
### Flexbox Layout Example
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This snippet demonstrates a basic Flexbox layout, likely used as a starting point for users experimenting with the technology. It's a common example found in Flexbox tutorials.
```CSS
/* Example CSS for Flexbox layout */
.container {
display: flex;
flex-direction: row; /* or column */
justify-content: center; /* or flex-start, flex-end, space-between, space-around */
align-items: center; /* or flex-start, flex-end, stretch, baseline */
}
.item {
flex: 1; /* Example of flex grow, shrink, basis */
margin: 5px;
padding: 10px;
background-color: lightblue;
}
```
--------------------------------
### Log Composition Start Event Data
Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
An example of how to use the `compositionstart` event listener to log the `data` property, which contains the characters generated by the input method. This helps in understanding the input process during composition.
```javascript
const inputElement = document.querySelector('input[type="text"]');
inputElement.addEventListener("compositionstart", (event) => {
console.log(`generated characters were: ${event.data}`);
});
```
--------------------------------
### Basic Flexbox Example - HTML/CSS
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
A fundamental example of using flexbox, provided as a reference for learning. This snippet, linked from CodePen, demonstrates basic flexbox properties and their application in creating layouts.
```HTML
Item 1
Item 2
Item 3
```
```CSS
.flex-container {
display: flex;
}
.flex-item {
/* Flex item styling */
}
```
--------------------------------
### HTML Input Labeling Examples
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input
Demonstrates three ways to associate labels with input fields in HTML. The first example shows an inaccessible setup, while the second and third illustrate implicit and explicit label associations, respectively. Explicit labeling using the 'for' attribute is recommended for better accessibility.
```html
Enter your name:
```
```html
```
```html
```
--------------------------------
### CSS Grid Starter Layouts
Source: https://css-tricks.com/snippets/css/complete-guide-grid
Provides fundamental CSS Grid layouts that serve as starting points for various web designs. These snippets cover common grid structures and configurations.
```CSS
.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-template-rows: auto 1fr auto;
gap: 15px;
}
```
--------------------------------
### HTML Structure for fit-content Example
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/fit-content
Provides the HTML structure for a CSS example demonstrating the `fit-content` keyword, showing a container with multiple items of varying text content.
```HTML
Item
Item with more text in it.
Item with more text in it, hopefully we have added enough text so the text
will start to wrap.
```
--------------------------------
### CSS Flexbox: Shorthand Property Examples
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Demonstrates common shorthand values for the CSS flex property. These examples show how to quickly set flex-grow, flex-shrink, and flex-basis for different layout needs, such as fixed sizing or content-based sizing.
```CSS
flex: 0 0 auto;
flex: 0 0 25%;
flex: 0 0 10em;
```
--------------------------------
### Listen for CSS Transition Start Events
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
This code snippet shows how to detect the beginning of a CSS transition using both the `transitionrun` and `transitionstart` events. The `signalStart` function is called when the transition begins, either before or after any delay.
```javascript
el.addEventListener("transitionrun", signalStart, true);
el.addEventListener("transitionstart", signalStart, true);
```
--------------------------------
### CSS Flexbox Responsive Grid Example (Eixample)
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This snippet refers to an open-source flexbox grid system called Eixample, which uses a traditional 12-column approach. It's designed to simplify the application of flexbox attributes for creating responsive layouts.
```CSS
/* Example CSS from Eixample grid (conceptual) */
.eixample-grid {
display: flex;
flex-wrap: wrap;
}
.eixample-col {
box-sizing: border-box;
}
.eixample-col-6 {
flex: 0 0 50%;
max-width: 50%;
}
.eixample-col-4 {
flex: 0 0 33.333%;
max-width: 33.333%;
}
```
--------------------------------
### Handle Animation Events
Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
Events related to CSS animations, including start, end, iteration, and cancellation. These allow for reacting to animation states.
```JavaScript
element.addEventListener('animationstart', handler);
element.addEventListener('animationend', handler);
element.addEventListener('animationiteration', handler);
element.addEventListener('animationcancel', handler);
```
--------------------------------
### CSS Grid Strategies for Design Mockups
Source: https://css-tricks.com/snippets/css/complete-guide-grid
This article explores various CSS Grid strategies to effectively match design mockups. It provides practical techniques and examples for implementing grid-based layouts that align with visual designs.
```CSS
/* Example CSS for Grid Layout */
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
```
--------------------------------
### HTML structure for cut event example
Source: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut
This HTML snippet sets up two editable divs, a 'source' and a 'target', which are used in the example to demonstrate cutting text from one element and potentially pasting it into another. Basic styling is also included.
```html
Cut text from this box.
And paste it into this one.
```
--------------------------------
### CSS Flexbox Layout Examples
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This snippet showcases various CSS Flexbox properties for creating flexible and responsive layouts. It demonstrates how to align items, distribute space, and order elements within a flex container.
```CSS
.wrap {
width: 910px;
margin: 0 auto;
}
#about {
width: 900px;
}
#container {
overflow: hidden;
}
```
--------------------------------
### CSS At-Rules Reference
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
Lists and describes various CSS at-rules, which are special rules that start with an '@' sign and provide directives to the CSS engine. This includes rules for character sets, media queries, font definitions, and more.
```CSS
/* CSS At-Rules */
@charset "UTF-8";
@color-profile;
@container;
@counter-style;
@document;
@font-face;
@font-feature-values;
@font-palette-values;
@import;
@keyframes;
@layer;
@media;
@namespace;
@page;
@position-try;
@property;
@scope;
@starting-style;
@supports;
@view-transition;
```
--------------------------------
### CSS Modules Reference
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
Provides a comprehensive reference for various CSS modules, covering a wide range of properties and functionalities from anchor positioning and animations to colors, fonts, layout, and more.
```CSS
/* Example for CSS Anchor Positioning */
.element {
anchor-name: --my-anchor;
position: anchor;
top: anchor(--my-anchor bottom);
left: anchor(--my-anchor left);
}
```
```CSS
/* Example for CSS Animations */
@keyframes slidein {
from { transform: translateX(0%); }
to { transform: translateX(100%); }
}
.animated-element {
animation-name: slidein;
animation-duration: 2s;
}
```
```CSS
/* Example for CSS Colors */
.text-color {
color: rgb(255, 0, 0);
}
.background-color {
background-color: #00ff00;
}
```
```CSS
/* Example for CSS Box Model */
.box {
width: 100px;
height: 100px;
padding: 10px;
border: 5px solid black;
margin: 15px;
}
```
```CSS
/* Example for CSS Custom Properties */
:root {
--main-bg-color: coral;
}
.my-element {
background-color: var(--main-bg-color);
}
```
```CSS
/* Example for CSS Nesting */
nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li {
display: inline-block;
margin: 0 5px;
}
}
```
--------------------------------
### CSS Grid align-content Property Examples
Source: https://css-tricks.com/snippets/css/complete-guide-grid
Demonstrates the usage of the `align-content` property in CSS Grid for aligning grid items along the block axis. It covers various values including start, end, center, stretch, space-around, space-between, and space-evenly.
```CSS
.container {
align-content: start;
}
```
```CSS
.container {
align-content: end;
}
```
```CSS
.container {
align-content: center;
}
```
```CSS
.container {
align-content: stretch;
}
```
```CSS
.container {
align-content: space-around;
}
```
```CSS
.container {
align-content: space-between;
}
```
```CSS
.container {
align-content: space-evenly;
}
```
--------------------------------
### CSS Flexbox Item Sizing
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Demonstrates how to size flex items using `flex-basis` and the `flex` shorthand property. The `flex: 1` example allows an item to grow and shrink, taking up available space.
```CSS
.flex-item-auto {
-webkit-box-basis: auto;
-webkit-flex-basis: auto;
-ms-flex-basis: auto;
flex-basis: auto;
-webkit-box-flex: 1;
/* OLD - iOS 6-, Safari 3.1-6 */
-moz-box-flex: 1;
/* OLD - Firefox 19- */
-webkit-flex: 1;
/* Chrome */
-ms-flex: 1 0 auto;
/* IE 10 */
flex: 1;
}
```
--------------------------------
### CSS Grid align-items: start
Source: https://css-tricks.com/snippets/css/complete-guide-grid
Sets the align-items property for a CSS Grid container to 'start', aligning items to the start edge of their cell along the block axis.
```CSS
.container {
align-items: start;
}
```
--------------------------------
### CSS for cut event example elements
Source: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut
This CSS provides basic styling for the 'source' and 'target' divs used in the 'cut' event example. It includes borders, margins, padding, and background colors to visually distinguish the elements.
```css
div.source,
div.target {
border: 1px solid gray;
margin: 0.5rem;
padding: 0.5rem;
height: 1rem;
background-color: #e9eef1;
}
```
--------------------------------
### Flexbox Align Content: Flex Start
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Aligns flex items to the start of the cross-axis. Includes vendor prefixes for compatibility.
```CSS
.flex-align-start {
-webkit-box-align-content: flex-start;
-webkit-align-content: flex-start;
-ms-flex-align-content: flex-start;
align-content: flex-start;
}
```
--------------------------------
### Flexbox Align Items: Flex Start
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Aligns flex items to the start of the cross-axis within their line. Includes vendor prefixes.
```CSS
.flex-align-item-start {
-webkit-box-align: flex-start;
-webkit-align-items: flex-start;
-moz-box-align: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
}
```
--------------------------------
### CSS Styling Basics
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
Covers fundamental CSS concepts for styling web pages, including backgrounds, borders, overflow properties, images, media, forms, and tables. Also includes debugging techniques and challenges for practical application.
```CSS
/* Example for Backgrounds and Borders */
body {
background-color: lightblue;
border: 1px solid black;
}
```
```CSS
/* Example for Overflow */
.container {
overflow: hidden;
width: 200px;
height: 100px;
}
```
```CSS
/* Example for Styling Tables */
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
```
--------------------------------
### CSS for Display and Opacity Transitions
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
This CSS code styles the HTML elements and defines the transitions for opacity and display properties. It includes a '.showing' class to control the visible state and uses '@starting-style' to manage the initial state for smooth transitions, especially when an element first appears.
```css
html {
height: 100vh;
}
div {
font-size: 1.6rem;
padding: 20px;
border: 3px solid red;
border-radius: 20px;
width: 480px;
display: none;
opacity: 0;
transition:
opacity 1s,
display 1s allow-discrete;
/* Equivalent to
transition: all 1s allow-discrete; */
}
.showing {
opacity: 1;
display: block;
}
@starting-style {
.showing {
opacity: 0;
}
}
```
--------------------------------
### CSS justify-content: start
Source: https://css-tricks.com/snippets/css/complete-guide-grid
Aligns the grid to be flush with the start edge of the grid container. This is useful when the total size of grid items is less than the container size.
```CSS
.container {
justify-content: start;
}
```
--------------------------------
### CSS fit-content Syntax
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/fit-content
Demonstrates the basic syntax for applying the `fit-content` keyword to CSS sizing properties like width and height.
```CSS
/* Used in sizing properties */
width: fit-content;
height: fit-content;
inline-size: fit-content;
block-size: fit-content;
```
--------------------------------
### CSS Styling Basics Tutorial
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout
Learn the fundamentals of CSS styling, including selectors, the box model, values, units, backgrounds, borders, and overflow properties. This section also covers debugging CSS and practical challenges.
```CSS
/* Example of basic CSS styling */
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
color: navy;
text-align: center;
}
```
--------------------------------
### Set and Get Element Class Attribute with JavaScript
Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/className
This JavaScript example shows how to set and get the 'class' attribute of an HTML element using `setAttribute` and `getAttribute`. This is particularly useful when dealing with SVG elements.
```javascript
elm.setAttribute("class", "my-class");
const myClass = elm.getAttribute("class");
```
--------------------------------
### CSS Flexbox: Align Items Example
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Shows an example of the 'align-items' property in CSS Flexbox, which sets the default alignment for items in the current flex line. It controls how flex items are positioned along the cross-axis.
```CSS
.element { align-items: flex-start; }
```
--------------------------------
### CSS Layout Techniques
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
Explores various CSS layout methods, including floats, positioning, Flexbox, CSS Grid Layout, responsive design principles, and media queries for creating adaptable web layouts.
```CSS
/* Example for Floats */
.float-left {
float: left;
margin-right: 10px;
}
```
```CSS
/* Example for Positioning */
.relative-pos {
position: relative;
top: 10px;
left: 5px;
}
```
```CSS
/* Example for Flexbox */
.flex-container {
display: flex;
justify-content: space-between;
}
```
```CSS
/* Example for CSS Grid Layout */
.grid-container {
display: grid;
grid-template-columns: auto 1fr auto;
gap: 10px;
}
```
```CSS
/* Example for Media Queries */
@media (max-width: 600px) {
.sidebar {
display: none;
}
}
```
--------------------------------
### Flexbox Layout Example - CSS
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This CSS snippet demonstrates a flexbox layout, likely for a responsive design. It uses flex properties to control alignment and distribution of items within a container. The example provided by Andy Maleh on CodePen illustrates these concepts.
```CSS
/* Example CSS for flexbox layout */
.container {
display: flex;
align-items: center; /* Aligns items vertically */
justify-content: center; /* Aligns items horizontally */
height: 300px; /* Example height for demonstration */
}
.item {
/* Flex item properties */
}
```
--------------------------------
### CSS Layout Cookbook Recipes
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function
Provides recipes for common CSS layout patterns, such as centering elements, sticky footers, navigation layouts, and card designs. These examples demonstrate practical application of CSS for building user interfaces.
```CSS
/* Recipe: Media objects */
/* Column layouts */
/* Center an element */
/* Sticky footers */
/* Split navigation */
/* Breadcrumb navigation */
/* List group with badges */
/* Pagination */
/* Card */
/* Grid wrapper */
```
--------------------------------
### Handle Animation Events
Source: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste
Event listeners for CSS animation lifecycle events, including start, end, and iteration.
```JavaScript
element.onanimationstart = handler;
```
```JavaScript
element.onanimationend = handler;
```
```JavaScript
element.onanimationiteration = handler;
```
--------------------------------
### Handle XR Events
Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
Experimental events related to WebXR, such as `beforexrselect`.
```JavaScript
element.addEventListener('beforexrselect', handler);
```
--------------------------------
### Handling Browser Events
Source: https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
Shows how to handle common browser events like BeforeUnloadEvent and HashChangeEvent. These events are vital for user interaction and managing URL changes.
```JavaScript
window.addEventListener('beforeunload', (event) => {
event.preventDefault();
event.returnValue = 'Are you sure you want to leave?';
});
```
```JavaScript
window.addEventListener('hashchange', (event) => {
console.log('Hash changed to:', event.newURL);
});
```
--------------------------------
### Add Icons to ComboBox Items
Source: https://hopper.workleap.design/components/ComboBox.txt
Demonstrates how to include icons within ComboBox items. This example shows adding icons at the start of the item text.
```tsx
import { ComboBox, ComboBoxItem, IconList, Text } from "@hopper-ui/components";
import { SparklesIcon } from "@hopper-ui/icons";
export default function Example() {
return (
DeveloperDesignerManager
);
}
```
--------------------------------
### Add compositionstart Event Listener
Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
Demonstrates how to add an event listener for the `compositionstart` event using `addEventListener()` or by setting the `oncompositionstart` property. This is useful for capturing the beginning of a text composition session.
```javascript
addEventListener("compositionstart", (event) => { })
oncompositionstart = (event) => { }
```
--------------------------------
### Handle transitionstart event in JavaScript
Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll_event
The `transitionstart` event is fired when a CSS transition starts. It's useful for tracking when animations begin.
```javascript
element.addEventListener('transitionstart', (event) => {
console.log('Transition started');
});
```
--------------------------------
### HTML for CSS Flexbox Alignment
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
The HTML structure corresponding to the CSS Flexbox alignment example, showing a container and an item to be centered.
```HTML