| | |
Centering left-aligned text using CSS
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
•
•
Join Date: Jun 2009
Posts: 28
Reputation:
Solved Threads: 3
I am working on a page that has 3 columns of text. I am trying to center the text in each column while maintaining the left justification for the text.
When I try to use
Here is a link to a page that shows the text and how they are not working. http://pages.suddenlink.net/salisburra/index2.html
Thanks so much for any help you can provide =)
This is the html from the page:
Here is the css applying to the html:
When I try to use
margin-left:auto; margin-right:auto; the spacing for the columns is destroyed. I have also tried putting a div around the paragraphs and tried to center that, but either I am doing something wrong or it isn't affecting anything.Here is a link to a page that shows the text and how they are not working. http://pages.suddenlink.net/salisburra/index2.html
Thanks so much for any help you can provide =)
This is the html from the page:
html Syntax (Toggle Plain Text)
... <body> <div class="tripletBox linkBlock"> <p> Suggested Itinerary<br /> Brochures </p> </div> <div class="tripletBox linkBlock"> <p> Lesson Plans<br /> Cool Sites </p> </div> <div class="tripletBox linkBlock"> <p> Featured Images<br /> Opportunities </p> </div> </body>
Here is the css applying to the html:
css Syntax (Toggle Plain Text)
body { margin-left: auto; margin-right: auto; min-width:1020px; max-width:1020px; ... } .tripletBox{ float:left; width:26.36%; margin-left:3.48%; margin-right:3.48%; } .tripletBox > * {/*centers images in the tripletBox container*/ display:block; margin-left:auto; margin-right:auto; } .linkBlock { ... text-align:left; }
•
•
Join Date: Jul 2008
Posts: 101
Reputation:
Solved Threads: 8
I think I understand what you're trying to do.
You are using a "double" class:
I don't think you can do that.
I think you should define 3 DIVS, for instance width 33% for each.
Keep the "margin:auto" definitions.
Inside each of them, place a new block where the text-alignment is "left".
For instance:
Other suggestion: Remove the definition of body width. The body should fill the window, and it will if you omit it.
I haven't tried this, but I think it should work.
You are using a "double" class:
HTML and CSS Syntax (Toggle Plain Text)
<div class="tripletBox linkBlock">
I don't think you can do that.
I think you should define 3 DIVS, for instance width 33% for each.
Keep the "margin:auto" definitions.
Inside each of them, place a new block where the text-alignment is "left".
For instance:
HTML and CSS Syntax (Toggle Plain Text)
<div class="tripletBox"> <div class="linkBlock"> Your text </div></div>
Other suggestion: Remove the definition of body width. The body should fill the window, and it will if you omit it.
I haven't tried this, but I think it should work.
Last edited by ingeva; Jun 27th, 2009 at 7:00 am.
Yes, I'm running Ubuntu. Of course.
I use multiple classes all the time. As long as they don't contradict each other, it works great.
Use
Remember that any surrounding styles (margin, border, padding) are rendered OUTSIDE any size style (width, height) you define. So you need to leave extra room for the surrounding styles to fit into.
Use
text-align: center; to center text. The margin works on everything else, but not text.Remember that any surrounding styles (margin, border, padding) are rendered OUTSIDE any size style (width, height) you define. So you need to leave extra room for the surrounding styles to fit into.
Last edited by MidiMagic; Jun 28th, 2009 at 8:59 pm.
Daylight-saving time uses more gasoline
•
•
Join Date: Jun 2009
Posts: 28
Reputation:
Solved Threads: 3
•
•
•
•
Use text-align: center; to center text. The margin works on everything else, but not text. text-align:center made the text center but with out a left justified lookex
------
------------
-------instead of
---------
---------
---------I also feel that Ingeva's idea should work, but when I actually implement that, nothing changes.
Thanks again for your help =)
•
•
Join Date: Jun 2009
Posts: 28
Reputation:
Solved Threads: 3
I think I have come up with a small hackjob of a solution. If I add
Then the text is lined up with their above headers, and nothing strange is happening with the floating divs.
What do you guys think about this (slightly tacky) solution?
css Syntax (Toggle Plain Text)
.linkBlock p{ margin-left:80px; }
Then the text is lined up with their above headers, and nothing strange is happening with the floating divs.
What do you guys think about this (slightly tacky) solution?
•
•
Join Date: Jul 2008
Posts: 101
Reputation:
Solved Threads: 8
•
•
•
•
I think I have come up with a small hackjob of a solution. If I add
css Syntax (Toggle Plain Text)
.linkBlock p{ margin-left:80px; }
What do you guys think about this (slightly tacky) solution?
But I think I wasn't clear enough in my first post.
If I may say so, your stylesheets looked like overkill, but I realize
that you also have other things in mind with your HTML.
I have re-written your HTML and stylesheet a little. I've used borders and background colors to indicate "what's what". I ignored the text images and use text instead. You can use images of course, but text is faster and more elegant. You can still use varying colors.
I try to avoid fixed sizes, like font sizes in pixels. I do that only once: in the body style. Otherwise I specify sizes as "em" or percent. With my example, vary the width of the window and see how everything follows. This reduces horizontal scrolling, but be aware that you can get some folding of DIVs that are too wide in a narrow window.
A design should be as simple as possible. Here I ended up with 4 levels of DIV, which I really think is too much, but an easier option (to write) is with a table, and that's not always considered "kosher".
My suggestion can be found here:
http://intertrafico.com/helper
Hope you can make it work just the way you want it.
Last edited by ingeva; Jul 1st, 2009 at 4:35 pm.
Yes, I'm running Ubuntu. Of course.
![]() |
Similar Threads
- Tutorial: Forms: styling text fields with CSS and HTML (Site Layout and Usability)
- css menu in ie7 : a:hover behaviour only on text not on the whole box (HTML and CSS)
- Refer to button text via CSS (HTML and CSS)
- Centering CSS (HTML and CSS)
- CSS Left hand row of links. (HTML and CSS)
- CSS Tab menu (HTML and CSS)
- Why is this page center aligned? (HTML and CSS)
- problems aligning lists with CSS (HTML and CSS)
Other Threads in the HTML and CSS Forum
- Previous Thread: Quick Check Missing Tag
- Next Thread: div does not inherit correct width
| Thread Tools | Search this Thread |
appointments asp background backgroundcolor beta browser bug calendar cart cgi code codeinjection corporateidentity css design development displayimageinsteadofflash dreamweaver emailmarketing epilepsy explorer firefox flash form google griefers hackers hitcounter hover html ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization pnginie6 positioning scroll seo shopping swf swf. textcolor timecolor titletags url urlseparatedwords visualization web webdevelopment webform website windows7






