tomhoppe.com

Racing, Web Development, Photography, and Beer...Stuff that matters.

Archive for the ‘CSS’ Category

CSS icons next to links, spanning multiple lines, and IE support

Thursday, April 16th, 2009

Man, IE sucks. We deal with it every day, but the lack of support for standards really makes developers jump through hoops sometimes for stupid little things. At work we’re adding some icons next to links to better identify them. A slideshow, community links, video etc etc. Normally this would be really simple. Something nice and automated like the CSS guy outlined would be nice. Except……

If the link spans two lines, IE just freaks. It doesn’t recognize the fact that the a element is two lines, it now thinks its a huge a element so the icon gets all cut off and wierd looking. Also, :after CSS support in IE doesn’t work, so it takes that option off the table.

So having said all that, we settled for a solution where we drop a tag, I chose the <i> tag for “icon” (I liked it better and its shorter then using the span tag and I use <em> for italics) after the end of the text inside the a element, and then identify the type of link with a class on the a tag. Not the ideal solution as now this isn’t automated and we have to manually identify the links, but to me it seems to be the only solution that reliably works in all browsers (IE6, IE7, FF, Safari). Alternatively, for automation, all it would take is a little jQuery to go through the hrefs on the page and drop in the <i></i> tag and class on the <a> tag.

<style type="text/css">
.asdf i {
background:url('url of your image') no-repeat;
height:10px;
vertical-align:top;
width:10px;
}
</style>

<a class="asdf" href="yourlink">Your link text goes here<i></i></a>

Easy jQuery fading color menu

Saturday, February 28th, 2009

I’m creating a site for a client and wanted to jazz up the main menu slightly. Right now its just a plain text text that rolls over with a new color. It would be cooler, and just as accessible, if I made that css color fade in and out instead of just “appear”. The HTML, CSS, and JS for this with jQuery is easy as pie.

The HTML is below. Notice all I did is double up on the text in span tags. You can’t “fade” the change of a color style, but you can fade the white text in and out above the black text.

<ul>
     <li><a href=""><span class="white">Sports</span><span class="black">Sports</span></a></li>
     <li><a href=""><span class="white">Concerts</span><span class="black">Concerts</span></a></li>
    <li><a href=""><span class="white">Theater</span><span class="black">Theater</span></a></li>
</ul>

CSS. Position that white span tag absolutely so its above the black, and what you see.

#header ul li {
float:left;
font-size:80%;
font-weight:bold;
margin-top:2px;
text-transform:uppercase;
}
#header ul li a {
color:#fff;
display:block;
height:18px;
padding:3px 15px 0 12px;
text-decoration:none;
}
#header .white {
color:#fff !important;
position:absolute;
}
#header .black {
color:#000 !important;
}

The throw in a line of jQuery to manipulate that absolutely positioned white span to fade in and out above the black for a cool fading effect on hover.

$("#header li ").hover(function(){$(this).find('.white').fadeOut("medium");},function(){$(this).find('.white').fadeIn("medium");});

2 ways of Javascript menu or navigation highlighting

Wednesday, August 27th, 2008

The following two ways are the way I do client side javascript menu highlighting. These work well if you have a site navigation or menu and you want to dynamically highlight the page that you are currently on. I use Method 1 when I have only a few items in the nav, as the JS for it is super easy, or I need to have relative URLs in my menu. Method 2 is better when there are a lot of items, as it relies only on the href and url and doesn’t need any extra stuff in the HTML. It does need absolute URLs in the menu href’s though in order to match correctly with the url.

Method 1 - This method relies on the fact that you will put id’s on each of the a elements with the value of the file name of that file. The HTML shows what I mean. The JS then just looks at the file name of the URL and makes that ID active. Super easy. There is also an “else” statement at the end of the JS so if the file name is blank because you are on “http://yourdomain.com/” it goes ahead and highlights the index menu item.

