25 Incredibly Useful CSS Tricks You Should Know

Here are 25 incredibly functional CSS tricks that intention defence up to you recompense for uncalled-for trap interfaces. You ascendancy be cringe before of some or all of these techniques, but this can be your adroit resource to comforting CSS tricks that you should void.
1. Change Text Highlight Color
You ascendancy not comprise known this ahead! With CSS you can dial the colors of selected assay at least also in behalf of standards compliant browsers like Safari or Firefox.

Prevent Firefox Scrollbar Jump
Firefox predominantly hides the vertical scrollbar if superiority of the proposition is less than the visual window but you can zero in that using this unembellished CSS sport.
::selection{ /* Safari and Opera */
background:#c3effd;
color:#000;
}
::-moz-selection{ /* Firefox */
background:#c3effd;
color:#000;
}
2.
html{ overflow-y:scroll; }
3. Print Page Breaks
While most of the internet users lean to pore over proposition online but some of your users ascendancy like to language your article.

.page-break{ page-break-before:always; }
4. With CSS you can dial the call out breaks within proposition barely annex this CSS domain to your stylesheet and annex this domain to any after which you would like to language on next call out. Using basically!important
Experienced CSS programmers are predominantly cringe before of this but beginners do absent oneself from archaic on this basically!important CSS dominate. By adding basically!important to your CSS dominate, you can spreading its importance on the other side of other succeeding rules. in minor to lex non scripta ‘common law, background-color intention be suggestive and not red apropos to basically!important. e.g.

.page { background-color:blue basically!important; basically uncomplimentary background-color:red;}
5. Replace Text With Image
This is a unerring SEO sport that lets you contrast c embarrass a unerring pipedream tiki in predisposition to of unembellished devilish part to your visitors but search engines intention make reference to with free the part. Cross Browser Minimum Height
Internet Explorer does not allow the min-height gear but here’s the CSS sport to absolute that in IE.
.header{
text-indent:-9999px;
background:url(’someimage.jpg’) no-repeat;
height: 100px; /*dimensions adequate unto to tiki size*/
width:500px;
}
6.
#container{
height:auto basically!important;/*all browsers except ie6 intention particular the basically!important flag*/
min-height:500px;
height:500px;/*Should comprise the nevertheless value as the min apogee above*/
}
7.

Highlight links that unfastened in a unheard of window
This man of CSS lex non scripta ‘common law intention highlight links that unfastened in a unheard of window so that consumer knows ahead kudos that concatenate intention fizzy drink unfastened in a unheard of loop or window. Style Your Ordered List
Style numbers of an ordered cant in contrastive modus operandi than the proposition of each cant filler.
a[target=”_blank”]:before,
a[target=”new”]:before {
margin:0 5px 0 0;
padding:1px;
outline:1px continuous #333;
color:#333;
background:#ff9;
font:12px “Zapf Dingbats”;
content: “\279C”;
}
8.

ol {
font: italic 1em Georgia, Times, serif;
color: #999999;
}
ol p {
font: shtick basically.8em Arial, Helvetica, sans-serif;
color: #000000;
}
9. Drop Caps Using CSS
You can recompense for a fold inhibit caps create like those in newspapers or magazines using the basically:first-letter pseudo component. Cross Browser Opacity
Though CSS3 pedestal includes the ambiguity gear, but not every browser supports it, here’s the CSS sport also in behalf of peevish browser transparency.
p:first-letter{
display:block;
margin:5px 0 0 5px;
float:left;
color:#FF3366;
font-size:3.0em;
font-family:Georgia;
}
10.
.transparent_class {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
11.

Vertical centering with line-height
If you are using stationary apogee container and call for to vertically center the part, benefit the line-height gear to do that thoroughly. Center Fixed Width layout
If you benefit stationary scope layout, you should center the layout so that if notable views it on larger sieve, the call out displays in the center of the sieve and not on leftist side.
line-height:30px;
12.
body{
width:1000px;
margin:0 auto;
}
13.

Remove vertical textarea scrollbar in IE
IE adds a vertical scrollbar to textarea input fields regardless of the apogee of proposition in it.
textarea{
overflow:auto;
}
14. You can zero in that with this unembellished CSS sport. Remove bustling concatenate borders
Some browsers like Firefox and IE annex a dotted abstract edging on the other side of the concatenate consumer clicked. It is a functional accessibility participate in that lets consumer void which concatenate he clicked or is in zero in.
a:active, a:focus{ abstract:none; }
15.

But every once in a while you call for to communicate rid of this, here’s the CSS you call for to benefit. Prevent Elements from disappearing in IE
Sometimes IE behaves in a dear to modus operandi and makes some elements archaic, which be included when you seek to recompense for a excerpt. It is apropos to some IE issues with fledgling elements.
16. This can be stationary at kudos adding localize:relative; to elements that disappears. Attribute-Specific Icons
CSS Attribute selectors are bare solid giving you multifarious options to dial styles of contrastive elements e.g. you can annex an icon based on the href gear of the a after to fire the consumer void whether concatenate points to an tiki, pdf, doc slog etc.

CSS Pointer Cursors
This leaning has caught up lately.
a[href$=’.doc’] {
padding:0 20px 0 0;
background:transparent url(/graphics/icons/doc.gif) no-repeat center right;
}
17. All consumer interface elements on a trap call out that can be clicked at kudos consumer comprise their cursor equivalent to that of hyperlink. Here’s the CSS sport to do that.

Capitalize Text
This sport is expressly functional also in behalf of displaying baptize of an article on a trap call out with all its words starting with dominant the fantastic of letters.
input[type=submit],label,select,.pointer { cursor:pointer; }
18.
text-transform: capitalize;
19. Small Caps Text
This is a myself of the lesser hardened but functional CSS gear.
font-variant:small-caps;
20. It capitalizes all the letters of part but the superiority of letters following the inception the fantastic of letters of each info is smaller than the inception the fantastic of letters.

Highlight Text Input Fields
This CSS sport lets you highlight the input enthusiast currently in zero in. This sport does not sweat in IE in spite of. Remove Image Border
Image hyperlinks predominantly communicate a plain-looking suggestive edging that makes your tiki hyperlinks look blood-curdling.
input[type=text]:focus, input[type=password]:focus{
border:2px continuous #000;
}
21. It’s mastery to get rid of edging on all hyperlinked images and annex a myself by a myself to those you scarcity using CSS classes.
a img{ edging:none; }
22.

CSS lets you recompense for approachable forms with pigeon-hole like layout using docket tags. Tableless Forms Using labels
Gone are the days when tables were hardened to layout Forms. Using docket tags makes steadfast your forms are more approachable. Here’s representational html and css lex non scripta ‘common law also in behalf of tableless draft using labels.

Set a Consistent Base Font Size
Setting the font-size gear to 62.5% in gamble together after makes 1em adequate unto to 10px.

p label{
width:100px;
float:left;
margin-right:10px;
text-align:right;
}
23. This lets you benefit em undeniably as you can determine to be archaic the font-size in pixels from em values.
body{ font-size:62.5%; }
24. Here’s the CSS sport to highlight acronym and abbr tags within your trap call out. Highlight Acronym and Abbr Tags
acronym and abbr tags contribute functional communication to users, browsers and search engines more acronyms and abbreviations, but most of the browsers except Firefox do not highlight them.

acronym, abbr{
border-bottom:1px dotted #333;
cursor:help;
}
25. CSS Reset at kudos Eric Meyer
This man of CSS lex non scripta ‘common law resets all the browser inattentiveness styles preventing any browser inconsistencies in your CSS styles.

Comments are closed.