Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to center text in IE but works in firefox

Text inside td elements need to be centered except for Summary and Experience. This only appears to work in Firefox/chrome. In IE8 all td text are displayed as left-justified. No matter what I try it doesn't center it. Any particular reason why this would happen?

CSS

#viewAll {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    width: 100%;
    border-collapse: collapse;
    margin-left: 10px;
    table-layout: fixed;
}

#viewAll td, #viewAll th {
    font-size: 1.1em;
    border: 1px solid #98bf21;
    word-wrap: break-word;
    text-align: center;
    overflow: hidden;
}

#viewAll tbody td {
    padding: 2px;
}


#viewAll th {
    font-size: 1.1em;
    padding-top: 5px;
    padding-bottom: 4px;
    background-color: #A7C942;
    color: #ffffff;
}

table

<?php
echo '<table id="viewAll" class="tablesorter">';

            echo '<thead>';
            echo '<tr align="center">';
            echo '<th style="width:70px;">Product</th>';
            echo '<th style="width:105px;">Prob</th>';
            echo '<th style="width:105px;">I</th>';
            echo '<th style="width:60px;">Status</th>';
            echo '<th style="width:120px;">Experience</th>';
            echo '<th style="width:200px;">Technical Summary</th>';
            echo '<th style="width:80px;">Record Created</th>';
            echo '<th style="width:80px;">Record Updated</th>';
            echo '<th style="width:50px;">Open</th>';

            echo '</tr>';
            echo '</thead>';
            echo '<tbody>';

            while ($data=mysqli_fetch_array($result)){

            #limiting the summary text displayed in the table
            $limited_summary = (strlen($data['summary']) > 300) ? substr(($data['summary']),0,300) . '...' : $data['summary'];
            $limited_exp = (strlen($data['exp']) > 300) ? substr(($data['exp']),0,300) . '...' : $data['exp'];

            echo '<tr align="center">

            <td style="width:70px; text-align:center;">'.$data['product'].'</td>';

            //if value is '-' do not display as link
            if ($data['prob'] != '-'){

            echo '<td style="width:105px;">'.$data['prob'].'</a></td>';   
            }
            else{
                    echo '<td style="width:105px; ">'.$data['prob'].'</td>';
            }

            if ($data['i'] != '-'){

              echo '<td style="width:105px; ">'.$data['i'].'</a></td>';
            }
            else{
                    echo '<td style="width:105px; ">'.$data['i'].'</td>';   
            }

            echo'<td style="width:40px; " >'.$data['status'].'</td>
            <td style="width:120px; text-align:left;">'.$limited_cust_exp.'</td>
            <td style="width:200px; text-align:left;">'.$limited_summary.'</td>
            <td style="width:80px; ">'.$data['created'].'</td>
            <td style="width:80px; ">'.$data['updated'].'</td>';


             if (isset($_SESSION['username'])){
             echo '<td style="width:50px; "> <form action="displayRecord.php" method="get">'.'
                <input type="hidden" name="id" value="'. $data['id'].'" style="text-decoration: none" /><input type="submit" value="Open" /></form></td>';
             }else{

                echo '<td style="width:50px; "> <form action="displayRecord.php" method="get">'.'
                <input type="hidden" name="id" value="'. $data['id'].'" style="text-decoration: none" /><input type="submit" value="View" /></form></td>';

             }


            echo '</tr>';

                }#end of while

echo '</tbody>';
echo '</table>';            

?>

EDIT 1: I just tried the exact same code via xampp and it centers it in IE. Any idea why it would work via XAMPP on my local machine but not via the server? (getting quite confused by this now)

EDIT 2: jsfiddle

like image 656
greenpool Avatar asked Dec 19 '12 05:12

greenpool


People also ask

Why text-Align Center doesn't work?

Short answer: your text isn't centered because the elements are floated, and floated elements "shrink" to the content, even if it's a block level element.

Why is my text not centered in HTML?

This is because text-align:center only affects inline elements, and <aside> is not an inline element by default. It is a block-level element. To align it, we will have to use something other than text-align , or turn it into an inline element.

Does Chrome support the TAG Center >?

The <center> tag has basic support with the following browsers: Chrome.

How do I center align text in a web page?

To just center the text inside an element, use text-align: center; This text is centered.


1 Answers

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Add this line of code at the top, it will work.

like image 110
Sahil Bhardwaj Avatar answered Oct 13 '22 00:10

Sahil Bhardwaj