Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 21-30 of 112 total

Blueprint CSS forms extension

Changes the widths of form elements so they fit into smaller columns created using the Blueprint CSS framework.

   1  div.span-1 input.text, div.span-1 input.title { width:  30px; }
   2  div.span-2 input.text, div.span-2 input.title { width:  50px; }
   3  div.span-3 input.text, div.span-3 input.title { width:  90px; }
   4  div.span-4 input.text, div.span-4 input.title { width: 130px; }
   5  div.span-5 input.text, div.span-5 input.title { width: 170px; }
   6  div.span-6 input.text, div.span-6 input.title { width: 210px; }
   7  div.span-7 input.text, div.span-7 input.title { width: 250px; }
   8  div.span-8 input.text, div.span-8 input.title { width: 290px; }
   9  
  10  div.span-1 select { width:  30px; }
  11  div.span-2 select { width:  50px; }
  12  div.span-3 select { width:  90px; }
  13  div.span-4 select { width: 130px; }
  14  div.span-5 select { width: 170px; }
  15  
  16  div.span-1  textarea { width:  30px; height:  25px; }
  17  div.span-2  textarea { width:  50px; height:  50px; }
  18  div.span-3  textarea { width:  90px; height:  75px; }
  19  div.span-4  textarea { width: 130px; height: 100px; }
  20  div.span-5  textarea { width: 170px; height: 125px; }
  21  div.span-6  textarea { width: 210px; height: 150px; }
  22  div.span-7  textarea { width: 250px; height: 175px; }
  23  div.span-8  textarea { width: 290px; height: 200px; }
  24  div.span-9  textarea { width: 330px; height: 225px; }
  25  div.span-10 textarea { width: 370px; height: 250px; }

Adding CSS style to buttons

This HTML and CSS code shows how to customise buttons in a restful way. Source: http://particletree.com/features/rediscovering-the-button-element/
   1  
   2  <div class="buttons">
   3      <button type="submit" class="positive">
   4          <img src="/images/icons/tick.png" alt=""/> 
   5          Save
   6      </button>
   7  
   8      <a href="/password/reset/">
   9          <img src="/images/icons/textfield_key.png" alt=""/> 
  10          Change Password
  11      </a>
  12  
  13      <a href="#" class="negative">
  14          <img src="/images/icons/cross.png" alt=""/>
  15          Cancel
  16      </a>
  17  </div>

   1  
   2  /* BUTTONS */
   3  
   4  .buttons a, .buttons button{
   5      display:block;
   6      float:left;
   7      margin:0 7px 0 0;
   8      background-color:#f5f5f5;
   9      border:1px solid #dedede;
  10      border-top:1px solid #eee;
  11      border-left:1px solid #eee;
  12  
  13      font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;
  14      font-size:100%;
  15      line-height:130%;
  16      text-decoration:none;
  17      font-weight:bold;
  18      color:#565656;
  19      cursor:pointer;
  20      padding:5px 10px 6px 7px; /* Links */
  21  }
  22  .buttons button{
  23      width:auto;
  24      overflow:visible;
  25      padding:4px 10px 3px 7px; /* IE6 */
  26  }
  27  .buttons button[type]{
  28      padding:5px 10px 5px 7px; /* Firefox */
  29      line-height:17px; /* Safari */
  30  }
  31  *:first-child+html button[type]{
  32      padding:4px 10px 3px 7px; /* IE7 */
  33  }
  34  .buttons button img, .buttons a img{
  35      margin:0 3px -3px 0 !important;
  36      padding:0;
  37      border:none;
  38      width:16px;
  39      height:16px;
  40  }

Adding colour to the buttons - Colour is used like a traffic light system, green for go (positive), red for stop (negative, think about this for a moment), and blue which isn't a traffic light (neutral, a miscellaneous item)
   1  
   2  /* STANDARD */
   3  
   4  button:hover, .buttons a:hover{
   5      background-color:#dff4ff;
   6      border:1px solid #c2e1ef;
   7      color:#336699;
   8  }
   9  .buttons a:active{
  10      background-color:#6299c5;
  11      border:1px solid #6299c5;
  12      color:#fff;
  13  }
  14  
  15  /* POSITIVE */
  16  
  17  button.positive, .buttons a.positive{
  18      color:#529214;
  19  }
  20  .buttons a.positive:hover, button.positive:hover{
  21      background-color:#E6EFC2;
  22      border:1px solid #C6D880;
  23      color:#529214;
  24  }
  25  .buttons a.positive:active{
  26      background-color:#529214;
  27      border:1px solid #529214;
  28      color:#fff;
  29  }
  30  
  31  /* NEGATIVE */
  32  
  33  .buttons a.negative, button.negative{
  34      color:#d12f19;
  35  }
  36  .buttons a.negative:hover, button.negative:hover{
  37      background:#fbe3e4;
  38      border:1px solid #fbc2c4;
  39      color:#d12f19;
  40  }
  41  .buttons a.negative:active{
  42      background-color:#d12f19;
  43      border:1px solid #d12f19;
  44      color:#fff;
  45  }

Embedded Fonts in Modules

How to use embedded fonts in modules and late-load the embedded font.
Save TrueType font file as ./Arial.ttf
   1  
   2  @font-face {
   3          src:url("./Arial.ttf");
   4          font-family: myFont;
   5  }
   6  
   7  Application
   8  {
   9  	font-family: 	myFont;
  10  	font-size: 	10px;
  11  }

Keeping the new contents of a growing list in view

The purpose of this code is to demonstrate how to keep the content at the bottom of a list always in view, similar to a chat window. Keywords: div, overflow, scroll, scrolltop. Reference: scrollTop Property http://snipr.com/1wdbn [msdn2.microsoft.com]

   1  
   2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   3    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   4  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   5    <head>
   6      <title>scrolling div</title>
   7      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
   8      
   9      <style type="text/css">
  10        <!--
  11        body {background-color: #43d;}
  12        div#list  {background-color: #4e8;  overflow: scroll; width: 15em; height: 10em;}
  13        p.other_user {background-color: #af5;}
  14        p {background-color: #ed3;}
  15        -->
  16      </style>
  17      <script type="text/javascript">
  18        function addText() {
  19          olist = document.getElementById('list');
  20          op = document.createElement('p');
  21          op.innerHTML = 'hi';
  22          ocontent = document.getElementById('content');
  23          ocontent.appendChild(op);
  24          olist.scrollTop = olist.scrollHeight;
  25        }
  26      </script>
  27    </head>
  28    <body>
  29      <div id="toolbar"><input type="button" value="add text" onclick="addText()" /></div>
  30      <p>A simple chat style display</p>
  31      <div id="list">
  32        <div id="content">
  33        <p class="other_user">Good <strong>afternoon</strong> how are you?</p>
  34        <p class="other_user">hello?</p>
  35        <p class="other_user">is anybody there?</p>
  36        </div>
  37      </div>    
  38    </body>
  39  </html>

iPhone Orientation

iPhoneOrientation
Demonstrates how to handle iPhone or iPod touch orientation events using HTML, CSS, and JavaScript.


index.html
   1  
   2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   3  <html xmlns="http://www.w3.org/1999/xhtml">
   4  <head>
   5  		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
   6  		<meta name="viewport" content="width=device-width, user-scalable=no" />
   7  		<title>Handling iPhone or iPod touch Orientation Events</title> 
   8  		
   9  		<!-- The iPhoneOrientation.css file is used to adjust the page appearance -->
  10  		<link rel="stylesheet" href="iPhoneOrientation.css" type="text/css" />
  11  		
  12  		<!-- The iPhoneOrientation.js file shows how to handle iPhone orientation events -->
  13  		<script type="text/javascript" src="iPhoneOrientation.js"></script>
  14  </head>
  15  <body class="portrait">
  16  		<!-- Display a message that describes the current iPhone orientation after rotation -->
  17  		<div id="currentOrientation"></div>
  18  
  19  		<!-- The container div is made of two inner divs: leftContainer and rightContainer. The leftContainer and rightContainer are stacked
  20  				 up one above the other when iPhone is in portrait orientation and side by side when iPhone is in landscape orientation -->
  21  		<div id="container">
  22  			<!--The button class is used to build a rounded rectangle around each text -->
  23  			<!--The page appearance changes whenever iPhone rotates between portrait and landscape display views -->
  24  			<div id="leftContainer">
  25  					<div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/chapter_10_section_1.html'">Debug Console</div>
  26  					<div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/chapter_4_section_8.html'">Viewport Settings</div>
  27  			</div>
  28  			<div id="rightContainer">
  29  					<div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/chapter_5_section_4.html'">Highlighting Elements</div>
  30  					<div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/DesigningForms/chapter_7_section_1.html'">Form Auto Correction</div>
  31  			</div>
  32  		</div>
  33  	
  34  </body>
  35  </html>




iPhoneOrientation.css
   1  
   2  body 
   3  {
   4  		margin: 0px;
   5  		padding: 0px;
   6  		font-size: 12px;
   7  		font-family: 'Lucida Grande', Verdana, sans-serif;
   8  		font-weight: bold;
   9  		/* Turn off font resizing */
  10  		-webkit-text-size-adjust: none;   
  11  }
  12  
  13  
  14  
  15  /* Set the background color of the page when the body tag's class attribute is equal to portrait. 
  16     The expression body[class="value"] is a CSS attribute selector where "body" is the html element to be styled, "class" the body's attribute to be
  17     manipulated, and "value" the class attribute's value, which is either portrait, landscapeLeft, or landscapeRight.
  18     This expression is used to dynamically select a body style according to the class attribute value. For instance, if the body's class attribute is set
  19     to landscapeLeft, then all style declarations matching body[class="landscapeLeft"] will be used to style "Handling iPhone or iPod touch Orientation Events". 
  20     The JavaScript updateOrientation function in the iPhoneOrientation.js file is used to set the body's class attribute to one of these values.
  21     Further information about CSS attribute selectors can be found at  http://www.w3.org/TR/css3-selectors/#attribute-selectors.
  22   */
  23  body[class="portrait"] 
  24  {
  25  		background: white;    	
  26  }
  27  
  28  
  29  /* Adjust a button when the body's class attribute is equal to portrait */
  30  body[class="portrait"] .button    
  31  {	
  32  		background: white;
  33  		width: 210px;
  34  		height: 13px;
  35  		
  36  		padding: 10px 0px;
  37  		margin: 10px auto;
  38  		
  39  		font-size: 15px;
  40  		
  41  		/* text is black on the button */
  42  		color: black;
  43  }
  44  
  45  
  46  /* The leftContainer and rightContainer div elements are stacked up one after the other when the body's class attribute is equal to portrait. 
  47     They are both 200 pixels wide. */
  48  body[class="portrait"] #leftContainer
  49  {
  50  		width: 200px;
  51  		margin: auto auto;
  52  }
  53  
  54  
  55  body[class="portrait"] #rightContainer
  56  {
  57  		width: 200px;
  58  		margin: auto auto;
  59  }
  60  
  61  
  62  /* Set the background color of the page when the body's class attribute is set to landscapeLeft */
  63  body[class="landscapeLeft"] 
  64  {
  65  		background: lightgrey;
  66  }
  67  
  68  
  69  /* Adjust a button when the body's class attribute is set to landscapeLeft */
  70  body[class="landscapeLeft"] .button  
  71  {
  72  		background: black;
  73  }
  74  
  75  
  76  /* The container div is evenly split between leftContainer and rightContainer when the body's class attribute is set to landscapeLeft.
  77     leftContainer and rightContainer are stacked side by side. leftContainer aligns buttons to the left side of the page; 
  78     rightContainer aligns buttons to the right side of the page. */
  79  body[class="landscapeLeft"] #leftContainer
  80  {
  81  		width: 50%;
  82  		/* Align the div to the left of the page  */
  83  		float: left;
  84  }
  85  
  86  
  87  body[class="landscapeLeft"] #rightContainer
  88  {
  89  		width: 50%;
  90  		/* Align the div to the right of the page  */
  91  		float: right;
  92  }
  93  
  94  
  95  
  96  /* Set the background color of the page when the body's class attribute is equal to landscapeRight */
  97  body[class="landscapeRight"] 
  98  {
  99  		background: tan;
 100  }
 101  
 102  
 103  /* Adjust a button when the body's class attribute is equal to landscapeRight */
 104  body[class="landscapeRight"] .button  
 105  {
 106  		background: darkred;
 107  }
 108  
 109  
 110  /* The container div is evenly split between leftContainer and rightContainer when the body's class attribute is set to landscapeRight.
 111     leftContainer aligns buttons to the left side of the page; rightContainer aligns buttons to the right side of the page. */
 112  body[class="landscapeRight"] #leftContainer
 113  {
 114  		width: 50%;
 115  		float: left;
 116  }
 117  
 118  body[class="landscapeRight"] #rightContainer
 119  {
 120  		width: 50%;
 121  		float: right;
 122  }
 123  
 124  
 125  /* Draw a rounded rectangle around a text */
 126   .button    
 127  {
 128  		font-weight: bold;
 129  		text-align: center;
 130  		
 131  		width: 130px;
 132  		height: 13px;
 133  		font-size: 10px;
 134  		
 135  		/* text is white on the button */
 136  		color: white;	
 137  	
 138  		/* Draw a rectangle around a text */
 139  		border: 1px solid black;    
 140  		
 141  		/* Round each corner of the generated rectangle */
 142  		-webkit-border-radius: 5px;   
 143  		padding: 5px 0px;
 144  		margin: 5px auto;
 145  }
 146  
 147  
 148  /* Defines styling properties for the currentOrientation div, which shows a message that indicates iPhone's current orientation after rotation */
 149  #currentOrientation
 150  {		
 151  		width: 280px;
 152  		text-align: center;
 153  		margin: 10px auto;
 154  }
 155  
 156  
 157  a
 158  {
 159  		text-decoration: none;
 160  }
 161  
 162  
 163  /* The container div contains four buttons that are evenly divided between the inner leftContainer and rightContainer div elements.
 164     Its width does not change when iPhone switches between portrait and landscape orientations. */
 165  #container
 166  {
 167  		/* fixed width across all iPhone orientation changes */
 168  		width: 300px;
 169  		margin: 10px auto;
 170  }




iPhoneOrientation.js
   1  
   2  /* updateOrientation checks the current orientation, sets the body's class attribute to portrait, landscapeLeft, or landscapeRight, 
   3     and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events".  */
   4  function updateOrientation()
   5  {
   6  	/*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
   7  	  left, or landscape mode with the screen turned to the right. */
   8  	var orientation=window.orientation;
   9  	switch(orientation)
  10  	{
  11  	
  12  		case 0:
  13  				/* If in portrait mode, sets the body's class attribute to portrait. Consequently, all style definitions matching the body[class="portrait"] declaration
  14  				   in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
  15  				document.body.setAttribute("class","portrait");
  16  				
  17  				/* Add a descriptive message on "Handling iPhone or iPod touch Orientation Events"  */
  18  				document.getElementById("currentOrientation").innerHTML="Now in portrait orientation (Home button on the bottom).";
  19  				break;	
  20  				
  21  		case 90:
  22  				/* If in landscape mode with the screen turned to the left, sets the body's class attribute to landscapeLeft. In this case, all style definitions matching the
  23  				   body[class="landscapeLeft"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
  24  				document.body.setAttribute("class","landscapeLeft");
  25  				
  26  				document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the left (Home button to the right).";
  27  				break;
  28  		
  29  		case -90:	
  30  				/* If in landscape mode with the screen turned to the right, sets the body's class attribute to landscapeRight. Here, all style definitions matching the 
  31  				   body[class="landscapeRight"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
  32  				document.body.setAttribute("class","landscapeRight");
  33  				
  34  				document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the right (Home button to the left).";
  35  				break;
  36  	}
  37  
  38  }
  39  
  40  // Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
  41  window.onorientationchange=updateOrientation;



Source: http://developer.apple.com/samplecode/iPhone/idxSafari-date.html
( AB-D )

Slashdot's 3 column liquid layout

The following html and css code is an example of a 3 column liquid layout used on the front page of http://slashdot.org. What's interesting is that the left and right column do not change their widths, it's only the article content which changes.

   1  
   2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   3              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   4  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   5  <head>
   6    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   7    <title>Aenean: ullamcorper elementum, dui quam porttitor neque</title>
   8    <link rel="stylesheet" type="text/css" media="screen" href="core-tidied.css" />
   9  
  10  </head>
  11  <body>
  12  <div id="frame">
  13    <div id="topnav">
  14      <div id="logo">
  15        <h1>
  16          <a href="//aenean.org">Aenean</a>
  17        </h1>
  18      </div>
  19    </div> 
  20    <div id="slogan">
  21      <h2>
  22        ullamcorper elementum, dui quam porttitor neque
  23      </h2>
  24    </div>
  25    <div id="wrapper">
  26      <div id="links">
  27        <div class="block" id="links-sections">
  28          <div class="title" id="links-sections-title">
  29            <h4>
  30                    hendrerit
  31            </h4>
  32          </div>
  33          <div class="content" id="links-sections-content">
  34            <ul>
  35            <li>suscipit</li>
  36            </ul>
  37          </div>
  38        </div>
  39      </div>
  40      <div id="contents">
  41        <div id="slashboxes">	
  42          <div class="block">
  43            <div class="title" id="index_qlinks-title">
  44              <h4>
  45                      Vestibulum
  46              </h4>
  47            </div>
  48            <div class="content" id="index_qlinks-content">
  49              <p>egestas quam </p>
  50            </div>
  51          </div>
  52        </div>
  53        <div id="articles">
  54          <div class="article" id="art1">
  55            <p>
  56            Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec tincidunt porttitor felis. Sed a tellus in lacus adipiscing tincidunt. Ut sollicitudin auctor dolor. Maecenas orci. Fusce porttitor odio eget erat. Aliquam erat volutpat. Fusce mollis, orci eget ullamcorper elementum, dui quam porttitor neque, euismod pulvinar risus turpis nec neque. Maecenas dolor risus, vestibulum in, congue a, pulvinar id, leo. Vestibulum porttitor hendrerit mauris. Morbi fringilla lectus quis orci. Vivamus laoreet massa scelerisque felis.
  57            </p>
  58  
  59            <p>
  60            Aenean nunc neque, euismod porta, tempor ut, eleifend at, massa. Nam tempor urna at ligula. Etiam auctor dui tempus odio egestas sagittis. Donec metus pede, tempor nec, tincidunt sit amet, consectetuer eget, massa. Nam dolor arcu, ornare et, imperdiet vel, euismod ut, nibh. Quisque ut erat. Maecenas ante urna, suscipit eget, dictum non, porttitor at, magna. Duis accumsan. Suspendisse luctus vehicula pede. Mauris a nisl. Cras leo.
  61            </p>
  62          </div>
  63        </div>
  64      </div>	
  65    </div>
  66    <div id="footer">
  67      Ut sollicitudin auctor dolor. Maecenas orci. 
  68    </div>	
  69  </div>
  70  
  71  </body>
  72  </html>


   1  
   2  
   3  /* file: core-tidied.css */
   4  body {
   5    min-width: 680px;
   6    color: #111;
   7    background: #222;
   8  }
   9  
  10  #contents p {
  11    background-color: #eee;
  12  }
  13  
  14  #topnav {
  15    background: #044;
  16    position: relative;
  17    height: 55px;
  18    margin: 5px 1.25em 0 1.25em;
  19  }
  20  
  21    #topnav #logo {
  22      width: 415px;
  23      height: 100%;
  24    }
  25    #topnav #logo h1 {
  26      display: block;
  27      height: 100%;
  28      width: 100%;
  29    }
  30      #topnav #logo h1 a {
  31        display: block;
  32        width: 100%;
  33        height: 100%;
  34        outline: none;
  35        text-indent: -5000px;
  36        text-decoration: none;
  37        background: url(//images.slashdot.org/logo.png) no-repeat left top;
  38      }
  39    
  40  #slogan{ display: none; }
  41  
  42  /* Wrapper */
  43  #wrapper {
  44    overflow: hidden;
  45    background-color: #fff;
  46  }
  47  
  48  #wrapper #articles { margin-right: 18.5em; }
  49  
  50  /* User section menu */
  51  /* Contents */
  52  #contents {
  53    width: auto;
  54    margin-left: 10.5em;
  55  }
  56  
  57  /* General Body */
  58  
  59  /* Blocks */
  60  div.block div.title { background: #666 }
  61    div.block div.title h4 {
  62      color: #fff;
  63    }
  64  
  65  
  66  /* Links (left sidebar) */
  67  div#links {
  68    float: left;
  69    width: 9.25em;
  70    background: #eee;
  71  }
  72      div#links div.block div.content ul li {  list-style-image: none; }
  73  
  74  /* Slashboxes (right sidebar) */
  75  div#slashboxes {
  76    float: right;
  77    width: 17.25em;
  78  }
  79  
  80  /* Footer */
  81  div#footer {
  82    background: #bbb;
  83    clear: both;
  84  }
  85  
  86  #contents {margin-top: 2em;}


The secret to positioning the columns, is to use left and right margins to push the element (column being adjusted), away from it's siblings. In the above example the contents (outer box) is pushed away from the left (#contents { margin-left: 10.5em;}), and the articles (inner box) within the contents is pushed from the right (#wrapper #articles { margin-right: 18.5em; }).

ie6,ie7 hack

// description of your code here

   1  
   2  #MyDiv {
   3  margin : 10px 10px 10px 10px;
   4  }
   5  
   6  /* IE6 Only */
   7  * html #MyDiv {
   8  margin : 5px 5px 5px 5px;
   9  }
  10  
  11  /* IE7 Only */
  12  *:first-child+html #MyDiv {
  13  margin : 2px 2px 2px 2px;
  14  }

Starting with CSS-based design

// description of your code here
// =INITIAL
// v2.1, by Faruk Ates - www.kurafire.net
// Addendum by Robert Nyman - www.robertnyman.com

// Neutralize styling:
// Elements we want to clean out entirely:
   1  
   2  
   3  html, body, form, fieldset {
   4  	margin: 0;
   5  	padding: 0;
   6  	font: 100%/120% Verdana, Arial, Helvetica, sans-serif;
   7  }
   8  
   9  /* Neutralize styling: 
  10     Elements with a vertical margin: */
  11  h1, h2, h3, h4, h5, h6, p, pre,
  12  blockquote, ul, ol, dl, address {
  13  	margin: 1em 0;
  14  	padding: 0;
  15  }
  16  
  17  /* Apply left margin:
  18     Only to the few elements that need it: */
  19  li, dd, blockquote {
  20  	margin-left: 1em;
  21  }
  22  
  23  /* Miscellaneous conveniences: */
  24  form label {
  25  	cursor: pointer;
  26  }
  27  fieldset {
  28  	border: none;
  29  }
  30  
  31  /* Form field text-scaling */
  32  input, select, textarea {
  33  	font-size: 100%;
  34  }
  35  
  36  /* link underlines tend to make hypertext less readable, 
  37     because underlines obscure the shapes of the lower halves of words */
  38  :link,:visited { text-decoration:none }
  39  /* no list-markers by default, since lists are used more often for semantics */
  40  ul,ol { list-style:none }
  41  /* whoever thought blue linked image borders were a good idea? */
  42  a img,:link img,:visited img { border:none }
  43  
  44  /* de-italicize address */
  45  address { font-style:normal }

