• Home
  • Development Tools
  • Services
  • Web UI Components

WeMakeSites.NET | CSS3, HTML5, JavaScript, AJAX and More

The Fine Art of Web Development

Feeds:
Posts
Comments
« 2011 in Review
CSS File Merger and Minifier »

Maintainable CSS3 Preprocessor and Generator for PHP

January 16, 2012 by acidmartin

If you are looking for a complete CSS merging and minification tool, check Builder.CSS, otherwise, keep reading this post :)

Here is a small script written in PHP for rendering of vendor-specific CSS3 properties on the fly, by defining them just once using the official W3C syntax. The css3 function generates not only vendor-specific properties, such as -moz-user-select, but also vendor-specific property values like the various CSS3 functions such as calc(), element(), linear- and radial-gradient(). You can download it from this link.

Below is an example for defining a vendor-specific property:

div
{
<? css3('transition', 'opacity 200ms linear'); ?>
}

… Which will output:

div
{
-moz-transition: opacity 200ms linear;
-webkit-transition: opacity 200ms linear;
-o-transition: opacity 200ms linear;
-ms-transition: opacity 200ms linear;
transition: opacity 200ms linear;
}

And here’s an example for defining the CSS3 function element():

div
{
<? css3('background', 'element(#background-div)'); ?>
}

… Which will give you:

