Pattern CSS – Inline Block Styles

Descrizione

L’editor di CSS in linea che mancava per i blocchi. Molto potente con i pattern sincronizzati. Si associa bene agli stili globali.

Tutorial

  • Every block will have a new “Pattern CSS” settings panel.
  • Per puntare un blocco, puoi usare il selettore [block].
  • Per puntare un elemento interno al blocco, usa il normale selettore CSS.
  • Use !important to override your theme styles (use sparingly)

Features

  • Caricamento intelligente. Carica il CSS solo quando il blocco è presente
  • No lock in. The styles are attached to the block attributes
  • Scopes styles to the block so that parent/sibling blocks are not affected
  • It’s fast. CSS is minified and optimized in the browser
  • It’s safe. Invalid, non-spec CSS is never persisted (validated via webassembly sandbox)
  • Supports reusable (synced or not-synced) patterns
  • See changes on the page as you make them
  • Combines adjacent rules (to decrease size)
  • Minifies colors and math functions to simplify according to spec
  • Supporta il CSS innestato

Segui su GitHub
DM su Twitter @kevinbatdorf

Esempi di base

/* Target the block directly */
[block] {
  background: antiquewhite;
  padding: 2rem;
}
/* Target any inner elements */
a {
  text-decoration-color: burlywood;
  text-decoration-thickness: 2px;
  text-decoration-style: solid !important;
}
a:hover {
  text-decoration-color: darkgoldenrod;
}

/* Output: */
.pcss-a1b7b016{background:#faebd7;padding:2rem}.pcss-a1b7b016 a{text-decoration-color:#deb887;text-decoration-thickness:2px;text-decoration-style:solid!important}.pcss-a1b7b016 a:hover{text-decoration-color:#b8860b}

Supports Media Queries

@media (prefers-color-scheme: dark) {
  [block] {
    border-color: blue;
  }
}

/* Output: */
@media (prefers-color-scheme:dark){.pcss-cddaa023{border-color:#00f}}

Combines Rules

[block] {
  color: red;
}
.bar {
  color: red;
}

/* Output: */
.pcss-3aa0f0fc,.pcss-3aa0f0fc .bar{color:red}

Fixes redundant properties

[block] {
  padding-top: 5px;
  padding-left: 50px;
  padding-bottom: 15px;
  padding-right: 5px;
}

/* Output: */
.pcss-3aa0f0fc{padding:5px 5px 15px 50px}

Supporta il CSS innestato

[block] {
  padding: 1rem;
  a {
    color: red;
  }
  background: white;
  /* Including media queries */
  @media (prefers-color-scheme: dark) {
    background: black;
    color:white;
  }
}

/* Output: */
.pcss-f526bb2d{background:#fff;padding:1rem;& a{color:red}@media (prefers-color-scheme:dark){&{color:#fff;background:#000}}}

Check browser support for CSS nesting

Screenshot

  • Aggiungi stili non disponibili nell’editor
  • Supporta anche i pattern riutilizzabili e sincronizzati
  • Ti avviserà se il tuo CSS non è corretto

Installazione

  1. Attiva il plugin dalla schermata ‘Plugin’ di WordPress

FAQ

Error about application/wasm mime type

Your server needs to be able to identify the mime type being used. See here: https://wordpress.org/support/topic/webassembly-instantiatestreaming-failed-because-your-server-does-not-serve-wasm/

Posso usare qualcosa di diverso da [block]?

You can add a custom selector via a PHP constant. It requires setting a type (type, attribute, etc) and the name.

Ecco un esempio per “foo { color: red}”, dove foo verrà rimpiazzato da .pcss-h3Hso39bsK (o qualcosa di simile):

Add this to functions.php:

define('PATTERN_CSS_SELECTOR_OVERRIDE', ['name' => 'foo', 'type' => 'type']);

Recensioni

13 Settembre 2024 1 risposta
As a seasoned WP developer often working on tight timelines and sometimes on tight budgets, this is such an important tool. Thank you for making it! Inline block styles are such an efficient and performant way to quickly customise the styles of blocks. Love it!
26 Luglio 2024 1 risposta
@Support Moderator I have no intention of asking for support here, because WP has already given up on support and is deleting posts. This is just a review. Anyway, after updating to 6.6.1 my code started breaking. This plugin may not be the cause, but it’s the only plugin that causes the error. Error loading block: Invalid parameter(s): attributes ‘Is WP trying to hide this issue by deleting reviews?’ PCSS plugin that allows to easily input CSS into pattern blocks. post results are displayed normally.
Leggi tutte le recensioni di 4

Contributi e sviluppo

“Pattern CSS – Inline Block Styles” è un software open source. Le persone che hanno contribuito allo sviluppo di questo plugin sono indicate di seguito.

Collaboratori

“Pattern CSS – Inline Block Styles” è stato tradotto in 1 lingua. Grazie ai traduttori per i loro contributi.

Traduci “Pattern CSS – Inline Block Styles” nella tua lingua.

Ti interessa lo sviluppo?

Esplora il codice segui il repository SVN, segui il log delle modifiche tramite RSS.

Changelog

1.2.5 – 2024-07-28

  • Fixed a small bug where a block may not have attributes when we access them.

1.2.4 – 2024-07-21

  • Renamed the panel to Pattern CSS to differenciate it from the core panel on FSE

1.2.3 – 2024-05-09

  • Removed globals like @import, @font-face, and @keyframes (and others)

1.2.2 – 2024-04-19

  • Fixed an issue where CSS media queries using <= were stripped out
  • Removed loading the viewer for users without the edit_css cap
  • Removed the tag stripping output – now only privlidged users can use
  • Updated tests to run on modern WP (by disabling the iframe)

1.2.1 – 2024-02-22

  • Removed the example code and added a useful default
  • Render blocks now work – now adds the id to the main class list

1.2.0 – 2024-02-20

  • Feature: Adds support for CSS nesting
  • Removes the code example on focus and adds it back on blur (if empty)
  • Lets users define an additional block selector
  • Adds a notice that the site logo isn’t currently supported

1.1.0 – 2024-02-18

  • Prevent adding classes to blocks unless CSS is added
  • Force the settings area to the bottom (mainly for custom blocks)

1.0.1 – 2023-11-04

  • Fixed a bug where the it would crash on the pattern manager page

1.0.0 – 2023-07-15

  • Feature: Now supports reusable blocks/patterns
  • Update: Removed the “per page” functionality to limit the scope of this plugin to blocks and reusable patterns only
  • Performance: Added global loading strategy to prevent per block n+1 loading issues
  • Improvement: Added the option to update the CSS selector used for scoping (useful for duplicating blocks)
  • Improvement: Added some examples when no CSS is present
  • Improvement: Removed the public className attribute requirement from the Additional Settings area
  • Improvement: Instead of saving as meta on a post, it now pulls from the attribute directly during page load (via the pre_render_block filter).
  • Fix: Now it will only show on post types with the public setting set to true