tags:

views:

224

answers:

5

Hello,

I'm making a very simple html webpage consisting only of text. How can I narrow the single column to make it easier for the reader to read?

I would like the body of text to be roughly in the center of the page and left aligned, with margins of white space (roughly equal) to left and right.

+2  A: 

By putting the text inside a DIV with a style to control the width:

<DIV style="width: 300px">
    Text goes here.
</DIV>

For centering, based on Angela's suggestion in the comments:

<DIV style="width: 300px; margin: 0 auto">
   Text goes here.<br>
    And another line which is much longer.
</DIV>
Daniel Earwicker
This is very close to what I want. My text now looks great but there is a lot of white space on the right hand size of the screen. Is it possible to center body of the text while leaving all the text left justified?
yuriel
You can set the right and left margins for the div to auto. "margin: 0 auto" (or replace 0 with whatever you want the top and bottom margin to be.
Angela
Thanks Angela, updated.
Daniel Earwicker
Thank you so much! I know I should just learn html but this seemed so simple, yet I couldn't find anything with Google...
yuriel
+2  A: 

Using CSS...

body {
  margin:0 auto;
  width:600px;
}
Josh Stodola
A: 

The width advice given by others is the key. From the usability standpoint, you definitely want to ensure that you don't have multiple columns Newspaper-style - people are just not used to reading web pages in this way. It's OK for unrelated content though.

levik
A: 

If you want multiple columns you can build on Earwicker's answer doing something like:

<div style="float: left; width: 300px">
   First Column
</div>
<div style="float: left; width: 300px; margin-left: 1em;">
   Second Column
</div>
Jimmie R. Houts
+3  A: 

Full Cross-Browser Solution

The html:

<div id="centered"><!-- put your content here --></div>

The CSS:

body {
   text-align:center; /* this is required for old versions of IE */
}
#centered {
   width:400px; /* this is the width of the center column (px, em or %) */
   text-align:left; /*resets the text alignment back to left */
   margin:0 auto; /* auto centers the div in standards complaint browsers */
}

That's it, enjoy!

Matthew James Taylor