Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Narrow single column of text in a webpage

Tags:

html

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.

like image 931
yuriel Avatar asked Mar 26 '09 23:03

yuriel


3 Answers

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>
like image 67
Daniel Earwicker Avatar answered Sep 20 '22 21:09

Daniel Earwicker


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!

like image 40
Matthew James Taylor Avatar answered Sep 20 '22 21:09

Matthew James Taylor


Using CSS...

body {
  margin:0 auto;
  width:600px;
}
like image 32
Josh Stodola Avatar answered Sep 21 '22 21:09

Josh Stodola