如何在所有浏览器中添加表格边框并使表格居中?

时间:2011-09-09 14:22:36

标签: html css cross-browser

有人能告诉我如何在Google Chrome中添加表格的边框吗? 以及如何在Firefox,Safari,Opera,Chrome中对齐桌子“中心”。

请查看附件代码:

<html>
<head>
<style type="text/css">
.mainpagebordr {
    BORDER-BOTTOM: #000000 1px solid;
    BORDER-LEFT: #000000 1px solid;
    BORDER-COLLAPSE: collapse;
    BORDER-TOP: #000000 1px solid;
    BORDER-RIGHT: #000000 1px solid; 
    margin-left : auto;
    margin-right:  auto;
    margin-left:  auto;
    }
    .marginStyle{margin: 0 auto;} 
</style>
</head>
<body>


<center>
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" class="marginStyle" align="center">

<tr class="rcptFont">

    <tr>

    <td width="26.7%">&nbsp;

    </td>

    <td align="center" width="480px" valign="top">

<table border="0" class="mainpagebordr marginStyle" height="730" align="center">     

        <tr class="rcptFont">

        <td width="175" valign="top" height="10%">

        <table width="200" align="left">

        <tr>

        <td width="105" height="90" style="padding-left: 10px">

        <img src="/URAPortalBC/Common/images/ura5.jpg" height="112" width="160"/>

        </td>

        </tr>

        <tr class="rcptFont1">

        <td width="175">

        </td>       

        </tr>       

        </table>    

        </td>



        <td colspan="4" width="245" align="center" class="withBorder marginStyle" valign="top">

        <table align="center" class="withBorder marginStyle" width="245">

                    <tr class="rcpthead">

                        <td width="245" align="center">

                            <strong>Uganda Revenue Authority</strong>

                        </td>

                    </tr>

                    <tr class="rcptFont1">

                        <td  align="center">Kampala Area office Plot 51,Windsor Crescent P.O.box 1234 Kampala,Uganda</td>

                    </tr>



        <tr class="rcpthead">

        <td  align="center" >

        <strong>Acknowledgement Receipt</strong>

        </td>

        </tr>

        <tr class="rcptFont" >

        <td align="center">

        <strong>Declaration of Instrument</strong>

        </td>

        </tr>

        </table>

        </td>

        <td colspan="4" width="245" valign="top" style="padding-top: 3px;padding-right: 10px">

                        <table width="170" class="rcptlstHead" valign="top">

                    <tr>

                        <td width=""><p style="FONT-SIZE:8pt;font-family:Arial;TEXT-ALIGN: right""><b>For General Tax Questions</b></p>

                    </tr>

                    <tr>

                        <td><p style="FONT-SIZE:8pt;font-family:Arial;TEXT-ALIGN: right"> Call Our Toll Free Number</p></td>

                    </tr>

                    <tr>

                        <td><p style="FONT-SIZE:10pt;font-family:Arial;TEXT-ALIGN: right"><b>0800117000</b></p></td>

                    </tr>

                    <tr>

                        <td><p style="FONT-SIZE:8pt;font-family:Arial;TEXT-ALIGN: right">  Or log onto URA web portal</p>

                        </td>

                    </tr>

                    <tr>

                        <td><p style="FONT-SIZE:10pt;font-family:Arial;TEXT-ALIGN: right">  <b>http://ura.go.ug </b></p>

                        </td>

                    </tr>

                </table>

            </td>

        </tr>   

        <tr> <td> &nbsp; </td> </tr>

        <tr class="rcptFont">

        <td colspan="4">

         &nbsp;&nbsp;Dr. dfdfd  asfdsf

        </td>

        <td colspan="5" >   

        &nbsp;Notice Date : <strong>09/09/2011</strong> 

        </td>

        </tr>





        <tr class="rcptFont">

        <td colspan="4">

         &nbsp;&nbsp;  ,

        </td>

        <td colspan="5" >

        &nbsp;Reference No :<strong>LI02120001570</strong>      

        </td>       

        </tr>

        <tr  class="rcptFont">

        <td colspan="4">

         &nbsp;&nbsp; addaf ,

        </td>

        <td colspan="5" align="right"> 

            <img src="http://localhost:8080/URAPortalBC/barcode?data=LI02120001570&amp;headless=false&amp;drawText=false&amp;width=1&amp;height=5&amp;type-Code128B" border="0" alt=""/>

        </td>

        </tr>

        <tr class="rcptFont">

            <td colspan="4">

         &nbsp;&nbsp;AMOLATAR, KIOGA, AMOLATAR TOWN COUNCIL

        </td>

        <td colspan="5" >

        &nbsp;TIN : <strong>N.A.</strong>       

        </td>

        </tr>



    <tr> <td> &nbsp; </td> </tr>



    <td colspan=10>

    <table align="center" border="1" bordercolor="black" valign="top" width="90%" cellpadding="0" cellspacing="0" class="marginStyle">

    <tr class="rcptFont">

        <td colspan="8">

        <center><b>Declaration of Instrument For Stamp Duty</b></center>

        </td>

            <tr class="rcptFont">

                <td align="center" width="5%" class="mainpagebordr" align="left"><b>1</b></td>

                <td align="left" width="45%" class="mainpagebordr" align="left"><b>TIN of applicant</b></td>

                <td align="left" width="50%" class="mainpagebordr" align="left"><b>N.A.</b></td>

            </tr>





            <tr class="rcptFont">

                <td align="center" width="5%" class="mainpagebordr" align="left"><b>2</b></td>

                <td align="left" width="45%" class="mainpagebordr" align="left"><b>Name of Taxpayer</b></td>

                <td align="left" width="50%" class="mainpagebordr" align="left"><b>Dr. dfdfd  asfdsf</b></td>

            </tr>



            <tr class="rcptFont">

                <td align="center" width="5%"class="mainpagebordr" align="left"><b>3</b></td>

                <td align="left" width="45%" class="mainpagebordr" align="left"><b>Type of Instrument</b></td>

                <td align="left" width="50%" class="mainpagebordr" align="left"><b>CANCELLATION-instrument of</b></td>

            </tr>

            <tr class="rcptFont">

                <td align="center" width="5%" class="mainpagebordr" align="left"><b>4</b></td>

                <td align="left" width="45%" class="mainpagebordr" align="left"><b>Number of copies to be stamped</b></td>

                <td align="left" width="50%" class="mainpagebordr" align="left"><b>2</b></td>

            </tr>



            <tr class="rcptFont">

                <td align="center" width="5%" class="mainpagebordr" align="left"><b>5</b></td>

                <td align="left" width="45%" class="mainpagebordr" align="left"><b>Amount of Duty (UGX)</b></td>

                <td align="left" width="50%" class="mainpagebordr" align="left"><b>0</b></td>

            </tr>





            <tr class="rcptFont">

                <td align="center" width="5%" class="mainpagebordr" align="left"><b>6</b></td>

                <td align="left" width="45%" class="mainpagebordr" align="left"><b>Payment registration Number</b></td>

                <td align="left" width="50%" class="mainpagebordr" align="left"><b>2120000000412</b></td>

            </tr>



        </table>

        </td>

        <br>

        <br>

        <tr align="center"  class="rcptFont">

            <td colspan="10"><b></b>        

                <br>

                <table align="left">

                        <tr><td class="rcptFont1">Your Search code:&nbsp;</td>

                            <td class="rcptFont1"><strong>52065557675TW</strong></td>

                        </tr>

                    </table>                

            </td>           

        </tr>



    <tr> <td> &nbsp; </td> </tr>

    <tr> <td> &nbsp; </td> </tr>

    <tr class="rcptFont">

        <td colspan="8">

        <center><b>Official URA Representative</b></center>

        </td>

        </tr>       

    <tr class="rcptFont">

        <td colspan="8">

        <center>Please check for the status of your application at the nearest tax office or</center>

        </td>

        </tr>   

    <tr class="rcptFont">

        <td colspan="8">

        <center>the URA web portal at http://ura.go.ug</center>

        </td>

        </tr>   

        <tr>

            <td colspan="10">

            <hr style="height:1px;">

            <p style="FONT-SIZE:8pt;font-family:Arial;TEXT-ALIGN: center;">Plot 26/28, Olwol Road, Opposite Blue Valley Guest House, LIRA</p>

            </td>

        </tr>       

        </table>

        </td>

        </tr>



    </table>

    <table align="center" >

            <!--<tr >

                <td align="center">

                    <form name="receiptForm" method="post">

                        <input type="hidden" name="dispatch" value="" />

                        <div id="buttons">

                            <input type="button" value="Print" id='printBtn' class="submit" onmouseover="hideStatusMsg()" onclick="printReceipt()" />

                            <input type="button" class="submit" value="Back" id='backBtn' onclick="backToRegn()" onmouseover="hideStatusMsg()"/>

                        </div>

                    </form>

                </td>

            </tr>

        --></table>



<!-- payment receipt 

 -->
</center>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

不推荐使用<center>标记,因此您不应使用它。 您在大多数表上使用了border="0"属性,最好省略此属性并使用css创建边框。

当元素具有固定宽度时,通过在两侧分配相等的边距,使用margin:0 auto;。在大多数情况下,您已将固定宽度table放置在相同大小的固定宽度td内。这没有留下任何空间的余地,所以从技术上讲,你已经把桌子放在了中心,但显然视觉效果并不是你想要的。

如果您希望最外面的表充当容器并使整个表结构居中,则需要给它一个固定的宽度,因为目前它的宽度是100%。

答案 1 :(得分:0)

改变这个:

<center>
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" class="marginStyle" align="center">

对此:

<table width="100%" cellpadding="0" cellspacing="0">

而且:

.marginStyle{margin: 0 auto;} 

对此:

table { text-align: center; margin: 0 auto; border-collapse: collapse; border: 1px solid red; }
table tr, table td { text-align: left; }