|
Book Section

General Section

Other Sites

|
JavaScript Workshop Forums
| View previous topic :: View next topic |
| Author |
Message |
diem Member

Joined: 18 Aug 2006 Posts: 69
|
Posted: Wed Feb 21, 2007 2:55 am Post subject: 3-column <div> alignment issues |
|
|
Hi,
Apologies in advance for the quantity of source code - I think its the only way for you to see what problem I'm facing (and hopefully provide some advice):
As you will see, I am trying to build a webpage using div tags and css to position elements on the page. You will also see that I would like the webpage to have a 3-column layout.
Getting a 3-column layout to behave correctly using ONLY css and div tags is proving tricky because when you un-comment the "blah" text that should appear in the middle column, the right-hand column gets pushed off onto the next line.
What I want is for all three columns to line up across the top of the page. See code:
Here is the html
[code]
<hmtl>
<head>
<title>POP - Play Our Part</title>
<script src="../js/initialise.js"></script>
<link rel="stylesheet" type="text/css" href="../css/TESTstyles.css" media="all" />
</head>
<body leftmargin="0" topmargin="0" onLoad="initPage();">
<div class="header">
<div class="alignTextLeft">
<img src="../img/popLogo2.bmp">
</div>
<div class="alignTextRight">
Here...
</div>
</div>
<div class="headerMenu">
<div class="alignTextLeft">
<a href="" class="headerMenuLink">HOME</a> <span class="headerMenuLinkSpacer">|</span>
<a href="" class="headerMenuLink">ABOUT POP</a> <span class="headerMenuLinkSpacer">|</span>
<a href="" class="headerMenuLink">OUR PROJECTS</a> <span class="headerMenuLinkSpacer">|</span>
<a href="" class="headerMenuLink">PLAY OUR PART</a> <span class="headerMenuLinkSpacer">|</span>
<a href="" class="headerMenuLink">FACTS AND FIGURES</a>
</div>
<div class="alignTextRight">
<span class="headerMenuDate" id="headerMenuDate"></span>
</div>
</div>
<div class="mainPageContent">
<div class="alignTextLeft">
<div class="leftColumn">
<div class="iPanelHeader" id="navPanelHeader">
Site Navigation
</div>
<div class="iPanelContent" id="navPanelContent">
<span class="navPanelImage">»</span> <span class="navPanelCurrentPage">Home</span> </br>
<span class="navPanelImage">»</span> <a href="">About POP</a> </br>
<span class="navPanelImage">»</span> <a href="">Our Projects</a> </br>
<span class="navPanelImage">»</span> <a href="">Play Our Part</a> </br>
<span class="navPanelImage">»</span> <a href="">Facts And Figures</a> </br>
</div>
</div>
</div>
<div class="alignTextLeft">
<div class="middleColumn">
<div class="iPanelHeader" id="mainArticleHeader">
Main Article
</div>
<div class="iPanelContent" id="mainArticleContent">
<!-- ADD/REMOVE THE COMMENTED BLOCK TO SEE THE LAYOUT PROBLEM
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
-->
</div>
</div>
</div>
<div class="alignTextRight">
<div class="rightColumn">
<div class="iPanelHeader" id="orphansPanelHeader">
Sub-article
</div>
<div class="iPanelContent" id="orphansPanelContent">
This is where the content for the Sub-article will be displayed.
</div>
</div>
</div>
</div>
</body>
</html>
[/code]
And here is the .css file
[code]
/*
* Standard html tag styles
*/
a
{
color: #000000;
text-decoration: none;
}
a:hover
{
text-decoration: underline;
}
hr
{
height: 1px;
}
body
{
background-color: #FFFFFF;
}
/*
* Alignment styles
*/
.alignTextLeft
{
text-align: left;
display: block;
float: left;
}
.alignTextRight
{
text-align: right;
display: block;
float: right;
}
.clearer
{
clear: both;
}
/*
* Header styles
*/
.header
{
width: 100%;
background-color: #FFFFFF;
}
.headerMenu
{
float: left;
background-color: #990000;
}
.headerMenuLink
{
color: #FFFFFF;
font-family: Times New Roman, Times, serif;
font-size: 0.9em;
font-weight: bold;
}
.headerMenuLinkSpacer
{
color: #FFFFFF;
font-weight: bold;
}
.headerMenuDate
{
color: #FFFFFF;
font-family: Times New Roman, Times, serif;
font-size: 0.9em;
font-weight: normal;
}
/*
* Home page layout
*/
.mainPageContent
{
float: left;
background-color: #FFFFFF;
}
.leftColumn
{
width: 10em;
margin-top: 5px;
margin-left: 2px;
margin-right: 3px;
float: left;
}
.middleColumn
{
margin-top: 5px;
margin-left: 0px;
margin-right: 0px;
float: left;
}
.rightColumn
{
width: 20em;
margin-top: 5px;
margin-left: 3px;
margin-right: 2px;
float: left;
}
/*
* Home page styles
*/
.iPanelHeader
{
color: FFFFFF;
background-color: #990000;
padding-top: 2px;
padding-left: 3px;
padding-right: 3px;
padding-bottom: 2px;
font-family: Verdana, Arial, Sans-serif;
font-size: 0.8em;
font-weight: bold;
}
.iPanelContent
{
border-width: 1px;
border-style: solid;
border-color: #990000;
padding-top: 2px;
padding-left: 3px;
padding-right: 3px;
padding-bottom: 2px;
margin-bottom: 5px;
font-family: Verdana, Arial, Sans-serif;
color: #000000;
font-size: 0.7em;
}
.navPanelImage
{
color: #990000;
font-weight: bold;
}
.navPanelCurrentPage
{
color: #990000;
font-weight: bold;
text-decoration: underline;
}
#navPanelContent
{
background-color: #EEEEEE;
}
#orphansPanelHeader
{
text-align: left;
}
#orphansPanelContent
{
text-align: left;
}
[/code]
THANKS! |
|
| Back to top |
|
 |
