One Line CSS Magic

Pin It


No need to mention CSS is awesome. Its pure beauty of CSS that gives life to the website and makes it lively. Yes, it’s not simple to write CSS for newbie and even professionals sometimes gets stuck because of cross browser issues. Sometimes, One line in CSS can be more than a magic providing solutions. I reviewed some of the CSS files and came up with some one line CSS.

Below are list of one line CSS. One line CSS mentioned below may or may validate web standards and web accessibility rules.

1. Set default margin and padding to all elements

* {margin: 0; padding: 0}

Every element that have not assigned margin or padding will have default value of above.
Some CSS designers argue that this is not necessary at all because all CSS element at the end will have their assigned value.

2. Set image border to zero

img, a img { border: 0; }

This can be used to prevent any linked images from displaying borders.

3. Remove Firefox’s link border

a:active, a:focus { outline: 0; }

This removes dotted outline from focused or active links on firefox.

4. Scrolling Render IE

html { background : url(null) fixed no-repeat; }

5. Prevent line breaks in links, over sized content to break

a{ white-space:nowrap;}
element { overflow:hidden; }

This trick prevents line breaks on links.

6. Centering block elements horizontally

element { margin:0 auto; }

This one line CSS horizontally centers a block level element.

For IE less than 7, following line should be added though.

element { text-align: center; }

7. Show Firefox scrollbar

html{ overflow:-moz-scrollbars-vertical; }

8. Remove textarea scrollbar in IE

textarea{ overflow:auto; }

8 total comments on this postSubmit yours
  1. Good one. Thanks for the tips.

  2. while i disagree on some of the other tips, #3 is quite ‘regretable’ … it’s 2008 ;)

  3. hm, most of these tips look very familiar to me…

  4. alen, yep few points matches

  5. Good tips! Solves many problems!
    Thanks!

  6. great tips. I have been using many of them for a while now, but #7 is news to me. Thanks.

  7. css lessons – css scrollbar examples code
    http://css-lessons.ucoz.com/scroll-css-examples.htm

  8. Great Tips! Great Tips! Wish i could find this site sooner – your tip to remove ff boarder on links works great! And i’ve added your boarder pics code too. A++ Cheers.

7 total pingbacks on this post
Submit your comment

Please enter your name

Your name is required

Please enter a valid email address

An email address is required

Please enter your message

Twitter

  • May 2, 2012 04:15

    10 Free WordPress Theme To Make You Forget About Premium Theme http://t.co/YRiLCiVa

  • March 2, 2012 17:16

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/FY0jh8Dn

  • March 2, 2012 16:43

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/QUlYKInf #IE #FF #Chrome #Testing #CrossBrowser

  • March 2, 2012 12:52

    Top 5 Plugins to Build Contact Form for WordPress http://t.co/PWyR08Iq #WordPress #Plugins #ContactForm

  • June 11, 2011 02:49

    CSS 3 Transitions http://bit.ly/m0pK3t

Design Gala © 2012 All Rights Reserved

Designed by 76miles

Powered by WordPress

More in CSS (14 of 15 articles)