Centering of text depending on what table column the Text is in

Posted on 2012-09-17
Last Modified: 2012-09-18

I have a table with columns defined as follows:

		<col class="col1" />
		<col class="col2" />
		<col class="col3" />
		<col class="col4" />
		<col class="col5" />
		<col class="col6" />
		<col class="col7" />

Open in new window

Any text that is in a cell within col2 or in col3 I want to be centered.  Any text that is in other columns should be unaffected.  

What's the best way to do that?  

Some of the text is H3 and some is H4.  But if they are in a table cell which is col2 and in col3 I want the text align centering to take control.

I've tried this, and it doesn't work:
#daytonaMastertable .col2 {
    text-align: center;

Open in new window

I also tried this and it didn't work:

col.col2 td h2 h3 h4 h5 {
      text-align: center;
Here's an HTML snippet:

					Over Provisioning</h4>
				<h4>Enterprise Class</h4></td>

Open in new window

BTW I already have this defined in the external style sheet:

#daytonaMastertable .col1 { width: 436px; }      
#daytonaMastertable .col2 { width: 110px; }
#daytonaMastertable .col3 { width: 110px; }
#daytonaMastertable .col4 { width: 130px; }
#daytonaMastertable .col5 { width: 150px; }
#daytonaMastertable .col6 { width: 0px; }            
#daytonaMastertable .col7 { width: 0px;


Question by:Rowby Goren
    LVL 11

    Expert Comment

    by:Amar Bardoliwala
    Hello  rowby,

    you can use <td align='center'> for column 2 and 3 in this way you will be able to center all texts in those columns.

    Also please look at following link.

    Hope this will help you.

    Thank you.

    Amar Bardoliwala
    LVL 49

    Accepted Solution

    align has been deprecated - you should rather use CSS
    The best of doing this is

    td:nth-child(3), td:nth-child(4) {
          text-align: center;

    BUT ... IE does not support this (surprise, surprise) - so if you are intent on supporting IE (personally I don't) then you can try this
    td.cent {
    	text-align: center;

    Open in new window

    And give your rows the class 'cent' (or whatever)
    		<td class="cent">Three</td>
    		<td class="cent">Four yyy</td>

    Open in new window

    LVL 9

    Author Comment

    by:Rowby Goren
    Hi Julian.

    What I did was go right to the html and did the old fashioned text align -- not in css but in the html.  It will serve as a temporary solution until I switch the table to pure divs.

    So thanks for helping me troubleshoot this.

    I just posted a related question on EE, regarding this same page,  that you might want to participate in.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at Browse or search based on font properties or name to find a suitable font for…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now