<div id="topMenu">
    <ul>
        <li><a id="index" href="">Blog</a></li>
        <li><a id="about" href="about.html">About</a></li>
        <li><a id="race_car" href="race_car.html">Race Car</a></li>
        <li><a id="contact" href="contact.html">Contact</a></li>
    </ul>
</div>
<script type="text/javascript" language="javascript">
var fileName=location.href.toLowerCase().substring( location.href.lastIndexOf("/")+1 ).split('.')[0];
if (document.getElementById(fileName)) {document.getElementById(fileName).className = "active";}
else {if (fileName == '') {document.getElementById('index').className = "active";}}
</script>

Method 2 - This method does not need any id’s in the a elements. What it does it look through the href statements in your menu and compares them to the URL. This method works better for larger menus.

<div id="topMenu">
    <ul>
        <li><a href="http://www.tomhoppe.com/test/index.html">Blog</a></li>
        <li><a href="http://www.tomhoppe.com/test/about.html">About</a></li>
        <li><a href="http://www.tomhoppe.com/test/race_car.html">Race Car</a></li>
        <li><a href="http://www.tomhoppe.com/test/contact.html">Contact</a></li>
    </ul>
</div>
<script type="text/javascript" language="javascript">
var theUrl = location.href.toLowerCase();
var navLinks = document.getElementById('topMenu').getElementsByTagName('a');

if (theUrl == 'http://www.tomhoppe.com/test/') { navLinks[0].className = 'active'; }
else {
    for (var i=0; i<navLinks.length; i++) {
        var NavLinkUrl = navLinks[i].getAttribute('href').toLowerCase();
        if (NavLinkUrl == theUrl) {navLinks[i].className = 'active';}
    }
}
</script>

Work work work work …….

Wednesday, August 20th, 2008

I’ve noticed that after working a TON, as in 80+ hour weeks for a few weeks, when that stops and I go back to “normal”, I have a real hard time adjusting to “normal” life. I get home and its as if my brain is used to still running at 100mph and not being able to just “sit still”. Real wierd feeling. Almost as if I’m lost just relaxing, and always feeling like its wierd that I’m not “doing something”.

Or maybe I just need a vacation …… :)

First foray in PHP

Wednesday, August 20th, 2008

So I’ve been a windows guy personally. Its just always what the companies where I worked used, and what I personally used. The web forum that I run has been using an antiquated ASP forum software for a while though, and it was time to move on. After evaluating some of the options, looks like vBulletin using PHP was the best one.

I have to say that I’m very impressed with my experience so far. PHP is installed and has been running like a champ on our IIS 6.0 server. The vBulletin and mySQL installs both went super smooth and I had the new forum up and running and data transferred in no time. I also made some custom php pages for redirects and the like, as well as a few edits to vBulletin’s pages.

I’m happy with the speed in which I was able to sort of “pick up” php. I was a little worried at first about being able to jump into it, but its like an “easy” ASP with a little bit of asp and javascript syntax all thrown into one. All in all, easy to learn and because of the community support, there is all kinds of mySQL and php info out there on google.

Regular Expression Cheat Sheet

Monday, August 11th, 2008

I just wanted to give myself a reference for a regular expression cheat sheet. This is much easier then forgetting and having to google for what I need. Pretty much all you ever need to know to setup a regexp.

. Matches any single character (many applications exclude newlines, and exactly which characters are considered newlines is flavor, character encoding, and platform specific, but it is safe to assume that the line feed character is included). Within POSIX bracket expressions, the dot character matches a literal dot. For example, a.c matches “abc“, etc., but [a.c] matches only “a“, “.“, or “c“.
[ ] A bracket expression. Matches a single character that is contained within the brackets. For example, [abc] matches “a“, “b“, or “c“. [a-z] specifies a range which matches any lowercase letter from “a” to “z“. These forms can be mixed: [abcx-z] matches “a“, “b“, “c“, “x“, “y“, and “z“, as does [a-cx-z].

The - character is treated as a literal character if it is the last or the first character within the brackets, or if it is escaped with a backslash: [abc-], [-abc], or [a\-bc].

