Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Thanked 1 Time in 1 Post

    unable to center text in a table

    i have tried to place the 'TEXT TO CENTER' in the center of the page using SPAN but does not seem to work, i have also tried to use <p> instead but still the bordered box is left aligned.

    I would center the whole table but this then messes up all the text and I would have to left align all text, adding even more code.

    How can I center just this section without having to recode the rest of the page ?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <table style="border: 0px solid rgb(54, 95, 145); text-align: left; width: 600px; height: 172px; font-size: 7pt;" border="0" cellpadding="2" cellspacing="0">
        <tr valign="top"> 
          <td colspan="2" bgcolor="#eaeaea" style="width: 600px;">
    <!--  only edit below this line -->
    <br><span style="width: 600px; border: 2px solid #41A808; font-size: 12pt; padding: 5px; margin-bottom: 5px; text-align: center; font-weight: bold; color: #002060;">TEXT TO CENTER</span><br>
    <!-- no edit below this line -->

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Memphis, TN
    Thanked 132 Times in 130 Posts
    add display: block; to your span

    You are giving it a width but, a span is inline by default and the width will not be applied unless you change it to be block level.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts