HTML colspan problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mindhunter74
    New Member
    • Oct 2009
    • 7

    HTML colspan problem

    I want to do an HTML table like the following:



    I wrote the following code to generate it:

    <table border>
    <tr>
    <td colspan="2">A</td>
    <td>A</td>
    </tr>

    <tr>
    <td>A</td>
    <td colspan="2">A</td>
    </tr>
    </table>


    But the problem is that it doesn't appear like I want in Firefox:


    And it's kinda similar to what I want in IE but it's not the same:


    Is this a problem in browsers? And is there anyway to solve it?
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    You have two table cells filled in each row but you are telling it to span two columns with one of those cells. You'd need at least 3 columns to span two cells or get rid of one of the cells in the row you want to expand.

    Comment

    • Mindhunter74
      New Member
      • Oct 2009
      • 7

      #3
      I'm not sure I got what you said.

      Yes, it looks fine when I add a row at the beginning with 3 columns but doesn't work without it.

      <table border>
      <tr><td>A</td><td>A</td><td>A</td></tr>
      <tr>
      <td colspan="2">A</td>
      <td>A</td>
      </tr>

      <tr>
      <td>A</td>
      <td colspan="2">A</td>
      </tr>
      </table>

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        You have two columns. Each row has a cell in both columns but you are telling one of those cells to occupy both columns. Where is the other cell to go?

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          simply put, the cell in the "middle" (over which you do the span) has no content and thus no width (despite default padding/spacing).

          Comment

          • Mindhunter74
            New Member
            • Oct 2009
            • 7

            #6
            Originally posted by drhowarddrfine
            You have two columns. Each row has a cell in both columns but you are telling one of those cells to occupy both columns. Where is the other cell to go?
            Aren't there 3 columns, not 2? I count the colspan of 2 as being 2 columns.

            Comment

            • Mindhunter74
              New Member
              • Oct 2009
              • 7

              #7
              Originally posted by Dormilich
              simply put, the cell in the "middle" (over which you do the span) has no content and thus no width (despite default padding/spacing).
              Unfortunately It still doesn't look like as I want.

              Comment

              • drhowarddrfine
                Recognized Expert Expert
                • Sep 2006
                • 7434

                #8
                Setting colspan to 2 does not create another column. There must be a 3rd column in this case for it to span. You only have two <td> elements in each row. You need to add another <td> in one of the rows but you can leave it empty.

                Comment

                • MusoFreak200
                  New Member
                  • Oct 2009
                  • 96

                  #9
                  it is not possible to make 3 columns with only a 2 columnspan...

                  i suggest that you re evaluate using a 3 columnspan...

                  thats all that i can give you info on but you could go to this site...

                  EchoEcho.Com - Complete Web Tutorials - HTML - JavaScript - Flash - Java Applets - Graphics - CGI - Design

                  Comment

                  Working...