[^ ] Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than “a“, “b“, or “c“. [^a-z] matches any single character that is not a lowercase letter from “a” to “z“. As above, literal characters and ranges can be mixed.
^ Matches the starting position within the string. In line-based tools, it matches the starting position of any line.
$ Matches the ending position of the string or the position just before a string-ending newline. In line-based tools, it matches the ending position of any line.
\( \) Defines a marked subexpression. The string matched within the parentheses can be recalled later (see the next entry, \n). A marked subexpression is also called a block or capturing group.
\n Matches what the nth marked subexpression matched, where n is a digit from 1 to 9. This construct is theoretically irregular and was not adopted in the POSIX ERE syntax. Some tools allow referencing more than nine capturing groups.
* Matches the preceding element zero or more times. For example, ab*c matches “ac“, “abc“, “abbbc“, etc. [xyz]* matches “”, “x“, “y“, “z“, “zx“, “zyx“, “xyzzy“, and so on. \(ab\)* matches “”, “ab“, “abab“, “ababab“, and so on.
\{m,n\} Matches the preceding element at least m and not more than n times. For example, a\{3,5\} matches only “aaa“, “aaaa“, and “aaaaa“. This is not found in a few, older instances of regular expressions.

Better Firefox bookmarks toolbar

Monday, June 30th, 2008

I hate having “toolbars” under my address bar as it takes away real estate from webpages. Having said that, there are pages that I want access to with one click and not having to go to “bookmarks” and searching for them. I found a cool little way to have your cake and eat it to by moving the bookmarks toolbar items to the main file toolbar. They fill out the otherwise unused space between “Help” and your window controls.

  • Enable your Bookmarks Toolbar under View, Toolbars.
  • Go to View, Toolbars, Customize
  • Drag the “Bookmarks Toolbar Items” from the Bookmarks toolbar to the top bar next to “Help”

Now you can change those items around to have shorter descriptions so they fit. I ended up removing the names and going by just the icons. When you bookmark something that you want in there, just add it to the bookmarks toolbar and it pops up there. Brilliant!

Google AJAX Libraries API

Monday, June 23rd, 2008

Kind of old news, but Google is now hosting the latest and greatest versions of the most popular JS libraries including jQuery, prototype, script_aculou_us, etc

Because of the gzip compression and fast response of google’s servers, these files get to the users fast!

You can either use google’s loader or just link to the permanent paths of the files.

The Ajaxian has a great article on this

iUI is awesome

Monday, June 9th, 2008

It looks like I will be an official iPhone convert here shortly. I’ve been playing with some iPhone looking pages lately at work, and got to use the iUI JS library that Joe Hewitt created.

This library is awesome. It lets you code a page in standard, plain HTML and then converts the CSS/JS to an iPhone look and feel. Also, it sets up your links to enable the “slide in” navigation to work correctly between your links. Plain genius and its oh so easy to use.

With this work and the new “Corporate Friendly” 3G iPhone that is coming soon, I’m hoping to be able to get rid of this POS Palm 700w that I’ve been cursed with, and go to the iPhone for my phone/email device. I’m very excited. We’ll see what happens!

Use it or lose it…..

Monday, April 14th, 2008

Its amazing how fast you lose a skill if you don’t use it for a few years

In my current day job of product development and client-side engineering, I haven’t been messing much with ASP, other then the occasional support for some in-house apps

I recently took a side job to make a database driven website for a jewelry store. The front end was a piece of cake, and took less time then I estimated. The asp back-end/adming tool/shopping cart on the other hand, bleh. Having been working pretty much 100% with Javascript, I “lost” the ASP syntax, methods, etc. I had to look all that up on google. I knew “what” I wanted to do, but I just couldn’t write it off the cuff like I can with JS these days.

In the end, it took certainly longer then planned, but I’m glad that I did it. I got the “asp mindset” back, and I haven’t lost a step in my day job either. Guess I came out smarter overall :)