How to make rounded buttons with the button element
25 pixel high buttons at your service:
1 button { 2 border: 0; 3 padding: 0; 4 font-variant: small-caps; 5 height:25px; 6 background: transparent url('../images/button-background-left.png') no-repeat; 7 cursor: pointer; 8 text-align: center; 9 } 10 11 button span { 12 font-family: georgia,serif; 13 line-height: 25px; 14 background: transparent url('../images/button-background.png') no-repeat top right; 15 position:relative; 16 display:block; 17 white-space:nowrap; 18 margin-top: -2px; 19 padding:0 15px; 20 }
HTML :
1 <button type="submit" value="Hello"><span>Hello »</span></button>
IE 6 & 7 might need:
1 button { 2 width:auto; 3 overflow:visible; 4 } 5 button span { 6 margin-top:1px; 7 }
References
- http://www.filamentgroup.com/lab/styling_the_button_element_with_sliding_doors/
- http://particletree.com/features/rediscovering-the-button-element/
Combining CSS and JavaScript files with PHP to reduce page load time
This is a very simple utility class that I created which combines multiple files into one—in contrast to all other PHP scripts I’ve found elsewhere, which all work badly and are a million lines long, this one is simple to understand and maintain:
1 <?php 2 class Files 3 { 4 private static function process($files, $output, $base_dir = '') 5 { 6 $contents = ''; 7 8 # If this is a string then it's a search pattern 9 if(is_string($files)) 10 { 11 $files = glob($files); 12 } 13 14 foreach ($files as $file) 15 { 16 $contents .= file_get_contents($base_dir.$file) . "\n\n"; 17 } 18 19 # TODO locking 20 if ($fp = fopen($output, 'wb')) 21 { 22 fwrite($fp, $contents); 23 fclose($fp); 24 } 25 26 return $contents; 27 } 28 29 # 30 # Combine all CSS files in the css directory: 31 # 32 # echo Files::combine("css/*.css", "css/all.css"); 33 # 34 # Combine only specified files in the given order: 35 # 36 # echo Files::combine(array("css/core.css", "css/default.css"), "css/all.css"); 37 # 38 # 39 static function combine($files, $output_filename, $base_dir = '') 40 { 41 # Combine the files 42 if(!file_exists($output_filename)) 43 { 44 self::process($files, $output_filename, $base_dir); 45 } 46 } 47 } 48 ?>
The call to Files::combine should go in a file that is called on each request. On the first request to this file, the files are combined into one, on subsequent requests nothing is done, the only overhead is a call to file_exists.
Ideally the name of the output filename should contain a version number, so that an updated CSS file is not taken from the browser cache. This can easily be supported by reading the build number from somewhere and appending it to the output filename:
1 Files::combine("css/*.css", "css/all-v$version.css");
Now all you have to do is add this to your HTML :
1 <link rel="stylesheet" type="text/css" href="/css/all-v<?php echo $version ?>.css" media="screen" />
This also works for JavaScript files. Note that I don’t make an effort to minify anything as GZIP usually does a great job at minimizing bandwidth costs.
Show and Hide (toggle) the Blueprint Grid with a JavaScript
This snippet-which could be improved on-allows you to easily display and hide the BlueprintCSS grid.
Put the following code inside the <head> element:
1 <style title="grid" type="text/css"> 2 .container { } 3 </style> 4 <script type="text/javascript"> 5 function toggleGrid() { 6 if (!document.styleSheets) return; 7 8 var cssTitle = "grid" 9 var selectorName = ".container"; 10 var cssText = "background: url('images/grid.png');"; 11 var css = new Array(); 12 13 // Find the stylesheet 14 for(i = 0; i < document.styleSheets.length; i++) 15 { 16 var styleSheet = document.styleSheets[i]; 17 18 if(styleSheet.title == cssTitle) { 19 if (document.styleSheets[i].cssRules) 20 css = document.styleSheets[i].cssRules; 21 else if (document.styleSheets[i].rules) 22 css = document.styleSheets[i].rules; 23 else return; 24 25 break; 26 } 27 } 28 29 // Find the selector 30 for (i = 0; i < css.length; i++) { 31 32 if ((css[i].selectorText.toLowerCase() == selectorName)) { 33 if(css[i].style.cssText == "") { 34 css[i].style.cssText = cssText; 35 } 36 else { 37 css[i].style.cssText = ""; 38 } 39 } 40 } 41 } 42 </script>
Change selectorName or cssText, if needed. Next add the following link, for example, to the footer:
1 <a href="javascript:toggleGrid();" id="toggle-grid">Show grid</a>
Now when you click the link, the grid will be displayed. Click again to hide it.
Note that this is a simple example of how to change a CSS style sheet dynamically with JavaScript. You can use it to change any selector at runtime.
How to create a mixed 2 to 3 column layout with footer and header
This is a draft, and an experiment with composing to a vertical flow and the golden ratio
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html> 4 <head> 5 <title>3 column</title> 6 <style type="text/css"> 7 8 /** Reset styles */ 9 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,p,blockquote,th,td { 10 margin:0; 11 padding:0; 12 } 13 14 /** 3 column layout */ 15 16 #container{ 17 background-color:#9cc; 18 width: 69em; 19 margin: 0 auto; 20 } 21 22 #content{ 23 float: left; 24 width: 41em; 25 } 26 27 #sidebar{ 28 float: right; 29 width: 23em; 30 } 31 32 #column1{ 33 float: left; 34 width:23em; 35 } 36 37 #column2{ 38 float: left; 39 width:23em; 40 } 41 42 #column3{ 43 float: left; 44 width:23em; 45 } 46 47 48 /* Vertical flow */ 49 50 body { 51 font-size: 75%; 52 } 53 54 html>body { 55 font-size: 14px; 56 } 57 58 p { 59 line-height 1.5em; 60 } 61 62 63 /* Temp styles */ 64 #column1, #column2, #column3, #content, #sidebar { 65 # background: blue; 66 # border: 1px solid black; 67 } 68 69 /** */ 70 body{ 71 font-family: Palatino,"Palatino Linotype",Georgia,serif; 72 } 73 74 </style> 75 </head> 76 <body> 77 78 <div id="header"> 79 <div id="container"> 80 <div id="column1">Header 1</div> 81 <div id="column2">Header 2</div> 82 <div id="column3">Header 3</div> 83 </div> 84 </div> 85 86 <div id="container"> 87 <div id="content">Content</div> 88 <div id="sidebar">Sidebar</div> 89 </div> 90 91 <div id="footer"> 92 <div id="container"> 93 <div id="column1">Footer 1</div> 94 <div id="column2">Footer 2</div> 95 <div id="column3">Footer 3</div> 96 </div> 97 </div> 98 99 </body> 100 </html>
A simple image replacement technique for increased usability and SEO ranking
This is currently my favorite image replacement technique. I don’t remember where I found it… Using it can improve both your site’s usability and your search engine ranking, by allowing both screen readers and search engines to find your h1 headlines. First create the h1 and the description of your page/site, for example:
1 <h1 id="logo">Viagra, Botox, you name it</h1>
Then create the CSS rule for the page title:
1 h1#logo { 2 text-indent: -9000px; 3 background: url(logo.gif); 4 width: 200px; /* Width of image */ 5 height: 50px; /* Height of image */ 6 }
People using a modern browser that support CSS will see your logo (the image), and search engines and people using less modern browsers will see the content of the h1 header tag.
Note that if you replace the text of a link then use the outline CSS property to remove the dotted border:
1 .text-replacement { 2 text-indent: -9000px; 3 } 4 5 .text-replacement a { 6 outline: none; 7 }