Turn CSS rules into abbreviated rules using PHP

Asked

Viewed 65 times

0

Having a CSS file would like, using PHP, to change a line by joining the rules that can be abbreviated.

For example in this code:

margin-top: -2px; -> abreviável para MARGIN
padding-right: 40px; -> juntável para PADDING

the rules margin-X, padding-X are traceable to the following notation:

parameter: (TOP, RIGHT, BOTTOM, LEFT);

in case it would look like this:

margin: -2px, 0, 0, 0;
padding: 0, 40px, 0, 0;

For other spaces (top, right, bottom, left) not specified the value must be set to 0.

How to do it in PHP?

  • There’s no css tag on that question?

  • I couldn’t understand it.

  • @rray I arranged the question

  • @Wallacemaxters not necessarily

  • The margin-top: would be generated by you or read from a file? this did not give to understand, what is the origin?

  • first you’d have to learn to pick up the parameters, then put them together.

  • @rray ah, the source would be a normal css file.. take each parameter inside the {}

  • 1

    The problem here is that for CSS, the order is important, and you cannot skip the parameter in the middle. The most you can do, is to test if all are filled and are equal and use only one, or if you omit some would have to take the default, or Parent, depending on the attribute. Actually the problem of the question is a bit complex, and it would need to be better defined.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.