Archive for the ‘CSS’ Category

Create a Stylized Content Box

Monday, November 2nd, 2009

With the popularity of widgets and grid styles in web design, there is a need for appealing content boxes.  Here is the HTML and CSS on how to recreate the content boxes we used on the State Bar of Wisconsin home page.

Sample Box

  1. List Item 1
  2. List Item 2
  3. List Item 3

First, the HTML:

<div class="homeBox">
<h2>Sample Box</h2>
<ol>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ol>
<img alt="" class="homeBoxBottom" src="/demos/homeToolsBackgroundBottom.png">
</div>

The image at the bottom is the one problem to this method. The image is purely aesthetic and probably shouldn’t be in the content. The rest is nice, since it’s simply a div and an h2. I used an image at the bottom since the box would have a variable height. There are other methods around this, but they would have also used extra mark up.

Next, the CSS.

.homeBox {
	padding-top: 30px;
	position: relative;
	background-image: url(demos/homeToolsBackground.png);
	background-repeat: repeat-y;
	width: 230px;
}
.homeBox h2 {
	background-image: url(/demos/homeToolsHeader.png);
	width: 230px;
	background-repeat: no-repeat;
	color: white;
	display: block;
	font-size: 16px;
	font-weight: normal;
	height: 26px;
	padding: 2px 0 0 20px;
	position: absolute;
	top: -2px;
	font-family: 'Trebuchet MS', Helvetica, sans-serif;
	font-size: 16px;
}
.homeBox .homeBoxBottom {
	bottom: -2px;
	position: absolute;
}

There isn’t anything too complicated here. The h2 includes the black & red image and it uses the full width of the div. It’s positioned absolutely and pushed 2 pixels out of the base div. It’s nice that the h2 is completely semantic and flexible, but still highly stylized.

The div has a 1px high image that gets repeated. This is what creates the impression of the header of the box being wider than the actual content of the box. If you don’t care to have that aesthetic, you could remove the images and just use a border. This would also solve the img issue in the HTML above.

This stylized content box is a good example of decisions that you sometimes have to make between style and semantics.

Re: Universal IE6 CSS

Thursday, May 28th, 2009

This article and solution around Internet Explorer 6 pitfalls went up last week. I’ve spent the past week thinking of a response to this suggestion.

When I asked myself why people visit my sites, and the ones that I make for other people, the answer was always “for the content”. Content that is almost always written words and that means type.

That is why I’m now advocating to my clients (and to you), that where feasible, not to waste hours in time and a client’s money on lengthy workarounds in an unnecessary attempt at cross-browser perfection. Instead, you and I should provide simple but effectively designed HTML elements. This means just great typography for headings, paragraphs, quotations, lists, tables and forms and no styling of layout.

Source: Andy Clarke’s For a Beautiful Web

I hate IE6. Frequently, I’ll work on something and it looks great in Chrome, Firefox & IE7. I start up a virtual machine and am hit with a sad hammer when I view the destruction after IE6 renders my code.

In Andy Clarke’s blog post above, he mentions a few different methods to handle this scenario.

How do you answer the Internet Explorer 6 question?

  1. Design for better browsers, then design alternative solutions to handle IE6 bugs?
  2. Write a remedial IE6 stylesheet to address layout issues?
  3. Use JavaScript to bootstrap CSS support in IE6?
  4. Make your site look exactly the same in IE6 as in any other browser?
  5. Develop to better browsers and spend no development time or testing for IE6?
  6. Block IE6 users from seeing your site’s styles?

Normally, my production method falls under number 1. I make sure my code is valid and semantic, which at this point ensures that it renders correctly in newer browsers. I look at it in IE6 and then often use the underscore hack to correct any issues. Personally, I’m fine with those changes as long as everything displays correctly.

The problem is, until very recently, most of my office was still using IE6 on Windows XP. Specifically, my manager and the directors all were using IE6. This meant that I spent hours trying my best to comply to option #4, pixel perfect match in IE6. Thankfully, most people in the office are using IE7 now, so we are getting close to option #1.

As for Clarke’s Universal IE6 Stylesheet, I’m not there yet. I don’t think you can ignore a browser to that degree until it’s well under 5% of users. Currently, it looks like IE6 is hovering around 15%.

Web developers have spent years circumnavigating IE6’s shortfalls. In the past year it’s market share has been cut in half, so I’m content with just riding it out with option #1 for another year or so. In 13 months, even Microsoft will stop supporting IE6.

Write code that is semantic and valid, make small adjustments for IE6, and wait for July 2010. At that point, I won’t even waste my time with a Universal IE6 Stylesheet.

CSS Rounded Corners

Thursday, May 7th, 2009

