The "box-sizing: border-box" means less complex math for grid designs!

One of the least enjoyable aspects of current website design is the need to add and subtract padding (or is it margin and also the border) from the width of elements in CSS design layouts. This post from Paul Irish goes into the border-box model and it's support in browsers.

One of my least favorite parts about layout with CSS is the relationship of width and padding. You're busy defining widths to match your grid or general column proportions, then down the line you start to add in text, which necessitates defining padding for those boxes. And 'lo and behold, you now are subtracting pixels from your original width so the box doesn't expand.

Ugh. If I say the width is 200px, gosh darn it, it's gonna be a 200px wide box even if I have 20px of padding. So as you know, this is NOT how the box model has worked for the past ten years. Wikipedia has a great history of this box model. Jeff Kaufman also dove into the history

Anyway, I have a recommendation for your CSS going forward:

*{ 
-moz-box-sizing: border-box; 
-webkit-box-sizing: border-box; 
box-sizing: border-box;
}

This gives you the box model you want. Applies it to all elements. Turns out many browsers already use border-box for a lot of form elements (which is why inputs and textareas look diff at width:100%;) But applying this to all elements is safe and wise.

http://paulirish.com/2012/box-sizing-border-box-ftw/ (via David Hinson)

Adding a percentage bar to the console

public static void OverwriteConsoleMessage(string message)
{
Console.CursorLeft = 0;
int maxCharacterWidth = Console.WindowWidth - 1;
if (message.Length > maxCharacterWidth)
{
message = message.Substring(0, maxCharacterWidth - 3) + "...";
}
message = message + new string(' ', maxCharacterWidth - message.Length);
Console.Write(message);
}
public static void RenderConsoleProgress(int percentage)
{
RenderConsoleProgress(percentage, '\u2590', Console.ForegroundColor, "");
}
public static void RenderConsoleProgress(int percentage, 
char progressBarCharacter, 
ConsoleColor color, string message)
{
Console.CursorVisible=false;
ConsoleColor originalColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.CursorLeft = 0;
int width = Console.WindowWidth - 1;
int newWidth = (int)((width * percentage) / 100d);
string progBar = new string(progressBarCharacter, newWidth) + 
new string(' ', width - newWidth);
Console.Write(progBar);
if (string.IsNullOrEmpty(message)) message = "";
Console.CursorTop++;
OverwriteConsoleMessage(message);
Console.CursorTop--;
Console.ForegroundColor = originalColor;
Console.CursorVisible = true;
}

Jay has talked me into this Blogging thing.

Once again Jay has talked me into doing this blog thing. This time around instead of rants and whatnot I will be posting the random things I search for during the day to aid in my coding.

Web Hosting and Windows Azure

I ended up putting this site on my College provided web space since I have easier access to it if I do something wrong, but my first deployment was into the cloud! I found an article about hosting a BlogEngine.NET blog in the new Windows Azure Web Sites preview and it was remarkably easy and straight forward.

And now there is a blog

I've been convinced that a blog is better than twitter for posting (and most importantly finding later) bits and pieces of programming wisdom that I come across on the web. This is the result.

Thank you, Scott Hanselman.

Month List

Page List