My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.

How to make a CSS layout for icon-left, text-right with floating divs One of the only ways to get an image-left / text-right layout to work in HTML when you have various-sized images is to use HTML tables. However, if you are generating your code with a script and you know the width of your images (or if all of your images are the same width), you can use this floating-div solution. Note that in this example I have to use in-line styles to indicate the width of each icon image, but if you need to avoid tables, this is nice solution. ![]() > > > Download Code > > > View Demo
<html> <style> * { margin: 0; padding: 0 } body { padding: 20px; text-align: center; background-color: #333; } p { margin: 0 0 10px 0; } #content { width: 600px; margin-left: auto; margin-right: auto; background: brown; border: 1px solid #555; text-align: left; } .item { margin: 20px; background-image:url('paperBackground.jpg'); padding: 20px; } .itemIcon { float:left; } .itemIcon p { font-size: 8pt; margin: 5px 0 0 0; } .itemBody h1 { font-size: 18pt; color: brown; margin: 0 0 10px 0; } .clear { clear: both; } </style> <body> <div id="content"> <div class="item"> <div class="itemIcon" style="width: 70px; padding-left: -80px"> <img src="icon.png" alt=""/> <p>This is the caption that is under the image.</p> </div> <div class="itemBody" style="margin-left: 80px"> <h1>This is the first item</h1> <p>Aliquid aliquam fabulas duo an, eu delenit intellegebat has, in sit commodo aliquip. Inermis neglegentur vis an, ea mei habeo animal verterem. Cum vivendo intellegam disputando id, usu id dicta harum convenire. Cibo corpora ut pri, sed legere probatus aliquyam no, vidisse suscipiantur eu mea. Modus etiam concludaturque pro an, ut latine quaeque per. Harum ignota mnesarchum pri ad, duo et diam oblique epicurei, pri ne vivendo omnesque epicurei.</p> <p>Aliquid aliquam fabulas duo an, eu delenit intellegebat has, in sit commodo aliquip. Inermis neglegentur vis an, ea mei habeo animal verterem. Cum vivendo intellegam disputando id, usu id dicta harum convenire. Cibo corpora ut pri, sed legere probatus aliquyam no, vidisse suscipiantur eu mea. Modus etiam concludaturque pro an, ut latine quaeque per. Harum ignota mnesarchum pri ad, duo et diam oblique epicurei, pri ne vivendo omnesque epicurei.</p> </div> </div> <div class="item"> <div class="itemIcon" style="width: 160px; padding-left: -170px"> <img src="bigIcon.png" alt=""/> <p>This is the caption that is under the image and it is a very long text so it is going to wrap a couple times here in the left column under the image.</p> </div> <div class="itemBody" style="margin-left: 170px"> <h1>This is the second item</h1> <p>Aliquid aliquam fabulas duo an, eu delenit intellegebat has, in sit commodo aliquip. Inermis neglegentur vis an, ea mei habeo animal verterem. Cum vivendo intellegam disputando id, usu id dicta harum convenire. Cibo corpora ut pri, sed legere probatus aliquyam no, vidisse suscipiantur eu mea. Modus etiam concludaturque pro an, ut latine quaeque per. Harum ignota mnesarchum pri ad, duo et diam oblique epicurei, pri ne vivendo omnesque epicurei.</p> <p>Aliquid aliquam fabulas duo an, eu delenit intellegebat has, in sit commodo aliquip. Inermis neglegentur vis an, ea mei habeo animal verterem. Cum vivendo intellegam disputando id, usu id dicta harum convenire. Cibo corpora ut pri, sed legere probatus aliquyam no, vidisse suscipiantur eu mea. Modus etiam concludaturque pro an, ut latine quaeque per. Harum ignota mnesarchum pri ad, duo et diam oblique epicurei, pri ne vivendo omnesque epicurei.</p> </div> </div> </div> </body> </html> |
Most Recently Added Items:
- Extension method to sort a generic collection of objects - c# code example - added yesterday
- A simple class that represents a matching quiz item - c# code example - added yesterday
- Extension method for checking regex in one line - c# code example - added 7 days ago
- How to use a Dictionary<> with struct key to save a dynamic matrix of objects - c# code example - added on Sunday, August 22, 2010
- A simple jquery search machine for a web page - jquery code example - added on Sunday, August 22, 2010
- Wrapper class to simplify the creation of Excel files in C# 4.0 - wpf code example - added on Tuesday, July 20, 2010
- How to make clickable flashcards in plain javascript for your mobile phone - javascript code example - added on Wednesday, July 07, 2010
- Simple example of javascript which loads jquery locally - jquery code example - added on Wednesday, July 07, 2010
- How to stop regular expression greediness - c# code example - added on Tuesday, July 06, 2010
- How to use a generic dictionary to total enum values - c# code example - added on Friday, July 02, 2010
- Generic method to case-insensitively convert a string to any enum - c# code example - added on Friday, July 02, 2010
- How to create a TextBlock that has various font formatting in code behind - silverlight code example - added on Wednesday, June 30, 2010
- How to encode binary files to text files and back to binary again - c# code example - added on Wednesday, June 30, 2010
- How to use a custom parameter struct to pass any number of variables to constructors of similar classes. - c# code example - added on Saturday, June 26, 2010
- How to make a class that renders an interactive FrameworkElement and interacts with the View - silverlight code example - added on Tuesday, June 15, 2010
- How to set a nullable type to null in a ternary operator - c# code example - added on Tuesday, June 15, 2010
- How to override events in inherited classes - c# code example - added on Friday, June 11, 2010
- How to strip off e.g. "note:" and "firstName: " from the left of a string using regex - c# code example - added on Tuesday, June 01, 2010
- How to create and subscribe to custom events using EventHandler - c# code example - added on Wednesday, May 12, 2010
- Code base for asynchronously loading and caching dependent data in a Silverlight app - silverlight code example - added on Wednesday, May 05, 2010
- Function to trim the preceding and trailing blank lines off an array - php code example - added on Sunday, May 02, 2010
- How to load and display the contents of a text file with AJAX/Jquery - jquery code example - added on Sunday, May 02, 2010
- How to use fopen() to create a proxy site to read any website content into AJAX - php code example - added on Sunday, May 02, 2010
- Code base for loading and caching external data into a silverlight app - silverlight code example - added on Friday, April 30, 2010
- An UpdateSourceTrigger workaround for Silverlight - wpf code example - added on Sunday, April 18, 2010
- Silverlight layout with click-in info panel - silverlight code example - added on Thursday, April 01, 2010
- How to get querystring variables and change HTML elements from Silverlight. - silverlight code example - added on Thursday, April 01, 2010
- XAML and code for a basic chat window in WPF - wpf code example - added on Saturday, March 27, 2010
- How to consume text from any Google Document, RSS feed, or Twitter feed in your Silverlight application - wpf code example - added on Sunday, March 21, 2010
- How to overlay one image on top of another in code behind - wpf code example - added on Saturday, March 20, 2010