View all colors from a set of stylesheets

Rake task to grep out colors from a set of CSS stylesheets and display them on a web page. Default configuration works for OS X Safari and a Rails application.

   1  
   2  BROWSER = "/Applications/Safari.app/Contents/MacOS/Safari"
   3  CSS_FILES = "#{RAILS_ROOT}/public/stylesheets/**/*.css"
   4  
   5  task :colors do
   6    require "tempfile"
   7    colors = Dir[CSS_FILES].map(&File.method(:read)).join.scan(/\#[0-9a-f]{3,6}/i).map{|c| c.upcase}.uniq
   8    Tempfile.open "colors" do |f|
   9      f.write <<-EOHTML
  10      <html>
  11        <head>
  12          <style type="text/css">
  13            div { width: 50px; height: 50px; display: inline-block }
  14          </style>
  15        </head>
  16        <body>
  17          #{colors.map{|clr| 
  18            "<div style='background: #{clr}'>&nbsp;</div> #{clr} <br />"
  19          }.join}
  20        </body>
  21      </html>
  22      EOHTML
  23      system BROWSER, f.path
  24    end
  25  end

CSS include

Import the contents of an existing CSS file into your current CSS

   1  
   2  @import "general.css";
« Newer Snippets
Older Snippets »
Showing 21-30 of 112 total