Tuesday, December 1, 2009

Inline Block, A Quick Work-Around

I've had previous struggles with inline-block quirks, and have been recently using a handy css solution I thought I'd share. Whenever I want a certain div, for example, to be displayed as inline-block, I simply add the class "inlineBlock" to it. Well, you ask, how do I define this class? I am glad you asked. I define it like so:

<style type="text/css">
.inlineBlock {
display:-moz-inline-stack;
display:inline-block;
zoom:1;
*display:inline;
}
.myClass1 {
/* other stuff */
}
<style>

<div class="myClass1 inlineBlock">
A fancy inline-block div.
</div>

This CSS causes my div to be displayed correctly as an inline-block in every browser I've checked. Not sure how the magic works specifically, but it does the job! If you have improvements or observations, add a comment below.

Tuesday, November 24, 2009

Browser detection with jQuery

Those who create web apps to work for the widest possible audience, know that overcoming browser quirks is an unfortunate part of the job. The two greatest pains for me are IE6 and IE7, both common browsers with an uncommon ability to screw up my pages. (I think IE8 is a wonderful improvement to this line of browsers.) Recently I found out how to determine if a browser is IE7 or lower using this handy jQuery statement:

<script type="text/javascript">
if ($.browser.msie && (parseFloat($.browser.version) < 8)) {
// Do something for IE7 or IE6
// Like replace some image src with a gif (instead of transparent png)
// or change a style to look right
}
</script>

Of course, you must have the jQuery library included on the page before this. But this little script is great for dealing with those demanding IE-specific quirks, like display:inline uniqueness, select-box borders and transparent png support.

IP Geo-Location Database

In a previous post I talked about a nice website that will help you block countries from your site using the IP address.

In a related stream of thought, I found an entire database of IP addresses that is available for free. The nice people at IpInfoDb have an entire database of IP-to-location data available for download (in SQL, too). And, they give you some tips and PHP code on how to most effectively use it. Thanks IpInfoDb!

Saturday, November 21, 2009

Good Design

I respect good design. Or maybe I should say that I love good design. Trained as an engineer I have always appreciated the extra effort that has been put into certain objects, products, services, etc. There is something about the well designed computer or cell phone or chair, that just seems to captivate me. It is a form of art that everyone can appreciate.

I just recently watched the movie Objectified by Gary Hustwit. The movie explores the concept of design and what it means. In one interview a designer in Europe comments that the one company in the world that takes design seriously right now is Apple. I agree with that. Their products exhibit a quality of design that far surpasses many others.

It has me thinking about good design in websites. What does a well designed web site look like? How can I make my websites function and work on a higher level? It is a fun thing to think about and has my head filled with new ideas and approaches. I hope to be able to put some of it to the test soon.

Saturday, November 7, 2009

javascript compression

Compression of JavaScript is highly recommended. It reduces file sizes and quickens browser response times. There are a few good sites out there that do JavaScript compression. There are even some that will "obfuscate" your code, making it much harder to reverse-engineer.

Well, Google has released its JavaScript compression tool called Closure. There is even an online version.

Friday, October 30, 2009

Block countries from your website

Ever wish you could block certain countries from your web server? I have. Sometimes it seems like all the hackers live in one place. I came across this website today that will create an .htaccess file for your web server. You can block any number of countries from your website based on their IP addresses. It cannot prevent determined people from using VPNs or proxies, but it works as a first line.

Wednesday, October 14, 2009

jQuery, checkbox status

I wanted to find the state of a checkbox and hide or show some text using jQuery. The thing that I got stuck on was determining if the checkbox was checked. This is how I ended up doing it:

<script type="text/javascript">
$(document).ready(function() {
$("input[name='cbname']").click( function() {
if ($(this).attr('checked'))
$('#text').hide();
else
$('#text').show();
});
});
</script>
<input type="checkbox" name="cbname"> Hide!
<div id="text">
Disappearing Text
</div>

Simply checking the attribute 'checked' of the checkbox returns its state (in jQuery 1.3.2, at least).