4 centered columns
|
|
Thread rating:  |
alice - 25 Jun 2007 04:41 GMT I've been slowly learning CSS, but wanting to jump ahead and get a page to have 4 columns of text that are centered on the page, no matter how big the monitor/browser/window, I'd like each one to resize and take up 25% of the screen space. Strange things have been happening since trying to do this- First, I can't figure out how to center any of this except by putting them all in a <center> tag, which I've heard is not what one is supposed to do any more, so what can I use? Second, I thought I could accomplish everything by setting the width of the columns in the style sheet to be 25%. This worked for a fleeting moment, but when I added a small margin, it stopped working - the 4th column is not fitting on the screen. So I got rid of the margin, but still it will not fit. Except in Firefox. In IE it will not, even though it did the first time. Now it will only fit if I change the size to 24%, but then there will be a small space to the right, not a big deal, but there must be a proper way to do all this, and a reason that IE cannot fit 4 25% divs on the screen. The divs are floated left, and have no setting for clear, but I've tried all the setting on these just to see if it would make a difference, but it does not. Any suggestions?
dorayme - 25 Jun 2007 05:55 GMT In article <1182742862.074531.305120@j4g2000prf.googlegroups.com>,
> I've been slowly learning CSS, but wanting to jump ahead and get a > page to have 4 columns of text that are centered on the page, no [quoted text clipped - 18 lines] > difference, but it does not. > Any suggestions? (1) Try: <http://www.glish.com/css/8.asp>
(2) If you want to float divs, you will have difficulty centering without using some javascript. I am sure it would be fine to use it for the purpose of centering things as your page would still be fine (just not centered) for those without js.
In a different context but not that different, I used some javascript called bootnic.js to get this working.
<http://tinyurl.com/2jsoe5>
Principle would be the same.
(3) Make life easy for yourself in the short term at least and use a 4 col table where centering is easy and the design most stable. (I'm out of here, I can feel the charge of the heavy brigade coming...)
 Signature dorayme
dorayme - 25 Jun 2007 06:18 GMT In article <doraymeRidThis-7B97D0.14551325062007@news-vip.optusnet.com.au>,
> In article > <1182742862.074531.305120@j4g2000prf.googlegroups.com>, [quoted text clipped - 4 lines] > > and take up 25% of the screen space. > > Strange things have been happening since trying to do this- ...
> (2) If you want to float divs, you will have difficulty centering > without using some javascript. I am sure it would be fine to use [quoted text clipped - 7 lines] > > Principle would be the same. Just a little follow up on this point. Take a look at:
<http://tinyurl.com/2fb9fm>
Just a quick slap up of 4 cols, not quite 25% (actually I did not quite understand your requirement. If each col is 25%, how can either each or the whole lot be centred? What's to centre? (I hope not the text within each col?)
 Signature dorayme
alice - 25 Jun 2007 17:12 GMT > In article > <doraymeRidThis-7B97D0.14551325062...@news-vip.optusnet.com.au>, [quoted text clipped - 33 lines] > -- > dorayme I guess by center what I really mean is, all 4 columns equal width and no space on the right side, which is what would happen normally.
Chris F.A. Johnson - 25 Jun 2007 07:58 GMT > I've been slowly learning CSS, but wanting to jump ahead and get a > page to have 4 columns of text that are centered on the page, no [quoted text clipped - 8 lines] > fleeting moment, but when I added a small margin, it stopped working - > the 4th column is not fitting on the screen. Margins, padding, and borders are added to the specified width. Make the width a litle less, then add the extras.
> So I got rid of the margin, but still it will not fit. Except in > Firefox. In IE it will not, even though it did the first time. Now it > will only fit if I change the size to 24%, but then there will be a > small space to the right, not a big deal, but there must be a proper > way to do all this, and a reason that IE cannot fit 4 25% divs on the > screen. Apart from the obvious (blaming IE), you could try a container division.
> The divs are floated left, and have no setting for clear, but I've > tried all the setting on these just to see if it would make a > difference, but it does not. > Any suggestions? Provide a URL.
 Signature Chris F.A. Johnson <http://cfaj.freeshell.org> ========= Do not reply to the From: address; use Reply-To: ======== Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
alice - 25 Jun 2007 17:11 GMT On Jun 24, 11:58 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> > I've been slowly learning CSS, but wanting to jump ahead and get a > > page to have 4 columns of text that are centered on the page, no [quoted text clipped - 34 lines] > Author: > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) I guess I'm not sure how to center that container div, that's what I'm asking. I've tried the text-align: center, but that only centers the text, not what I want.
Jim Moe - 25 Jun 2007 20:05 GMT > I guess I'm not sure how to center that container div, that's what I'm > asking. I've tried the text-align: center, but that only centers the > text, not what I want. div { margin: 0 auto; }
 Signature jmm (hyphen) list (at) sohnen-moe (dot) com (Remove .AXSPAMGN for email)
alice - 25 Jun 2007 20:28 GMT > > I guess I'm not sure how to center that container div, that's what I'm > > asking. I've tried the text-align: center, but that only centers the [quoted text clipped - 5 lines] > jmm (hyphen) list (at) sohnen-moe (dot) com > (Remove .AXSPAMGN for email) Doing that does not center the 4 divs within it. In fact, when I try that on anything, it is not centered. It's strange to me how difficult this really is...
alice - 25 Jun 2007 17:56 GMT On Jun 24, 11:58 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> > I've been slowly learning CSS, but wanting to jump ahead and get a > > page to have 4 columns of text that are centered on the page, no [quoted text clipped - 28 lines] > > Provide a URL. www.fearofdolls.com/4columns.html
I guess I can try the javascript, but I was hoping for a more definitive answer as to why not, or if, IE can have 4 divs at 25%...why does that add up to more than 100% even without any margins or padding?
> -- > Chris F.A. Johnson <http://cfaj.freeshell.org> > ========= Do not reply to the From: address; use Reply-To: ======== > Author: > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) alice - 25 Jun 2007 18:21 GMT > On Jun 24, 11:58 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com> > wrote: [quoted text clipped - 48 lines] > > - Show quoted text - Ok, this is strange, yesterday the columns would not fit, today they do. And yes, the browser window was maximized the whole time. Anyway, there must be a better way to center all this than javascript, but how do I center the container div?
Ben C - 25 Jun 2007 21:38 GMT [...]
>> www.fearofdolls.com/4columns.html [...]
> Ok, this is strange, yesterday the columns would not fit, today they > do. I think you were using 25% yesterday, now you're using 160px, so provided the viewport is wider than 640px (or 640px plus a bit in IE) then they will fit.
Using 25% was logical, it's not your fault it didn't work, but a bug (or "weird feature" if you're extremely generous) in IE.
Although bear in mind as was pointed out that borders, padding and margins are not included in what you set for width.
> And yes, the browser window was maximized the whole time. > Anyway, there must be a better way to center all this than javascript, > but how do I center the container div? You don't have a container div at the moment. But if you put one in around your floats, like this:
<div class="container"> <div class="reviews"> THIS IS COLUMN1 Pormebut there is an audibected. </div> ...
style it like this:
.container { margin: 0 auto; /* to centre it */ display: table; /* to give it shrink-to-fit width */ }
But for IE where display: table doesn't work, you'll have to settle for fixing the width, but this is OK since you're setting the widths of the things in it so you know what the total needs to be:
.container { margin: 0 auto; /* to centre it */ width: 640px; overflow: hidden; /* to make it contain the floats vertically */ }
The problem is that from what I hear, on IE, the fourth column might jump down with that 640px even though 4 * 160 = 640. So you'll have to give it a bit more than 640px. And then it won't be properly centered. So you can use an actual table instead.
<table class="container"> <tbody> <tr> <td> <div class="reviews"> THIS IS COLUMN1 Pormebut there is an audibected. </div>
etc. But if you're going to use a table you might as well give it four columns and not bother with the floats.
Ideally, you would use this instead:
.container { text-align: center; }
.reviews { width: 160px; vertical-align: top; text-align: left; display: inline-block; }
which works in Opera and Konqueror, and might even work in IE, but not Firefox.
alice - 26 Jun 2007 17:52 GMT > [...] > >>www.fearofdolls.com/4columns.html [quoted text clipped - 84 lines] > which works in Opera and Konqueror, and might even work in IE, but not > Firefox. Thanks. All of that makes sense..I thought something was wrong with IE. I originally wanted to not have to set the width of the columns, let them be as big as they can/as needed, but I guess there's really no way to do that. I was also expecting some sort of simple -center- tag, like in he old days of html.
|
|
|