Order of applying styles

Abierto
#2,069 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 5 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
css, html, php
Área
backend

Línea de trabajo

Reproduce with the two testcases in the issue body: div elements with classes text-b text-a and text-b text-c, then compare the computed styles. The payload does not name the source files, so search the codebase for where class selectors are matched and applied in order. Done means both class orderings produce the same declarations, with the later class in the attribute winning for conflicting properties.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug/fix help wanted HTML/CSS support
Guidelines
Description of the bug

The order in which styles are applied is affected by the class name:

I've provided 2 examples that demonstrate this

Example 1:

<div class="text-b text-a">Foo</div>

Expected output:

  • color: red;
  • background-color: blue;
  • text-transform: uppercase;
  • text-decoration: line-through;

Actual output:

  • color: green;
  • background-color: black;
  • text-transform: uppercase;
  • text-decoration: line-through;

Since text-decoration: line-through was applied, this means that text-a was applied first and then text-b

test_mpdf_b_a

But if we rename the text-a class to text-c, we will get the expected result

Example 2:

<div class="text-b text-c">Foo</div>

Actual output:

  • color: red;
  • background-color: blue;
  • text-transform: uppercase;
  • text-decoration: line-through;
test_mpdf_b_c

It seems that the order in which classes are applied is affected by alphabetical order.

Note: If you render html in a browser, this problem does not occur.

mPDF version

v8.2.4

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

PHP 7.4.33 (cli) (built: Sep 27 2024 12:56:02) ( NTS ) and PHP 8.3.12 (cli) (built: Sep 24 2024 18:08:04) (NTS)

Reproducible PHP+CSS+HTML snippet suffering by the error

First testcase:

<?php

require __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4',
]);

$html = <<<HTML
<html lang="en">
    <head>
        <title>Testcase</title>
    </head>
    <style>
        div {font-size: 108px;}
            
        .text-b {
            background-color: black;
            text-transform: uppercase;
            color: green;
        }
        
        .text-a {
            background-color: blue;
            color: red;
            text-decoration: line-through;
        }
    </style>
    <body>
        <div id="root">
            <div class="text-b text-a">Foo</div>
            <hr>
            <div class="text-a text-b">Bar</div>
        </div>
    </body>
</html>
HTML;

$mpdf->WriteHTML($html);
$mpdf->Output('test_b_a.pdf', 'F');

Second testcase:

<?php

require __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4',
]);

$html = <<<HTML
<html lang="en">
    <head>
        <title>Testcase</title>
    </head>
    <style>
        div {font-size: 108px;}
            
        .text-b {
            background-color: black;
            text-transform: uppercase;
            color: green;
        }
        
        .text-c {
            background-color: blue;
            color: red;
            text-decoration: line-through;
        }
    </style>
    <body>
        <div id="root">
            <div class="text-b text-c">Foo</div>
            <hr>
            <div class="text-c text-b">Bar</div>
        </div>
    </body>
</html>
HTML;

$mpdf->WriteHTML($html);
$mpdf->Output('test_b_c.pdf', 'F');
Lenguaje dominante
PHP
Estrellas
4.7k
Forks
1.1k
Merge medio
6 d 11 h
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de mpdf/mpdf

Todos los issues de mpdf/mpdf

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.