2012年7月18日 星期三

Convert CSS into programmable CSS with LESS syntax

This class can convert CSS into programmable CSS with LESS (Leaner CSS) syntax.

It can parse a given CSS style sheet and extract certain common property constant values to turn them into variables in the converted output using LESS .

Currently it turns the CSS properties into LESS variables: color, width, height, font-family and font-size.

include_once 'css2less/class.css2less.php';

# sample: creates less source

$css = <<< EOD
#sidebar {
  padding: 0;
  margin: 0;
  font-size: 11px;
  width: 217px;
  position: absolute;
  top: 45px;
  left: 0;
  background-color: #EFEFEF;
  color: #444;
}

#sidebar h3 {
  clear: both;
  padding: 0;
  font-size: 12px;
  font-weight: bold;
}

#sidebar input[type='text'],
#sidebar input[type='password'],
#sidebar textarea {
  width: 186px;
  padding: 6px 5px;
  color: #626262;
  font-family: "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", "Luxi Sans", Tahoma, sans-serif;
  font-size: 1em;
  border: 1px solid #CCC;
  box-shadow: inset 0 1px 3px #E4E4E4;
}

EOD;

$cls = new CSS2LESS($css);
$less = $cls->convert();
echo sprintf('<pre>%s</pre>
', $less);


範例:/test/css2less_sample.php

沒有留言: