This is causing me to pull out my nose hair!
In an effort to replace tables with table-less CSS & HTML, I’ve tried to come up with some simple code for a two-column snippet.
This is not necessarily for a page layout, just for one or more sections within a web application. As I’ve said, I need to replace old HTML tables with CSS.
Basically, this is what it looks like:
The problem is, it actually works, but I’m afraid it won’t hold up. As soon as I switch some of the HTML around, the layout falls apart, like so:
Basically, I wanted to place the HTML in the order in which it appears in the document. The layout works when I have the following code (it is bare-bones minimal, stripped down, just to show what happens):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Simple XHTML Example </title>
<style type="text/css">
#container{
width: 90%;
margin: 10px auto;
background-color: #fff;
color: #333;
border: 1px dotted #363636;
line-height: 130%;
}
#top{
padding: .5em;
background-color: #ddd;
border-bottom: 1px solid gray;
}
#top h1{
padding: 0;
margin: 0;
}
#fsTable{
background-color: #eee;
float: right;
width: 500px;
margin: 0;
padding: 10px;
}
#content{
margin-right: 520px;
border-right: 1px solid gray;
padding: 1em;
max-width: 36em;
}
#footer{
clear: both;
margin: 0;
padding: .5em;
color: #333;
background-color: #ddd;
border-top: 1px solid gray;
}
#fsTable p { margin: 0 0 1em 0; }
#content h2 { margin: 0 0 .5em 0; }
/*
FLOAT CONTAINERS FIX:
http://www.csscreator.com/attributes/containedfloat.php
*/
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix{display: inline-block;}
/* Hides from IE-mac \\*/
* html .clearfix{height: 1%;}
.clearfix{display: block;}
/* End hide from IE-mac */
</style>
</head>
<body>
<div id="container">
<div id="fsTable">Aggregate Teller Balancing Record</div>
<div id="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
<div class="clearfix"></div>
</body>
</html>
Then I make a minor change in the HTML, and it stops working (see what it looks like in the second screenshot):
<body>
<div id="container">
<div id="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div id="fsTable">Aggregate Teller Balancing Record</div>
</div>
<div class="clearfix"></div>
</body>
All I did was move the floating “fsTable” DIV below the DIV that holds the content for the left column.
Am I missing something? Is there a document flow issue that I need to be aware of?
Seriously, I thought that CSS would be able to affect the layout, regardless of the HTML markup . . . but somewhere I went wrong.
Can anyone point me to the solution to this problem?
Please.