freedom - Premium WordPress Theme
$49.99

Freedom is a "one of its kind" premium theme that comes with a revolutionary "Theme Maker" (Also known as a Color Scheme Generator). This allows you to create your own color schemes using three basic colors (primary, secondary & tertiary). The theme includes a robust back-end options panel that lets you define all your settings of the theme without writing a word of code.

Wix.com

Dec
12

10 CSS Snippets to Save Precious Time

chickenstrip

Today, I have compiled a set of 10 CSS snippets that can save you a lot of time and effort. These codes are needed frequently when developing CSS-based websites or themes. Just bookmark these codes (Ctrl + D) so that you don’t have to look for them on the Internet every time.

1. CSS Tooltips

Through this code, you can have your own tooltips using just CSS. This is the CSS code :-

a:hover {background:#ffffff; text-decoration:none;} /*BG color is a must for IE6*/
a.tooltip span {display:none; padding:2px 3px; margin-left:8px; width:130px;}
a.tooltip:hover span{display:inline; position:absolute; background:#ffffff; border:1px solid #cccccc; color:#6c6c6c;}

Now, use the tooltips like this :-

Easy <a class="tooltip" href="#">Tooltip<span>This is the crazy little Easy Tooltip Text.</span></a>.

2. Eric Meyer’s Reset Code

HTML tags on different browsers have their own formatting and styling. To reset all that and bring everything to ground zero before starting to code, just add these lines at the beginning of your CSS file.

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	vertical-align: baseline;
	background: transparent;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}

3. Handy CSS Debugger

This code will add different color borders around your assets depending on its level. At each level in the hierarchy the color changes so you can see when “depth” changes. You can comment it out if you don’t need it.

* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }

4. Centering a DIV of Unknown Width

You can easily center a DIV by using margin:auto; property when you have mentioned its width in your CSS. But in case you wanted to center a DIV with unknown width, here is the code to do so :-

.content {
	margin: 0 auto 8px;
	display: table;
	}

.content div {
	display: table-cell;
	}

<!--[if IE]>
.content {
	display: block;
	text-align: center;
	}
.content div {
	display: inline;
	zoom: 1;
}
<![endif]-->

5. Adding AJAX style Loading Icon to Large Images

Instead of using any kind of JavaScript to add a loading icon before your large image is loaded, you can use this simple CSS technique. Just use the following class in the same DIV where you are calling the large image. Make sure the path to the small loading.gif is correct.

.loading { background: url(loading.gif) no-repeat center center; }

6. CSS Image Preloader

In case you need to preload images before the loading of your page completes, use the following technique. Just add the images’ paths to the DIV class, and call the DIV in your HTML. The DIV will not be visible but the images will preload nicely.

div.loader{
background:url(images/hover.gif) no-repeat;
background:url(images/hover2.gif) no-repeat;
background:url(images/hover3.gif) no-repeat;
margin-left:-10000px;
}

7. CSS Opacity Hack

You can set opacity of any asset by using the following codes (to achieve transparency) :-

selector {
filter: alpha(opacity=60); /* MSIE/PC */
-moz-opacity: 0.6; /* Mozilla 1.6 and older */
opacity: 0.6;
}

8. Min-Height for IE and all other browsers

Since min-height doesn’t work in IE, this code makes up for IE’s shortcomings. The first part of the code is the correct code that works in Firefox and Safari. The second part of the code is for IE. Internet Explorer will ignore min-height and is just given a height of 8em. The IE bug automatically expands the container to fit the extra text.

/* for browsers that don't suck */
.container {
  min-height:8em;
  height:auto !important;
}

/* for Internet Explorer - which of course sucks */
/*\*/
* html .container {
  height: 8em;
}
/**/

9. Styling Links by File Type

You can easily style specific URLs by using icons. This works only with CSS3 compatible browsers and degrades nicely with non-compatible browsers. Make sure to change the icon image paths.

/* external links */
a[href^="http://"]
{
padding-right: 13px;
background: url(external.gif) no-repeat center right;
}

/* emails */
a[href^="mailto:"]
{
padding-right: 20px;
background: url(email.png) no-repeat center right;
}

/* pdfs */
a[href$=".pdf"]
{
padding-right: 18px;
background: url(acrobat.png) no-repeat center right;
}

10. Remove Textarea Scrollbar in IE

IE has this nasty habit of showing a scrollbar in the textarea even when the content is inside the textarea. To avoid this, use the following code :-

textarea{
	overflow:auto;
}
This post was viewed 10,294 times

24 Comments to “10 CSS Snippets to Save Precious Time” | Leave a Comment!

  1. check up says:

    Thank you. Very useful bookmarked ! succesful article

  2. music says:

    Thank you. Very useful bookmarked !

  3. Naseer says:

    very informative…
    Thanks for share ….

  4. BlogSDN says:

    Gr8 tutorial i really liked it.

  5. irika says:

    Great list. I particularly like Eric Meyer’s Reset Code, which as you say brings everything back to ground zero. I plan to use this code regularly from now on.

  6. estetik says:

    Css a big way this information in the pages of our decorations’m sure will work.

  7. very nice usefull tip’s

    obrigado pelas dicas…

  8. IhateDesign says:

    Thanks for the snippets!!!

  9. Rick says:

    Love the cartoon too, by the way.

  10. denbagus says:

    nice css tutorial .thank you

  11. Nice list you have here. I particularly like the tooltip example – it makes creating your own fancy tooltip simpler.

    Thanks for sharing them

  12. Rick says:

    Great list. I particularly like Eric Meyer’s Reset Code, which as you say brings everything back to ground zero. I plan to use this code regularly from now on.

  13. I have to admit that a lot of these I didn’t even know about, but they are really great! I have always had trouble centering div’s and being able to change links based on their type of connection (http, ftp, mailto, etc) is really useful.

  14. Nice tips. will try the tips and of course bookmark it :)

  15. Jason says:

    Number nine is a good one. Thanks for sharing.

  16. Kubuntufrust says:

    Great. That are clear and easy to understand snippets. Good work.

  17. Chris says:

    Bookmarked the post as a reference. The comic was a scream! Thanks for sharing!

  18. Great snippets! I like the one about debugger.

  19. Positron says:

    Thanks for the tips. I used the ajax style loading image (5) It’s nice :)

  20. Aziz Light says:

    As a “list-style posts” hater, I have to say: this list is really, really cool. For the first time I actually learned a lot from a list-style post.

    Great job and thanks a lot.

  21. Kawsar Ali says:

    Very useful bookmarked !

  22. Jbcarey says:

    This is indeed very nice list. Good job.

  23. Syuxx says:

    Nice sharing there! Thanks for helping most of newbies coder to save their time. Haha
    :)


Websites that Link to this Post

  1. links for 2010-01-18 | Digital Rehab
  2. Heti események | I build websites
  3. Linkjes voor December 13th tot December 14th
  4. Napi okosságok – 2009/12/15 | Yloz féle zacc
  5. Notable Tech Posts – 2009.12.13 | The Life of Lew Ayotte

Leave a comment

Search :
Browse :
Archive :

$$$ Make Money $$$

Become an Affiliate

Welcome to Blog Oh! Blog's affiliate program! I personally invite you to make money by selling all of Blog Oh! Blog's Premium themes.

You will get a whopping 25% share on each sale generated through your affiliate link.

All you need to do is sign up as Blog Oh! Blog's affiliate, choose a banner, paste it on your website or blog and wait for sales to happen. It's as simple as that!

All affiliates will be paid on 10th of every month. Your affiliate earning needs to be a minimum $50 to get paid for each month.

Here is the sign up link and here are some banners to get you started!