LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2006, 03:46 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
CSS layout


Hm.. I know this is not really a Linux-related question, and I am not sure if it even fits in programming but here goes anyway... Just because I like LQ.

I am trying to learn how to go from using tables to using css and divs with xhtml. So for my new website I wanted to start with making a three column layout, where I use two margins to the left and right with a dynamical width, and a main box in the middle with a fixed width.

I have tried googling after tutorials and guides but none of them tells me how to do this. All I get is how to put stuff to the right or left with float and stuff like that. Shouldn't this be a very basic, simple thing to accomplish?

I have created a site with the following html:
<div class="marg">left</div>
<div class="main">main</div>
<div class="marg">right</div>

But I can't figure out what to write in the css-file to get my desired result. Of course what I want to get is a site with a fixed width, using margins on both sides, a fairly common layout, although it seems to be impossible to find a tutorial that uses this layout.

The best result I got was when I used "float: left" with all divs and then used "width: 800px" just for main. The problem is that the two margins on the sides is not 'filling' all width.

Can someone please tell me what I am missing, cause I am starting to wonder what all this talk about divs+css is about? How can this be better then tables when a simple thing like this seems so hard? I hope I am the problem here.
 
Old 04-01-2006, 04:57 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
this looks like a real good example

also, when i asked, google told me this
 
Old 04-01-2006, 05:11 PM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
I've already read a number of those but they all just confuse me even more. I am not sure if I am on the right track but here's my current code:

index.htm
Code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>This Band's Site</title>
<link rel="stylesheet" type="text/css" href="sys/layout.css" />
</head>

<body>

<div class="margleft">left</div>
<div class="main">main</div>
<div class="margright">right</div>

</body>
</html>
sys/layout.css
Code:
div.margleft {
        border: 1px solid #777;
        left: 10px;
        position: absolute;
}
div.margright {
        border: 1px solid #777;
        right: 10px;
        position: absolute;
}
div.main {
        border: 1px solid #000;
        width: 800px;
        position: absolute;
}
And this is what it looks like:
http://217.31.180.216/band/

As you all can see, this is wrong and bad. But why? I just don't get it. This is just too complex for me.. Tables are easy to learn and understand. The movement from tables to divs seems more and more unnecessary.
 
Old 04-01-2006, 05:40 PM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
>The movement from tables to divs seems more and more unnecessary.

well yeh at first. CSS can be frustrating to get going with, but once its up and rolling you will be far happier and you will be writing far less code than before CSS.. i prefer a two column layout just because i found it easier to do.. however if i were to use a three column i suppose i would try somthing like this.. (changes to your files)

Code:
#margleft {
        position: absolute;
        border: 1px solid #777;
        left: 10px;
        width:100;
}
#margright {
        position: absolute;
        border: 1px solid #777;
        right: 10px;
}

#center{
        position:absolute;
        border: 1px solid #000;
        width:75%;
        left:120;
}
Code:
<html>
  <link rel="stylesheet" type="text/css" href="a.css" />
  <body>    
    <div id="margleft">
       left
    </div>    
    <div id="center">
      center
    </div>    
    <div id="margright">
       sdfds
    </div>
</body>
</html>
that one example i posted, bigbaer.com. looks pretty good i would suggest looking at it closer.
 
Old 04-02-2006, 06:43 AM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Yeah, I hope it is like with other stuff: the harder to learn the better and more effective it will be.

But I still have a big problem. I tried your example code and there is two things with it.. First you define a width for the margleft, but what I want is to make both margs using dynamical width, filling each side of the fixed width center, making the center appear in the middle of the page.

The same goes for the site you linked to. They do what most other sites do: they use fixed size for the left and right columns and let the center fill the rest. I want to do the opposite. I want a box at the center of the page with a fixed width.

Another thing is that, as you see on my page, is that the center box shouldn't use absolute position since that always places it on top of the left margin. The best would be if I didn't have to use the left and right margins and could just use one center box, that would be of a fixed width and aligned to the center of the whole page.

Hope I am making myself clear enough, here.. Cause this is really giving me a headache and I just want to get on with it so I can start creating the website. I feel kinda stuck here.

EDIT:

Here is a site I think is somewhat on the right track: http://www.pixy.cz/blogg/clanky/css-3col-layout/
This site uses a fixed size for both margins and then let the center fill the space between the two. If I could only switch this, to make the margins dynamical and the center fixed instead.

EDIT2:

Maybe I should just use frames and make them cols=*,x,* instead? It seems much easier, even if I don't like frames that much. Cause this is taking just too long. Isn't there any way I can just make a fixed size box and put it in the middle of the page?

Last edited by Ephracis; 04-02-2006 at 07:24 AM.
 
Old 04-02-2006, 02:42 PM   #6
Jaqui
Member
 
Registered: Jan 2006
Location: Vancouver BC
Distribution: LFS, SLak, Gentoo, Debian
Posts: 291

Rep: Reputation: 36
What I have done is work off the CSS from Stu Nichol's CSS PLAY site, he does allow that and has multiple layout options on it.

The only issue whith his css is that most of it is IE unfriendly, since IE doesn't recognise standards compliant css correctly.

He does have a couple of options in layouts that fit what you are looking for in there somewhere.

I'm personally using one of his "fixed" layouts on my own site.

Last edited by Jaqui; 04-02-2006 at 02:44 PM.
 
Old 04-03-2006, 06:59 AM   #7
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Thank you! I had to copy the whole source and then delete parts of it step by step but I ended up with just the a simple fixed size box placed in the middle of the page. Thank you so much for the link.
 
Old 04-03-2006, 02:14 PM   #8
Jaqui
Member
 
Registered: Jan 2006
Location: Vancouver BC
Distribution: LFS, SLak, Gentoo, Debian
Posts: 291

Rep: Reputation: 36
No problem. I figured you would find a layout that fit your needs there.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Xine and CSS Ian_Hawdon Linux - Software 2 08-25-2005 03:40 AM
two backgounds with CSS Boby Programming 2 11-25-2004 03:49 AM
html/css retrodict Programming 5 11-01-2004 06:56 PM
Getting started with CSS Dewar Programming 3 01-28-2004 07:28 AM
CSS taking over... Phrater Programming 2 07-09-2003 02:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration