sabberworm / PHP-CSS-Parser

A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$block->expandShorthands() adds none-stated values

Idrinth opened this issue · comments

I would have expected it to not add defaults, so that background: #fff doesn't suddenly include a statement regarding background-repeat

Edit: Code that this happend on:

.x3-login-window .x3-login-window-tr, .x-panel-ghost .x3-login-window-tr {
    background: -moz-linear-gradient(top, #0072a3, #075a79);
    background: -webkit-gradient(linear, 0 0, 0 100%, from(#0072a3), to(#075a79));
    background: linear-gradient(top, #0072a3, #075a79);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0072a3', endColorstr='#075a79');
    color: #FFFFFF;
    font-family: Arial,Helvetica,sans-serif;
    font-size: 14px;
    font-style: normal;
    font-weight: bold;
    padding: 3px 3px 0 20px;
    margin: 0 0 5px;
    height: 21px;
array(20) {
  string(98) "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#0072a3",endColorstr="#075a79");"
  string(12) "color: #fff;"
  string(40) "font-family: Arial,Helvetica,sans-serif;"
  string(16) "font-size: 14px;"
  string(19) "font-style: normal;"
  string(17) "font-weight: 700;"
  string(13) "height: 21px;"
  string(14) "margin-top: 0;"
  string(16) "margin-right: 0;"
  string(19) "margin-bottom: 5px;"
  string(15) "margin-left: 0;"
  string(17) "padding-top: 3px;"
  string(19) "padding-right: 3px;"
  string(18) "padding-bottom: 0;"
  string(19) "padding-left: 20px;"
  string(30) "background-color: transparent;"
  string(23) "background-image: none;"
  string(26) "background-repeat: repeat;"
  string(30) "background-attachment: scroll;"
  string(27) "background-position: 0% 0%;"

I would have expected that too. I don’t know if @ju1ius, the original contributor of the shorthands feature, is interested in fixing this. Otherwise, someone else can provide a PR.

I would have expected it to not add defaults,

But that is how CSS works. When using shorthand properties (background, margin, border, padding, etc...), a value which is not specified is set to its initial value. Please refer to
In your case, you should use the background-image property, not the background shortand.

I agree, that this follows the standards for interpreting shorthand properties when appliing them to a html, I'm not sure if it should be the case for parsing stated properties.

What about a flag when expanding shorthands, that states if you want defaults to be added? That would solve the disparity between expected behaviour and current behaviour.

I would like to recant my previous statement. In fact, what happens now is exactly what I expect to happen. I don’t expect expandShorthands to change the effects of my CSS at all, which it would do, if it left out the defaults.

The only problem with this, IMHO, is that the CSS standard keeps evolving and the list of expanded properties keeps growing (think of display being a shorthand for display-inside and display-outside), which we need to keep up-to-date, possibly causing breaking changes in the process (e.g. if a browser doesn’t yet understand display-inside/display-outside).

I guess I’ll close this for now. @Idrinth, feel free to open a PR with your suggested flag, though.

ezoic increase your site revenue