remove white spaces in a css file

Discussion in 'CSS' started by bono056, Jan 20, 2011.

  1. #1
    hi
    i always delete white spaces between lines in my css files before upload it to server. i mean if my css file contains codes like this:
    
    body {
    	position: relative; 
    	background-color: #ffffff;
    	text-align: center;
    }
    Code (markup):
    i turn it to something like this:
    
    body {position: relative; background-color: #ffffff; text-align: center;}
    
    Code (markup):
    i do myself that takes alot of time. is there any tool for doing in a css file? i wonder if IDE s like dreamweaver or frontpage have this feature or not?
     
    bono056, Jan 20, 2011 IP
  2. WordOfMouth

    WordOfMouth Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There is an addon to Firebug for Firefox that does what you're looking for.
     
    WordOfMouth, Jan 20, 2011 IP
  3. steelfrog

    steelfrog Peon

    Messages:
    537
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    steelfrog, Jan 20, 2011 IP
  4. robsnob

    robsnob Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You may use php to do that.

    
    <?php
    
    // Path to css file.
    $cssFileLocation = 'http://test.com/test.css'
    
    echo str_replace(array("\r","\n"), ' ', file_get_contents($cssFileLocation));
    
    ?>
    
    
    PHP:
     
    robsnob, Jan 20, 2011 IP
  5. davmillar

    davmillar Peon

    Messages:
    12
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    One tool that I use is http://www.cleancss.com. Not only do I use it for eliminating white-space, but it comes in handy when reading others' CSS code that's formatted weirdly. The down-side is some browser-specific properties get messed up, and sometimes opacity values can be handled wrong.
     
    davmillar, Jan 21, 2011 IP
  6. bono056

    bono056 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    TanX, but i've searched css optimize, clean css, but could not find anything in firefox add on repository, i would be thankful if u mention th name.
     
    bono056, Jan 23, 2011 IP