Adding code snippets to your blog entries

Carl discovers the world

  • RSS Feed
  • Login
  • Contact
Ning Themes
Skins 4 Ning, CSS tips, PHP hacks, howto's and theme doc's
Keyword Elite
I use Keyword Elite to find profitable
niches for my online business
Serendipity Directory
Add your site to the Serendipity
Users Directory
Welcome
Herzlich Willkommen


Hi, Welcome to my site, please bookmark me, and feel free to comment on my posts
  • Home
  • About
  • Serendipity
  • Blogger
  • Wordpress
 

Tuesday, May 2. 2006

Adding code snippets to your blog entries

Select language: German, English
Regular visitors to my site will know I often include code snippets in my posts. To refresh your memory on html in your entries be sure to read adding html code to your blog entries

Including html in your posts isn't something you need to do very often, and certainly can't damage your blog, so please feel free to experiment. If you're familiar with HTML basics you would know that the <code> tag is available to be used for code snippets within webpages, and this is equally true of blog posts.

Where it gets interesting is that actually putting any html into your post will automatically be interpreted by your browser. So lets say for example you wanted to include a code snippet that your site visitors could use to link to your website. If you actually place the direct html into your post you'll notice that your browser makes this into a link, and not into a code snippet.
The solution is to use ascii characters instead of the actual character, let me show you what I mean;

This is the code to make a link;

<a href="#">my link</a>

and if I type that directly into my post I get my link, so to actually get it to display as a code snippet I need to place the following into my post instead;

&lt;code&gt;
&lt;a href="#"&gt;my link&lt;/a&gt;
&lt;/code&gt;

The &lt; and &gt; are the ascii codes used to create the < and > seen in my code snippets.

Finally, many templates don't include the code tag in their stylesheets, which means you are relying on the default style used by your browser, or worse, the site visitors browser. You could override this by creating your own style like the following;

code {
display:block;
font-size:1.2em;
padding:5px 15px;
border:1px solid #ddd;
background-color:#efefef; }

Which would give you a code snippet that looks like this;
code {
display:block;
font-size:1.2em;
padding:5px 15px;
border:1px solid #ddd;
background-color:#efefef; }

Hope this helps you with your own blog or website.
If you enjoyed this post, make sure you subscribe to my RSS feed.
Posted by Carl in Basic html/css at 14:03   Comments (0)
Defined tags for this entry: bloggertechnorati, bloggingtechnorati, csstechnorati, htmltechnorati, serendipitytechnorati, templatestechnorati
Related entries by tags:
Blogspot users, enable comments for all
SEO using Social Bookmarking Type Sites
Add This Bookmark and Share Widget Code for Serendipity Templates


Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments

    No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
 
Submitted comments will be subject to moderation before being displayed.
 
 

Categories

  • Blogger
  • Blogger Templates
  • Carl's Journal
  • Writing Resources
  • Christmas
  • Humanity
  • Italian
  • Ning Templates
  • Palm z22
  • Science/Nature
  • Technology
  • Screencasting
  • SEO, Traffic
  • Serendipity Blog
  • Basic html/css
  • Download Themes
  • Theming Serendipity
  • Using Serendipity
  • Small Business
  • Spain
  • Spanish
  • Travel
  • Wordpress
  • Xampp WebServer

All categories




U COMMENT
I FOLLOW






My Feedburner Feed
Subscribe to my Feedburner

© 2005-7 Carl Galloway.Template by Carl, artwork by Pixabella. Valid XHTML, CSS