Gravatar

Geoff Evason

Posts Tagged ‘css’

My Blog Theme Packaged As A WordPress Theme

Monday, May 12th, 2008

I’ve made my blog theme into a wordpress theme that others can now use. It’s packaged as a zip file which you can download here. If you aren’t familiar with wordpress themes, here is how you install a wordpress theme

The downloadable theme has 3 color variations. You’ll need to know the basics of CSS in order to change the color. Just edit the styles.css file to uncomment the color section you want.

If you want to add your own background, here is a great article on simple web design from scratch (which is where I got the idea for my theme)

How To Get Code Syntax Highlighting on Your Blog

Friday, May 2nd, 2008

So, I’ve just recently updated the look and feel of my blog. I previously had a few blogs that I managed and I wanted to consolidate things into one place.

I looked into using some Rails CMSs (radiant, mephisto) but ultimately decided on using wordpress. I really do think Wordpress is the best tool for the job, and it has a great community and lots of plugins!

Anyway, back to the topic at hand. I’ve seen a bunch of blog posts with cool syntax highlighting. I hadn’t been able to figure out how to do it (until I looked at the markup for Tim Lucas’s site).

There are a few Wordpress plugins that let you do this, but none of them really struck me as being what I wanted. After investigating further I found code_highlighter.js by Dan Webb.

Apparently some code highlighters do work on the server side, where as this javascript file moves the work to the client. The idea of this code highlighter is simple. Just include the main code_highlighter.js script and any of the other 4 supported languge packs that you want to use (html, css, js, ruby). I personally just merged the 4 language packs into the main file so I only had one include.

If you are using wordpress, you need to upload the js file somwhere. The nature place is to create a scripts folder in your wordpress root folder. Or, you can create a scripts folder in your theme folder and include it like this:


<script type=“text/javascript” src="wp-content/themes/geoff/js/code_highlighter.js"></script>

I did the latter so that it’s nice and packaged within my theme.

The next step is to style it (which is easy to do using css). Here’s the css I use:


/* Code highlighting (derived from) VibrantInk colours from Justin Palmer @ http://encytemedia.com
*/

 pre {
   padding: 10px;
   overflow: auto;
   width: 100%;
 }
 pre, code {   background-color: #111; }

 /** RUBY / JAVASCRIPT **/
 code span.comment { 	color: #609; }
 code span.string { 	color: #5c2; }
 code span.brackets { }
 code span.symbol { 	color: #777; }
 code span.keywords { 	color: #d72; }

 /** HTML **/
 code.html span.tag { 	color: #ddd; }
 code.html span.attribute { 	color: #d72; }
 code.html span.string { 	color: #5c2; }
 code.html span.comment {	color: #609; }
 code.html span.doctype { 	color: #D7FF80; }

/** CSS **/
code.css .selectors {  color: #d72;}
code.css .properties {  color: #5c2;}

CSS For Sliding Door Input Buttons In Rails

Tuesday, February 26th, 2008

UPDATE: This article appears to get a reasonable amount of traffic from google so I figured I’d update/correct it. The solution I outline below ended up not working as nicely as I had hoped, so I scrapped it. Instead, I just created a single image and making all my button text fit within the length of that single image. Sliding doors isn’t worth the trouble (i.m.h.o), and what I wrote below isn’t a perfect solution anyway.

——

This is one of those annoying things that took me all day to figure out, and the stuff I was able to find on the internets wasn’t very helpful….

I wanted to create some fancy looking buttons with curved corners. But I wanted them to be real buttons (http:post) , not links (http:get) that just look like buttons.

I looked for a way to do it and found a way to do it using links and a way to do it using the <button> element. Neither of these did what I wanted. Rails uses <input type=”button” /> rather than <button>. After learning more about the difference between buttons and inputs I’m still not sure why, but I figured there must be a good reason. I did try <button> but IE was giving me headaches (I couldn’t click on the button) so I gave up. I tried adapting these methods and they weren’t working for me.

One of the methods linked above worked briefly, but it required floating one of the elements left, which makes layout a REAL pain!

So, I (perhaps by accident) found an easier way. I took the opposite approach from using the outer html element for the left image.

First, I made my own button helpers like so:


module ButtonHelper
  def fancy_button_to(button_text, action_text, button_class = "button")
    return '<form method="post" action="' + action_text + '">' + button_base(button_class, button_text) + '</form>'
  end

def button(button_text, button_class = "button")
    return button_base("button", button_text)
end

protected

  def button_base(button_class, button_text)
    return '<p class="button_wrapper"><span class="' + button_class + '"><input value="' + button_text + '" type="submit" /></span>'
  end

end

Then, the css looks like this:


span.button input {
 border:0;
 cursor:pointer;
 white-space:nowrap;
 color: #fff;
 text-align:center;
 font-weight: bold;
}

span.button {
 background: transparent url(/images/small_button_left.gif) no-repeat top left;
 padding: 6px 0px 6px 5px;
}

span.button input{
 background: transparent url(/images/small_button_right.png) no-repeat top right;
 padding-right: 5px;
 font-size: 15px;
 height: 25px;
}

You will need to create some sliding door images (see links at the beginning of this post). The values measured in pixels in the css will depend on those images.

Of course, there is some conditional css, but it’s pretty short. You just have to use different padding amounts for IE6 and IE7. So, I created a new css file call button_ie.css. I conditionally include it in the html file like so:


<!--[if lte IE 7]>
  <link href="/stylesheets/button_ie.css" media="screen" rel="Stylesheet" type="text/css"></link>
<![endif]-->

The button_ie.css looks like this:


span.button {
  padding: 0px 0px 0px 5px;
}

This isn’t perfect. Occasionally there is an error of 1 pixel in firefox 2, but IE6, IE7, & Safari seem to work fine.

Hopefully this will save someone else the frustration I faced today. Though to be honest, I’m actually thinking of moving to fix width buttons.