Over 18 months ago, when I first got my web production job, I was asked to create some rounded corners using CSS. It took awhile, and a little help, but I finally nailed it. Of course, the design was changed during production and the rounded corners were never used. Still, I kept the CSS I used for future reference and it has come in handy. So, here it is, all CSS and no JavaScript. It will also resize as you adjust your window.

First, these are the four images I used. The images are huge, (1848×1816), so it should be able to adjust to any screen resolution. Still, these are GIFs that are only 12 KB a piece.

Here is the HTML. It’s relatively simple, just nesting divs inside each other that we will onionskin with the CSS.

<div class="upperleft">
	<div class="upperright">
		<div class="lowerleft">
			<div class="lowerright">
			<div class="textarea">
				<p>Insert Content Here.</p>
 			</div>
 			</div>
		</div>
	</div>
</div>

And the CSS. I just use the 4 different background images and position each accordingly, and adjust the Margin & Padding so it all lines up.

/* CSS Document */
.upperleft {
	min-width:400px;
	background-image:url(top_left.gif);
	background-position: top left;
	background-repeat: no-repeat;
	margin-right: 15px;
	}

.upperright {
	background-image:url(top_right.gif);
	background-position: top right;
	background-repeat: no-repeat;
	margin-right: -15px;
	margin-left: 15px;
	}

.lowerleft {
	position: relative;
	top:15px;
	background-image:url(bottom_left.gif);
	background-position: bottom left;
	background-repeat: no-repeat;
	margin-right: 15px;
	margin-left: -15px;
	}

.lowerright {
	background-image:url(bottom_right.gif);
	background-position: bottom right;
	background-repeat: no-repeat;
	margin-right: -15px;
	margin-left: 15px;
	padding-left:5px;
	padding-right:15px;
	padding-bottom: -20px;
	}

.textarea {
	position: relative;
	top:-10px;
}

Sliding Door Buttons

Sunday, March 8th, 2009

There are a few different ways to create styled buttons for a website. One is to create an image for the button, but the problem is you will need to create new images for each button on the site. Another option is to create a background image and overlay the button text over the image. This is a better option, but what if the Button text is too long?

The best option to handle button styles on a website is to use the sliding doors technique. Create two images that will adjust accordingly to the size of the button. This means that the user only needs to load two images and they’ll be able to view every button on your website, regardless of the size of the text.

Now, lets go over how to create these buttons using CSS. First, create the images, one for the right side and the other for the left.

Right Button

Left Button

As you can see, one is excessively long so that it’s able to stretch depending on the amount of text in the button. Now the html:

<button class="wbButton">
     <span>Search</span>
</button>

Finally, the CSS:

.wbButton, .wbButton:hover {
     border:0;
     cursor:pointer;
     background:url(/demos/button_right.png) no-repeat right;
     padding: 0 25px 0 0;
     text-align: center;
     width: auto;
     overflow: visible;
     margin: 0 0 0 10px;
}

.wbButton span {
     background:url(/demos/button_left.png) no-repeat left;
     position: relative;
     display: block;
     white-space: nowrap;
     padding: 0 0 0 25px;
     height: 25px;
     line-height: 25px;
     font-size: 13px;
}

The background image sets and positions the image, while the padding will adjust the positioning of the two images. When you create your images, you’ll probably need to adjust the line-height, height & padding. This should work in all modern browsers.

CSS/Design Book Reviews

Saturday, February 21st, 2009

I picked up a few Sitepoint books during their 5 PDFs for the price of 1 sale last week.  I finished reading two of them this week, so here are my reviews for The Principles of Beautiful Web Design and Everything You Know About CSS is Wrong!

Principles of Web DesignOf these two books, I enjoyed The Principles of Beautiful Web Design the most.  It’s separated into sections on Layout and Composition, Color, Texture, Typography & Imagery.  Obviously these aren’t as in depth as an entire book on each section, but it serves as a great introduction for each principle.  Along with general tips and theories on each section, the book also follows along with a real life example.  This really helps to see the principles in practice.  With that said, the author is careful not to say that their method is the only way, but does give a lot of advice on how to organize the creation of a website.  I also learned that there are a few principles that I need to work on, mainly Typography & Texture.  This book is highly recommended since it’s good for a straight read thru, but also worth keeping on the shelf for reference.

Everything You Know About CSS is Wrong! looks at the future of web design.  The major event coming up that brings about this discussion is the release of Internet Explorer 8.  With Internet Explorer 8, all of the major browsers will support table styles.  With table styles, grid layouts will be a lot easier to create.  This is the genesis for the title of the book.  While I’m excited about the future possibilities of CSS and the death of IE6 (and to a lesser extent, IE7), this book  holds most of it’s value in the first read through.  I doubt I’ll go back to this for reference.  Once IE8 does come out, there will still be a long time that I’ll be using floats and positioning until IE7 is finally phased out (even if it’s with two different stylesheets).  Either way, this was still an interesting read and has me thinking about the future of CSS and Grid Design.