Skip to content

Commit

Permalink
Output styles before the element
Browse files Browse the repository at this point in the history
The reason for this is nested content such as:

    <group class="wp-element-1">
      <p>Text with <link> and colors inherited from group</p>
      <p class="wp-element-2">Text with <link> and own colors</p>
    </group>

The selectors for the link are

- ".wp-element 1 a" => generated by the group
- ".wp-element-2 a" => generated by the paragraph

because they have the same specificity the latest will win.
We need the styles to respect the DOM order of the elements
that have them.

    <style .wp-element-1>
    <style .wp-element-2>
    <group ...>...</group>
  • Loading branch information
oandregal committed Sep 9, 2021
1 parent bc67b3d commit 8d38f00
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function gutenberg_render_elements_support( $block_content, $block ) {
$first_element_offset = $html_element_matches[0][1];
$content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 );
}
return $content . $style;
return $style . $content;

}

Expand Down

0 comments on commit 8d38f00

Please sign in to comment.