sohnee Senior Member

Joined: 17 Jul 2002 Posts: 2077 Location: UK
|
Posted: Wed Feb 21, 2007 8:13 am Post subject: |
|
|
I've simplified the example for the sake of other people that might have the same problem. This is solution "A" - slots 3 dynamically widthed columns on the page.
There is a solution "B" that involves fixing the width of some of the columns - I won't post it here, but it involves using the position:relative and width: auto attributes and then setting a left and right margin - solution "A" is easier!!!
| Code: | <hmtl>
<head>
<title>POP - Play Our Part</title>
<style>
div.top {
width: 100%;
}
div.top_menu {
width: 100%;
background-color: Silver;
}
div.menu {
float: left;
width: 20%;
background-color: Yellow;
}
div.content {
float: left;
width: 60%;
}
div.right {
float: left;
width: 20%;
background-color: Aqua;
}
</style>
</head>
<body leftmargin="0" topmargin="0">
<div class="top">
<h1>HEADER</h1>
</div>
<div class="top_menu">
<p>MENU</p>
</div>
<div class="menu">
<a href="#">Link</a><br />
<a href="#">Link</a><br />
<a href="#">Link</a><br />
<a href="#">Link</a><br />
<a href="#">Link</a>
</div>
<div class="content">
<p>Lorem ipsum ei eros oblique invidunt sed, at quo tation mentitum forensibus, ipsum nihil constituto ut nec. Perfecto principes eu has. Duo assum accusata eu. Quando cetero qui no, ut pri magna commodo vocibus. Ei elit tota recteque vel, in feugait interpretaris pro. Vim inani reprimique eu.</p>
<p>Nam at fastidii mnesarchum honestatis. Ad tale utamur partiendo ius, sea ad suas harum contentiones. Possim efficiendi sadipscing te vis. No eos graecis inimicus. Ex vis vocibus prodesset contentiones. Malorum insolens laboramus has ex, ut inani labitur usu.</p>
<p>At vis quot volumus comprehensam. Qui no illud veniam inermis, falli mundi ei cum. Mel ad latine impetus appellantur. Habeo noster dicunt pri id. Et mei falli doctus ocurreret, ne eos option liberavisse, vix malis clita argumentum at. Ei his placerat deterruisset.</p>
<p>Ad quo dolorem imperdiet. Kasd verear cum ut, discere numquam pro ei, erant singulis convenire eum no. Salutandi democritum ei his, mel debet decore appellantur at. Soluta cetero singulis te qui, vim diam eruditi ad, ne debet oblique mea. Cu minim delectus urbanitas eum, lorem incorrupte an nec, ea sea forensibus deterruisset. Modo essent in mei, ad vis error errem aeterno. Et ignota nemore duo, id usu tale forensibus disputando.</p>
</div>
<div class="right">
Other Stuff
</div>
</body>
</html> |
_________________ I also work on... Steve Fenton's Blog and contribute to The Enhance PHP Unit Testing Framework |
|
| Back to top |
|
 |
diem Member

Joined: 18 Aug 2006 Posts: 69
|
Posted: Wed Feb 21, 2007 9:03 am Post subject: |
|
|
Hi,
Thanks for posting a reply so quickly!
I have run solution "A" in my browser and seen that it works perfectly assuming you want your 3 columns to take up the full width of the screen.
My specific purposes require that a small gap (of 2-3 pixels) is placed between each of the columns, which means that setting the width of each column as a percentage doesn't provide quite the result I'm looking for.
Would solution "B" help with this issue - even though it is more complex..?
If so, I'd be very grateful if I could take a look at it.
Thanks! |
|
| Back to top |
|
 |
sohnee Senior Member