div
{
background: -moz-element(#background-div);
background: -webkit-element(#background-div);
background: -o-element(#background-div);
background: -ms-element(#background-div);
background: element(#background-div);
}

* As of January 2012, the element() function is supported only by Mozilla FireFox, so you may consider using normal CSS to define that function.

All Features:

  • Detects and renders both vendor-specific properties and vendor-specific values, such as CSS3 functions;
  • Combines multiple CSS files into one;
  • If GZIP is available, the output stylesheet is gzipped and its size is much smaller than the size of all CSS files;
  • Supports multiple CSS3 property values, such as:
    div
    {
    <? css3('background', 'url("background.png") no-repeat center, linear-gradient(#ccc, #333)'); ?>
    }
    

Requirements:

  • Web-server with PHP support;

Usage:

  1. Register the script the way you normally register style sheets on the page:
    <link rel="stylesheet" href="css3.php?files=" />
    
  2. In the files parameter, define the path to all of the stylesheets that you want to merge:
    <link rel="stylesheet" href="css3.php?files=Styles/styles-01.css,Styles/styles-02.css" />
    

    The order in which you define them is going to be their inclusion order in the final PHP-processed file. Make sure that URLs, pointing to external assets such as background images and fonts are set relatively to the css3.php file, otherwise, they will not be requested correctly.

  3. In each of the CSS files, use the css3($property, $value) function to define CSS3 properties:
    div
    {
    <? css3('background', 'element(#background-div)'); ?>
    }
    
  4. If you wish to exclude some specific vendor properties, you can just remove them from the $prefixes array in the css3.php file:
    $prefixes = array('-moz-', '-webkit-', '-o-', '-ms-');
    

    The script can be easily changed to allow passing of prefixes as a function argument, if you wish to define the properties per function usage. Even better – the third argument can be an exclusion array, which will be checked against the vendor-specific array in the script itself (in_array()). Basically, you can change the function to this:

    div
    {
    <? css3('background', 'element(#background-div)', array('-moz-', '-webkit-')); ?>
    }
    
  5. Is is recommended to extend the script so it checks for already existing processed file on the server, instead of processing and merging it each time the page is requested. If the file does not exist, then the result of the PHP processing can be output to a static file that will be served.

The script can be downloaded from here. Other cool HTML5, CSS3 and JavaScript experiments can be found on this page.

Advertisement

Share this:

  • StumbleUpon
  • Digg
  • Reddit

Like this:

Like
One blogger likes this post.
  • acidmartin

Posted in CSS, CSS3, php | Tagged css3 generator, css3 preprocessor for php, maintainable css3 preprocessor, php css preprocessor | Leave a Comment

  • Follow

    @wemakesitesnet
  • Share

    Bookmark and Share
  • Blogroll

    • Acid.JS Web.UI
    • Amir Harel
    • CSS Minifier and Merger
    • Hotel Booking Form UI
    • HTML5 Guitar Chord Finder
    • Image Slider UI
    • JavaScript Obfuscator
    • JavaScript, CSS3 and HTML5 Experiments
    • Liubomir Stoianov
    • Progress Bar UI
    • Ribbon Bar UI
    • RSS Feed
    • Split Button UI
    • Tabstrip UI
    • WeMakeSites.NET
    • Window UI
  • Categories

    • acc-checker-js (1)
    • accessibility (1)
    • Acid.JS (29)
    • Acid.RSS (2)
    • AJAX (34)
    • AJAX Photo Gallery (7)
    • Annual Review (2)
    • Browsers (14)
    • builder-css (2)
    • builder-js (1)
    • ButtonReplacement.JS (2)
    • captcha-ajax (1)
    • CheckBox.XML (3)
    • ColorPicker.JS (2)
    • contact-form-js (5)
    • Content Management (10)
    • ContextMenu.XML (1)
    • Cool Websites (6)
    • CSS (47)
    • CSS Hacks (14)
    • CSS3 (19)
    • Deals and Promotions (3)
    • dhtml window (1)
    • dialogs-js (7)
    • doctype (3)
    • editor-bb (1)
    • EULA.XML (1)
    • Fonts (1)
    • form styling (2)
    • Forms (43)
    • forms-js (7)
    • Fun (1)
    • gallery (1)
    • gallery-xml (19)
    • guestbook-xml (4)
    • guitar-chords-js (1)
    • help and manuals (1)
    • hotel-reservation-form-js (9)
    • HTML5 (6)
    • image-slider-js (1)
    • Input.JS (1)
    • JavaScript (25)
    • LoadingPanel.JS (1)
    • minifier (3)
    • News (79)
    • obfuscation (3)
    • PageAnnouncement.XML (1)
    • php (2)
    • progressbar-js (1)
    • RadioButton.XML (3)
    • ribbon-bar-xml (2)
    • Rounded CSS Corners (17)
    • rounded-corners-panel-js (4)
    • Search (10)
    • SearchBox.XML (1)
    • SelectBoxReplacement.JS (1)
    • Skinnable Web 2.0 Buttons (1)
    • skinnable window (1)
    • SpinBox.JS (3)
    • split-button-xml (1)
    • Survey (1)
    • SVG (1)
    • tabstrip-xml (5)
    • Thoughts (5)
    • TinySite.XML (2)
    • Tips and Tricks (39)
    • Tools (3)
    • tooltip (1)
    • tooltip-js (1)
    • tour-dates (3)
    • Typography (1)
    • Updates (5)
    • Upload.XML (1)
    • usability (1)
    • UX (5)
    • voting-poll (3)
    • Web 2.0 AJAX Loading Panel (7)
    • web 2.0 window (1)
    • Web Development (34)
    • Website Widgets and Parts (99)
    • window component (1)
    • window-js (1)
    • XHTML (12)
    • XML (14)
    • YUI (2)
  • Most Popular Posts

    • The Mystery of c:\fakepath Unveiled
    • Using CSS to Style Radiobuttons and Checkboxes in Safari and Chrome
    • Using the IE8 X-UA Compatibility Meta Tag Properly
    • CSS3 Treevew. No JavaScript.
    • Imageless CSS3 Custom Checkboxes and Radio Buttons
    • Setting Opacity and Other Filters in Internet Explorer 8
    • Creating a Gaussian Blur Effect With CSS3
    • CSS Hack for Internet Explorer 8
    • Controlling the CSS Opacity Rate of Child Elements in Transparent Parents in Internet Explorer
    • Custom Crossbrowser Styling for Checkboxes and Radio Buttons
  • Recent Posts

    • Funny, but True Facts About Novice Developers
    • Follow me on Twitter
    • Builder.CSS 2.0 Minifier and Merger is Out
    • JavaScript Merger, Minifier and Obfuscator
    • CSS File Merger and Minifier
  • Archives

    • February 2012 (4)
    • January 2012 (3)
    • November 2011 (1)
    • October 2011 (3)
    • September 2011 (3)
    • August 2011 (1)
    • June 2011 (2)
    • May 2011 (2)
    • April 2011 (1)
    • March 2011 (2)
    • February 2011 (1)
    • January 2011 (1)
    • December 2010 (4)
    • November 2010 (7)
    • October 2010 (1)
    • September 2010 (1)
    • August 2010 (4)
    • July 2010 (10)
    • June 2010 (3)
    • May 2010 (4)
    • April 2010 (1)
    • March 2010 (3)
    • February 2010 (2)
    • January 2010 (1)
    • November 2009 (4)
    • October 2009 (4)
    • September 2009 (5)
    • August 2009 (5)
    • July 2009 (7)
    • June 2009 (4)
    • May 2009 (7)
    • April 2009 (1)
    • March 2009 (7)
    • February 2009 (2)
    • January 2009 (3)
    • December 2008 (2)
    • November 2008 (9)
    • October 2008 (7)
    • September 2008 (4)
    • August 2008 (5)
    • July 2008 (4)
    • June 2008 (2)
    • May 2008 (4)
    • April 2008 (1)
    • March 2008 (1)
    • September 2007 (1)
    • July 2007 (1)
    • May 2007 (1)
    • April 2007 (1)
    • March 2007 (1)
    • January 2007 (1)
    • December 2006 (1)
  • Tags

    acid.js AJAX ajax booking form ajax form ajax guestbook ajax hotel booking form ajax library ajax toolkit ajax tools browser gui cms CSS css filters css hack css tricks custom alert custom checkbox custom checkboxes custom combobox customdialogs custom dropdown custom radiobuttons Forms form skinning form styling hotel-reservation-form-js hotel reservation form JavaScript javascript library js library lightbox php hotel booking form php hotel reservation form reservation form script reservation php script rounded corner textboxes selectbox replacement skinnable forms tabstrip web 2.0 web 2.0 form website controls website widgets XML xmlhttprequest

Blog at WordPress.com.

Theme: MistyLook by Sadish.


Follow

Get every new post delivered to your Inbox.

Powered by WordPress.com