1 reply [Last post]
charmarie1962
charmarie1962's picture
Offline
Regular
Texas / USA
Last seen: 5 years 25 weeks ago
Texas / USA
Timezone: GMT-5
Joined: 2014-03-18
Posts: 16
Points: 22

Hi! I'm trying to figure out how to write this code, and I just can't figure it out. What I want is to put my text into a "div", and I want the "div" centered. However, I want my text to align to the left. I know how to do this in a table, but I'm trying to learn not to use tables.

Example: If I'm writing this paragraph. I'd like it to be inside a div that's centered, but I'd like my text aligned to the left. How would I write this, please? I'm totally lost right now.

Thanks so much for the help! Sorry...I'm really, really new to css - it's still really scary to me right now! Smile

Charlotte

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 30 weeks 9 hours ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Presumably the div element

Presumably the div element has an explicit width smaller than its container. otherwise the div, being a block element, will take all available width. An example:

<div id="box">
  <div id="contentbox">
    <p>Now is the time for all good men to come to the aid of their party.</p>
 
    <p>The quick brown fox jumps over the lazy dog.</p>
  </div>
</div>
============
#contentbox {
    border: 1px dotted gray;
    margin: 0 auto;
    width: 50%;
    }

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.