Joined: 17 Jul 2002 Posts: 2077 Location: UK
|
Posted: Wed Feb 21, 2007 9:12 am Post subject: |
|
|
Well, you could allow for a 1% gap in between each bit - you just reduce the center div by 2% and add a margin-left of 1% and bob's your uncle!
Solution B would allow for a specified width for the left and right column and would allow for a specified width for the margins rather than a percentage.
Do you want to know solution B still (I hesitate to supply it, because I think it's a bit nasty - but you are welcome to see it and make up your own mind if you prefer.) _________________ I also work on... Steve Fenton's Blog and contribute to The Enhance PHP Unit Testing Framework |
|
| Back to top |
|
 |
diem Member

Joined: 18 Aug 2006 Posts: 69
|
Posted: Thu Feb 22, 2007 1:35 am Post subject: |
|
|
OK, figured it out:
Using the code you provided in solution "A" as a starting point, I then added a "container" div for each of the 3 colums. I was then able to specify a margin around each of the container divs to create the gaps without affecting the alignment of the colums.
Thanks for the advice! |
|
| Back to top |
|
 |
sohnee Senior Member

Joined: 17 Jul 2002 Posts: 2077 Location: UK
|
Posted: Thu Feb 22, 2007 3:10 am Post subject: |
|
|
Here is the "solution b"...
| Code: |
<hmtl>
<head>
<title>POP - Play Our Part</title>
<style>
div.top {
width: 100%;
}
div.top_menu {
width: 100%;
background-color: Silver;
}
div.menu {
float: left;
width: 200px;
background-color: Yellow;
}
div.content {
position: relative;
width: auto;
margin-left: 204px;
margin-right: 204px;
border: 1px solid black;
}
div.right {
float: right;
width: 200px;
background-color: Aqua;
}
</style>
</head>
<body leftmargin="0" topmargin="0">
<div class="top">
<h1>HEADER</h1>
</div>
<div class="top_menu">
<p>MENU</p>
</div>
<div class="menu">
<a href="#">Link</a><br />
<a href="#">Link</a><br />
<a href="#">Link</a><br />
<a href="#">Link</a><br />
<a href="#">Link</a>
</div>
<div class="right">
Other Stuff
</div>
<div class="content">
<p>Lorem ipsum ei eros oblique invidunt sed, at quo tation mentitum forensibus, ipsum nihil constituto ut nec. Perfecto principes eu has. Duo assum accusata eu. Quando cetero qui no, ut pri magna commodo vocibus. Ei elit tota recteque vel, in feugait interpretaris pro. Vim inani reprimique eu.</p>
<p>Nam at fastidii mnesarchum honestatis. Ad tale utamur partiendo ius, sea ad suas harum contentiones. Possim efficiendi sadipscing te vis. No eos graecis inimicus. Ex vis vocibus prodesset contentiones. Malorum insolens laboramus has ex, ut inani labitur usu.</p>
<p>At vis quot volumus comprehensam. Qui no illud veniam inermis, falli mundi ei cum. Mel ad latine impetus appellantur. Habeo noster dicunt pri id. Et mei falli doctus ocurreret, ne eos option liberavisse, vix malis clita argumentum at. Ei his placerat deterruisset.</p>
<p>Ad quo dolorem imperdiet. Kasd verear cum ut, discere numquam pro ei, erant singulis convenire eum no. Salutandi democritum ei his, mel debet decore appellantur at. Soluta cetero singulis te qui, vim diam eruditi ad, ne debet oblique mea. Cu minim delectus urbanitas eum, lorem incorrupte an nec, ea sea forensibus deterruisset. Modo essent in mei, ad vis error errem aeterno. Et ignota nemore duo, id usu tale forensibus disputando.</p>
</div>
</body>
</html>
|
_________________ I also work on... Steve Fenton's Blog and contribute to The Enhance PHP Unit Testing Framework |
|
| Back to top |
|
 |
diem Member

Joined: 18 Aug 2006 Posts: 69
|
Posted: Fri Feb 23, 2007 1:23 am Post subject: |
|
|
| Cool, thanks for posting solution "b". I think I'm getting the hang of div tags and css... |
|
| Back to top |
|
 |
gogotechy Member

Joined: 31 Jan 2006 Posts: 86 Location: United States
|
Posted: Fri Mar 02, 2007 9:24 am Post subject: Wow, sounds cool |
|
|
Hey can i see your webpage after completion? please PM the url! _________________ Justin Bowen, The head webmaster of the 'Eagles Team'
Mod for AwardSpace, Bolt, and
System Admin for the greatest support forum:
http://gogotechy2.proboards75.com
Infinity Isocates Projects Director |
|
| Back to top |
|
 |
sohnee Senior Member

Joined: 17 Jul 2002 Posts: 2077 Location: UK
|
|
| Back to top |
|
 |
gogotechy Member

Joined: 31 Jan 2006 Posts: 86 Location: United States
|
Posted: Thu Apr 26, 2007 8:20 am Post subject: is your site done? |
|
|
Hey is your site done diem? if it is PM the url ! I wish to look at _________________ Justin Bowen, The head webmaster of the 'Eagles Team'
Mod for AwardSpace, Bolt, and
System Admin for the greatest support forum:
http://gogotechy2.proboards75.com
Infinity Isocates Projects Director |
|
| Back to top |
|
 |
Rainman New member

Joined: 17 Feb 2013 Posts: 9
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|
|
(c) 1997-2002 Starling Technologies and
Michael Moncur. Portions (c) Sams Publishing.
|
|
|