Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 9
There are 1 users currently browsing forums.
HTML & CSS Articles Read and post HTML and CSS tutorials.

Reply
  #1  
Old 05-25-2006
Forum Administrator
 
Join Date: Mar 2006
Location: Toronto, Ontario
Posts: 2,396
Rep Power: 7
Nick Presta is on a distinguished road
Collection of CSS tricks

HTML Code:
/* 
	These CSS Selectors will match links that are files. 
	The first example will match a link that ends ($) in .pdf and the places (PDF) after.
*/

/* Examples */
a[href$='.pdf']:after { content: " (PDF)"; }
a[href$='.doc']:after { content: " (MS Word)"; }
a[href$='.xls']:after { content: " (Excel)"; }

/* General Formatting */
a[href]:after { 
padding: 3px; 
display: inline; 
vertical-align: middle; 
background: transparent; 
}
This will only work in browsers that support CSS2(.1). These browsers include Konqueror (KDE 3.5.2), Opera 9, and Firefox 1.5+ and the latest version of Safari. It isn't required for things to work but it is helpful and neat for browsers that support it so you can include it without fear of breaking other browsers.

HTML Code:
/*
	Displays the quoted source inside the blockquote (only when it contains a cite attribute) automatically.
	Can be customized. Uses attr(cite) to grab the cite attribute.
*/

blockquote[cite]:after { 
	margin: 1em 0 0 0; 
	font-size: 0.8em; 
	display: block; 
	padding: 0.5em 0 0 0; 
	font-weight: bold; 
	border-top: 1px solid #000; 
	color: #000;  
	content: "Quote from: " attr(cite);
}
Again, CSS2 is needed here. This won't break browsers that don't have CSS2 but for browsers that do, this is helpful. Instead of hardcoding the cite or using Javascript, you could implement a CSS solution. Opera, Konqueror, Firefox and the latest version of Safari.

HTML Code:
h2[id]:hover::after {
content: " #"attr(id);
}
This is useful when you provide anchors to sections of your page but want to show others what the anchor is called. You can style the generated content any way you like to make it obvious. This works with browsers that support CSS2 and content generation.

HTML Code:
/*
	This will append the link IRI after the link itself and place it inside round brackets (parenthesis).
	Will match any links that do not begind (^) with the pound sign (#) as those are for anchors
*/

@media print {
	a:not([href^='#']):after { background: transparent; padding:3px; content:" ( " attr(href) " ) "; }
}
This is for print media (when you're printing a page, usually). It is good for factual articles that have a lot of quotes to other sites. This CSS will add the link URL (when the HREF attribute is not equal to # meaning it's an anchor) after the link and put brackets around it. Again, good for browsers that support it (Currently only FF 1.5+, I believe) and doesn't hurt browsers that don't support it.

HTML Code:
/*
     This will automatically number your headings. Great for books or manuals.
*/

h2 { content: counter(section); counter-increment: section; }
h2:before { content: "Chapter "counter(section)": ";  }
This requires the use of the :before pseudo-selector, counters and content property. Firefox 1.5+ and Opera 9+, etc should handle this fine.
You can see an example of this here:
http://nickpresta.ath.cx/old/h1_before_content.html

Last edited by Nick Presta; 05-26-2006 at 06:59 PM.
Reply With Quote
  #2  
Old 05-25-2006
unclekyky's Avatar
Jovially Avuncular
 
Join Date: Sep 2004
Age: 20
Posts: 5,889
Rep Power: 12
unclekyky is on a distinguished road
Re: Collection of CSS tricks

Thanks. I've been meaning to look into this semi-new CSS stuff for awhile, but never got around to it.

Keep adding to the list!
Reply With Quote
  #3  
Old 05-25-2006
Forum Administrator
 
Join Date: Mar 2006
Location: Toronto, Ontario
Posts: 2,396
Rep Power: 7
Nick Presta is on a distinguished road
Re: Collection of CSS tricks

I will. This is older stuff that I've had sitting around for a while. There are tons of awesome things you can do with selectors.
Reply With Quote
  #4  
Old 05-26-2006
paran's Avatar
Just a "Little" Kid
 
Join Date: Mar 2006
Location: In a box.
Posts: 69
Rep Power: 5
paran is on a distinguished road
Re: Collection of CSS tricks

nice job Nick. wow, these tricks are awesome. Never knew you could accomplish so much with just CSS. Thanks
Reply With Quote
  #5  
Old 05-26-2006
Forum Administrator
 
Join Date: Mar 2006
Location: Toronto, Ontario
Posts: 2,396
Rep Power: 7
Nick Presta is on a distinguished road
Re: Collection of CSS tricks

You can do even more but with the lack of CSS support they aren't too practical.

If you want, I can post some CSS2.1/3 stuff that is really neat...
Reply With Quote
  #6  
Old 05-26-2006
unclekyky's Avatar
Jovially Avuncular
 
Join Date: Sep 2004
Age: 20
Posts: 5,889
Rep Power: 12
unclekyky is on a distinguished road
Re: Collection of CSS tricks

All I can say is: Do it.
Reply With Quote
  #7  
Old 05-26-2006
Mau Mau is offline
A friend
 
Join Date: Jun 2005
Location: California, USA
Age: 20
Posts: 2,956
Rep Power: 8
Mau is on a distinguished road
Re: Collection of CSS tricks

Nice tutorial -- I learned some things! Perhaps put this on the wiki?
Reply With Quote
  #8  
Old 05-26-2006
Forum Administrator
 
Join Date: Mar 2006
Location: Toronto, Ontario
Posts: 2,396
Rep Power: 7
Nick Presta is on a distinguished road
Re: Collection of CSS tricks

Updated. And sure, I'll add some of these and an example (as well as tests) of CSS 2/3 selectors and such.
Reply With Quote
  #9  
Old 05-28-2006
Err... Bean, Mister Bean
 
Join Date: Jul 2005
Location: Derbyshire, UK
Age: 18
Posts: 2,320
Rep Power: 8
sirjavabean is on a distinguished road
Re: Collection of CSS tricks

I can't wait until "real" CSS gets proper adoption in all major browsers. That day will be sweeeet
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to vertically align text in a <div> tag using CSS... HELP!!!!!! DRIVING ME INSANE Makaveli HTML/CSS Coding 10 02-11-2006 04:34 PM
New CSS Design n0x Site Reviews & Site Management 3 07-24-2005 12:50 AM
CSS Themes Question. Ben H HTML/CSS Coding 4 07-05-2005 12:29 PM
Cool CSS Tricks Ebene HTML/CSS Coding 6 06-10-2005 02:15 PM