Posted By

nerdfiles on 05/05/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

LeeRJohnson


CSS Setting


 / Published in: CSS
 

URL: http://carsonified.com/blog/design/setting-rather-than-resetting-default-styling/

  1. /* base.css | v0.2 (03282010) | Thierry Koblentz
  2.  *
  3.  * The purpose of this styles sheet is to set default styles for common browsers and address common issues (missing scrollbar, extended buttons in IE, gap below images, etc.)
  4.  *
  5.  * Changes in this version:
  6.  * - styling <pre> and <code> (see "Fixed Monospace Sizing")
  7.  * - styling <ol> inside <ul> (merci Goulven)
  8.  */
  9.  
  10. /* using height:100% on html and body allows to style containers with a 100% height
  11.  * the overflow declaration is to make sure there is a gutter for the scollbar in all browsers regardless of content
  12.  * note that there is no font-size declaration set in this rule. If you wish to include one, you should use font-size: 100.01% to prevent bugs in IE and Opera
  13.  */
  14. html {
  15. height: 100%;
  16. overflow-y: scroll;
  17. }
  18. /* not all browsers set white as the default background color
  19.  * color is set to create not too much contrast with the background color
  20.  * line-height is to ensure that text is legible enough (that there is enough space between the upper and lower line)
  21.  */
  22. body {
  23. height: 100%;
  24. background: #fff;
  25. color: #444;
  26. line-height: 1.4;
  27. }
  28.  
  29. /* this choice of font-family is supposed to render text the same across platforms
  30.  * letter-spacing makes the font a bit more legible
  31.  */
  32. body, input, button, textarea, select {
  33. font-family: "Palatino Linotype", Freeserif, serif;
  34. letter-spacing: .05em;
  35. }
  36. h1, h2, h3, h4, h5, h6 {
  37. font-family: Georgia, "DejaVu Serif", serif;
  38. letter-spacing: .1em;
  39. }
  40. pre, tt, code, kbd, samp, var {
  41. font-family: "Courier New", Courier, monospace;
  42. }
  43.  
  44. /* These should be self explanatory
  45.  */
  46. h1 {font-size: 1.5em;}
  47. h2 {font-size: 1.4em;}
  48. h3 {font-size: 1.3em;}
  49. h4 {font-size: 1.2em;}
  50. h5 {font-size: 1.1em;}
  51. h6 {font-size: 1em;}
  52.  
  53. h1, h2, h3, h4, h5 {font-weight: normal;}
  54.  
  55. /* styling for links and visited links as well as for links in a hovered, focus and active state
  56.  * make sure to keep these rules in that order, with :active being last
  57.  * text-decoration: none is to make the links more legible while they are in a hovered, focus or active state
  58.  * a:focus and :focus are used to help keyboard users, you may change their styling, but make sure to give users a visual clue of the element's state.
  59.  * outline:none used with the pseudo-class :active is to avoid the sticky outline when a user clicks on a link, but choose to not follow it
  60.  * note that the last rule does not do anything in IE as this browser does not support "outline" (besides, it treats :active and :focus the same)
  61.  */
  62. a:link {color: #000;}
  63. a:visited {text-decoration: none;}
  64. a:hover {text-decoration: none;}
  65. a:focus {text-decoration: none;}
  66. a:focus,:focus {outline: 1px dotted #000;}
  67. a:active {outline: none;}
  68.  
  69. /* margin and padding values are reset for all these elements
  70.  * you could remove from there elements you do not used in your documents, but I don't think it'd worth it
  71.  */
  72. body, p, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, blockquote, th, td {
  73. margin: 0;
  74. padding: 0;
  75. }
  76.  
  77. /* this is to prevent border from showing around fieldsets and images (i.e., images inside anchors)
  78.  */
  79. fieldset, img {
  80. border: 0;
  81. }
  82.  
  83. /* to prevent a gap from showing below images in some browsers
  84.  */
  85. img {vertical-align: bottom;}
  86.  
  87. /* Styling of list items
  88.  * This styles sheet contains a class to apply on lists to reset list-type and margin on LIs
  89.  */
  90. ol li,
  91. ul ol li {list-style-type: decimal;}
  92. ul li {list-style-type: disc;}
  93. ul ul li {list-style-type: circle;}
  94. ul ul ul li {list-style-type: square;}
  95. ol ol li {list-style-type: lower-alpha;}
  96. ol ol ol li {list-style-type: lower-roman;}
  97.  
  98. /* These should be self explanatory
  99.  * I believe *most* UAs style sub and sup like this by default so I am not sure there is value to include these rules here
  100.  */
  101. sub {
  102. vertical-align: sub;
  103. font-size: smaller;
  104. }
  105.  
  106. sup {
  107. vertical-align: super;
  108. font-size: smaller;
  109. }
  110.  
  111. /* color is to make that element stands out (see color set via body)
  112.  * padding is used so Internet Explorer does not cut-off descenders in letters like p, g, etc.)
  113.  */
  114. legend {
  115. color: #000;
  116. padding-bottom: .5em;
  117. }
  118.  
  119. /* according to Eric Meyer's reset: tables still need 'cellspacing="0"' in the markup
  120.  */
  121. table {
  122. border-collapse: collapse;
  123. border-spacing: 0;
  124. }
  125.  
  126. /* caption and summary are very important for tabular data but because caption is nearly impossible to style across browsers many authors do not use it or use display:none to "hide" it (which is almost the same as not using it).
  127.  * so to prevent such workaround, I am positioning this element off-screen
  128.  */
  129. caption {
  130. position: absolute;
  131. left: -999em;
  132. }
  133.  
  134. /* all th should be centered unless they are in tbody (table body)
  135.  */
  136. th {text-align: center;}
  137. tbody th {text-align: left;}
  138.  
  139. /* See Eric Meyer's article about Fixed Monospace Sizing
  140.  * http://meyerweb.com/eric/thoughts/2010/02/12/fixed-monospace-sizing/
  141.  */
  142. code {color: #06f;}
  143. code, pre {font-family: "Courier New", monospace, serif; font-size: 1em;}
  144.  
  145. /* This should be self explanatory
  146.  */
  147. blockquote, q, em, cite, dfn, i, cite, var, address {
  148. font-style: italic;
  149. }
  150.  
  151. /* to prevent some browsers from inserting quotes on "q" and "p" ("p" in blockquotes)
  152.  */
  153. blockquote p:before, blockquote p:after, q:before, q:after {content: '';}
  154.  
  155. /* These should be self explanatory
  156.  */
  157. th, strong, dt, b {
  158. font-weight: bold;
  159. }
  160.  
  161. ins {
  162. text-decoration: none;
  163. border-bottom: 3px double #333;
  164. }
  165.  
  166. del {text-decoration: line-through;}
  167.  
  168. abbr,
  169. acronym {
  170. border-bottom: 1px dotted #333;
  171. font-variant: normal;
  172. }
  173.  
  174. /* Creating white space (vertical gutters) via padding
  175.  * most authors do not set right/left padding or margin on these elements, they rather use an extra wrapper or style the container with padding to create the left and right gap/gutter they need
  176.  * I find that the latter creates less robust layouts because it leads authors to mix padding with width which creates issue with the broken box model (IE5 or IE6 in quirks mode)
  177.  * so imho, setting this style using the child combinator (i.e., div > h1) should be the best way to do it, but unfortunately IE 6 does not support such syntax, so I have to go with the following + a reset (see next rule)
  178.  */
  179. h1, h2, h3, h4, h5, h6, p, pre, ul, ol, dl, fieldset, address {padding:0 30px;}
  180.  
  181. /* this is to reset the left/right gaps (created by the previous and next rules) on nested elements
  182.  */
  183. dd p, dd pre, dd ul, dd ol, dd dl, li p, li pre, li ul, li ol, li dl, fieldset p, fieldset ul, fieldset ol {
  184. padding-right: 0;
  185. padding-left: 0;
  186. }
  187.  
  188. /* These should be self explanatory
  189.  */
  190. dd {
  191. padding-left: 20px;
  192. margin-top: .5em;
  193. }
  194.  
  195. li {margin-left:30px;}
  196.  
  197. /* we cannot use padding on a table to create left and right gaps (as we do with the elements above), instead we use margin
  198.  */
  199. table {
  200. margin-right: 30px;
  201. margin-left: 30px;
  202. }
  203.  
  204. /* we use margin for hr for the same reason we do for table
  205.  */
  206. hr {
  207. margin-right: 30px;
  208. margin-left: 30px;
  209. border-style: inset;
  210. border-width: 1px;
  211. }
  212.  
  213. /* top margin solution */
  214. /* this is my approach to create white space between elements, you do not have to adhere to it
  215.  * rather than stylling these elements with top and bottom margin, or simply bottom margin I only use top margin
  216.  */
  217. h1, h2, h3, h4, h5, h6, p, pre, dt, li, hr, legend, input, button, textarea, select, address, table {margin-top: 1.2em;}
  218.  
  219. /* top padding solution */
  220. /* this is a different approach which may be less frustrating for novice because it avoids running into collapsing margin and allows to clear floats while preserving space above the element
  221.  * if you decide to give this a try, then comment out the above rule and uncomment the two next ones
  222.  */
  223. /*
  224.  h1, h2, h3, h4, h5, h6, p, pre, dt, dd, li, legend, address {padding-top: 1.2em;}
  225.  hr, input, button, textarea, select, table {margin-top: 1.2em;}
  226.  */
  227.  
  228. /* form elements
  229.  * this should not affect the layout of the labels unless you style them in a way that padding applies
  230.  * if I include this here it is mostly because when labels are styled with float and clear, top padding creates a gap between labels (bottom margin would, but not top margin)
  231.  */
  232. label {padding-top: 1.2em;}
  233.  
  234. /* line height helps to set the vertical alignment of radio buttons and check boxes (remember to group these in fieldsets)
  235.  */
  236. fieldset {line-height: 1;}
  237.  
  238. /* vertical alignment of checkboxes (a different value is served to IE 7)
  239.  */
  240. input[type="checkbox"] {
  241. vertical-align: bottom;
  242. *vertical-align: baseline;
  243. }
  244.  
  245. /* vertical alignment of radio buttons
  246.  */
  247. input[type="radio"] {vertical-align: text-bottom;}
  248.  
  249. /* vertical alignment of input fields for IE 6
  250.  */
  251. input {_vertical-align: text-bottom;}
  252.  
  253. /* a specific font-size is set for these elements
  254.  */
  255. input, button, textarea, select, optgroup, option {
  256. font-size: .9em;
  257. }
  258.  
  259. /* this is to fix IE 6 and 7 which create extra right/left padding on buttons
  260.  * IMPORTANT: because IE 6 does not understand the first selector below, you need to apply the class "inputButton" to all input of type="button" in your documents
  261.  * the first declaration is for IE 6 and 7, the second one for IE 6 only, the third one is for all browsers.
  262.  */
  263. button,
  264. input[type="submit"],
  265. input[type="reset"],
  266. input[type="button"],
  267. .inputButton {
  268. *overflow: visible;
  269. _width: 0;
  270. padding: .2em .4em;
  271. }
  272.  
  273. /* classes
  274.  * to style elements with the default padding and margin we set on headings, paragraphs, lists, etc.
  275.  * for example, this class could be used on a DIV inside a blockquote or a DIV inside a FORM, etc.
  276.  */
  277. .block {
  278. padding: 0 30px;
  279. margin-top: 1.2em;
  280. }
  281.  
  282. /* to swap padding for margin
  283.  * for example, this class could be used on a heading you'd style with a bottom border
  284.  */
  285. .padding2margin {
  286. margin-right: 30px;
  287. margin-left: 30px;
  288. padding-right: 0;
  289. padding-left: 0;
  290. }
  291.  
  292. /* list items are styled by default with markers (disc, etc.) and left margin
  293.  * if you apply the class "noMarker" to a list, its items won't display markers and won't have left margin
  294.  */
  295. .noMarker li {
  296. list-style: none;
  297. margin-left: 0;
  298. }

Report this snippet  

You need to login to post a comment.