stign.no

Welcome to my WordPress weblog

Handling multiple columns in list-elements with CSS

Posted on | April 16, 2009 | No Comments

A lot of stuff in one list-elementThis is an example of a list-item, styles with css to hold two columns with several elements inside. The idea is to let the text column to the right of the image keep a straight left margin, and don`t let the text float under the image. All text elements are contained inside a span-tag, wich has is given the css property and value: "display: block", since it is an inline element. The css magic, however, lies in the css property "overflow: hidden" (overflow: auto will work as well).  The "overflow" -property gives the span-tag a strict rectangular shape, thus preventing it from floating around the image. When it comes to IE6 and IE7, it`s the "zoom: 1 " -property and value that does the magic that "overflow" does for all other modern browsers.

I have also used this method for styling search result pages, with great success. The amount of markup needed, really depends on how many html elements one has to deal with, but I feel that this combination of html and css generates less amount of markup.

Here`s the list:

 

This is the css code:

.col-container {
	width: 90%;
	margin: 0;
	font: normal 1em/1.3 Arial, Helvetica, sans-serif;
}
.col-container * {
	margin: 0;
	padding: 0;
}
.col-container li {
	list-style-type:none;
	margin: 0 0 10px 0;
}
.col-container li span, .col-container li {
	display: block;
	overflow: hidden;
	zoom: 1;
}
.col-container li img {
	float: left;
	margin: 5px 10px 10px 0;
	padding: 1px;
	background: #111;
}
.col-container li span a {
	text-decoration: none;
	color: #333;
	border: none;
}
.col-container li span b {
	display: block;
	margin-bottom:3px;
}
.col-container li span date, .col-container li span author {
	font-style: italic;
	font-size: 90%;
}
.col-container li span b a {
	color: #A11B1B;
	font-size: 120%;
}

No related posts.

Comments

Leave a Reply





Comment Spam Protection by WP-SpamFree

  • Categories

  • Twitter

  • RSS smashingmagazine.com

  • Featuring Recent Posts WordPress Widget development by YD