Inappropriate Uses

Database is forcontent HTML is fordescribing and displaying content CSS is fordesign JavaScript is forfunctionality

 

Those are the appropriate uses for these technologies. Inappropriate use is when you cross those lines and create a mismatch.…

Avatar of Chris Coyier
Chris Coyier on

Basic Microformatted hCard

A basic address and URL, marked up using Microformats.

<div id="hcard-Christopher-John-Coyier" class="vcard">
 <a class="url fn n" href="http://chriscoyier.net">
  <span class="given-name">Christopher</span>
  <span class="additional-name">John</span>
  <span class="family-name">Coyier</span>
</a>
 <div class="org">CSS-Tricks</div>
 <a class="email" href="mailto:[email protected]">[email protected]</a>
 <div class="adr">
  <div class="street-address">123 Appleseed Street</div>
  <span class="locality">Chicago</span>, <span class="region">IL </span> 
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Font Shorthand

Syntax

body {
  font: font-style font-variant font-weight font-size/line-height font-family;
}

In Use

body {
  font: italic small-caps normal 13px/150% Arial, Helvetica, sans-serif;
}

You need to supply at least font-size and font-family for the shorthand to work, otherwise it’ll just …

Avatar of Chris Coyier
Chris Coyier on (Updated on )

Style Override Technique

p { 
   font-size: 24px !important; 
}

The !important rule at the end of a value will override any other style declarations of that attribute, including inline styles.…

Avatar of Chris Coyier
Chris Coyier on

Disable Automatic Formatting Using a Shortcode

function my_formatter($content) {
       $new_content = '';
       $pattern_full = '{(\[raw\].*?\[/raw\])}is';
       $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
       $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

       foreach ($pieces as $piece) {
               if (preg_match($pattern_contents, $piece, $matches)) {
                       $new_content .= $matches[1];
               } else {
                       $new_content .= wptexturize(wpautop($piece));
               }
       }

       return 
Avatar of Chris Coyier
Chris Coyier on

Modern Event Handling

<script type="text/javascript">
/**
 * Attach an event handler on a given Node taking care of Browsers Differences
 * @param {Object} node
 * @param {String} type
 * @param {Function} fn
 * @param {Boolean} capture
 */
function addEventHandler(node,type,fn , capture){
       if(typeof window.event 
Avatar of Chris Coyier
Chris Coyier on

MySQL Database Access Class

<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */


class dbAccess {

       var $db_connect_id;
       var $query_result;
       var $row = array();
       var $rowset = array();
       var $num_queries = 0;

       //
       // Constructor
       //
       function dbAccess($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) 
Avatar of Chris Coyier
Chris Coyier on

Create Unique AlphaNumeric

function MakeUnique($length=16) {
           $salt       = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
           $len        = strlen($salt);
           $makepass   = '';
           mt_srand(10000000*(double)microtime());
           for ($i = 0; $i < $length; $i++) {
               $makepass .= $salt[mt_rand(0,$len - 1)];
           }
       return $makepass;
}
Avatar of Chris Coyier
Chris Coyier on

Randomize File Name

function randomizeFileName( $real_file_name ) {
               $name_parts = @explode( ".", $real_file_name );
               $ext = "";
               if ( count( $name_parts ) > 0 ) {
                       $ext = $name_parts[count( $name_parts ) - 1];
               }
               return substr(md5(uniqid(rand(),1)), -16) . "." . $ext;
}
Avatar of Chris Coyier
Chris Coyier on

MySQL Restore Class

<?php

define('MSR_VERSION', '1.0.0');
define('__SEP__', "/*sep*/" );

define('MSR_STRING', 0);
define('MSR_FILE', 1);
set_time_limit( 600 );


class MySQL_Restore {

 var $server           = 'localhost';
 var $port             = 3306;
 var $username         = 'root';
 var $password         = '';
 var $database         = '';
 var $link_id          = -1;
 
Avatar of Chris Coyier
Chris Coyier on