<div style="width: 95%">
<div style="float: left;">Link 1</div>
<div style="float: right;">Link 2</div>
</div>
You mean that?
<html>
<head>
<style>
div.fl {
float: left;
}
div.fr {
float: right;
text-align: right;
}
</style>
</head>
<body>
<div class="fl">
A
</div>
<div class="fr">
B
</div>
</body>
</html>
replace A and B
I think the best way to do any layout nowadays, is to use Grids. Once you get the hang of using grid layouts, you will never look back.
A good way to get started is to use Blueprint CSS. Its a nice framework to help you design a grid based layout.
You can avoid the heavy markup by leveraging the fact that both links are oneliners. With this markup:
<div id="navigation"></div>
<a id="view" href="...">View this page</a>
<a id="back" href="...">Back to List of Pages</a>
<form></form>
And this simple css:
#view {
float: right;
}
No clearing necessary, and no need to specify widths.
This solution would only work for this scenario: two links. If you need more, then you should look at a set of floating list items.
This way you can adjust the column width, I've done it this way for quite some time now. I figured this out by studying Wikipedia HTML and CSS. Column B will occupy the remaining width but stay confined within the width of #outer-wrapper.
<div id="outer-wrapper">
<div style="float: left; width: 200px;">
Column A
</div>
<div style="margin-left: 210px;">
Column B
</div>
<div style="clear: both;"></div>
</div>
You can nest these are have a clear maintainable column based layout.
Instead of getting too 'div happy', I'd rather put ids on the anchor tags and apply styles to them directly. You may need to put a tag with 'clear: both;' after the links to clear the floats... I leave figuring that out that as an exercise for the reader.
<html>
<head>
<title>Test Page</title>
<style type="text/css">
#viewpage {
float:right;
margin-right:5%;
}
#listpages {
float:left;
}
</style>
</head>
<body>
<a id='listpages' href="<? echo $url1 ?>">Back to List of Pages</a>
<a id='viewpage' href="<? echo $url2 ?>">View this page</a>
</body>
</html>
The idea behind using CSS 'correctly' in this case is to make your html describe your content in a way that makes sense and then use CSS to change how the content is displayed.