Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Styling Blocks with Multiple Approaches

This example demonstrates different techniques for styling WordPress blocks, showcasing best practices for managing CSS in block development. You'll learn how to implement styles using multiple approaches including inline styles, default classes, custom classes, and separate stylesheets for editor and frontend contexts.

Key concepts covered:

  • Inline styles through useBlockProps
  • Default WordPress block classes (wp-block-block-development-examples-stylesheets-79a4c3)
  • Custom class implementation (hasPerspective through useBlockProps)
  • Editor-specific styling (editor.scss)
  • Shared frontend/editor styles (style.scss)
Example Description Tags Download .zip Live Demo
Stylesheets Shows different approaches to adding and managing styles in blocks, including editor-specific and front-end styles. styles featured 📦 Image

Understanding the Example Code

Style Implementation Methods

  1. Inline Styles
    • Applied directly through useBlockProps
    • Provides dynamic styling capabilities
  2. CSS Classes
    • Default class: wp-block-block-development-examples-stylesheets-79a4c3
    • Custom class: hasPerspective (applied conditionally)

CSS Output Structure

The styles are output in several ways:

  1. Frontend Output
    • Block wrapper receives inline styles and classes
    • Shared styles loaded via style.scss
    • Editor-specific styles isolated in editor.scss

Image

The inline styles and classes (added via useBlockProps) for the block wrapper are added to the <div> container of the block

Image

The styles shared by the editor and the frontend (style.scss) have been inserted in a style tag

Image

Related Resources


Note Check the Start Guide for local development with the examples