0

I have one question regarding the HTML tables that I couldn't manage to find myself.

Is it possible to create this layout using HTML and inline css within one table?

enter image description here

I tried to merge my cells in 4th row (I've started with 3 column layout) because I need 2 cells, and if my table width is 640px, and I force 320px for both cells, whole table gets messed up.

EDIT: 4th row is the issue, I need 2 equal width cells in it.

Thanks in advance.

4
  • I have a colspan on 3rd row, 4th row is my problem. I can't get 2 equal width cells in it. Commented Oct 22, 2014 at 12:22
  • can you make us a jsfiddle? Commented Oct 22, 2014 at 12:22
  • If you want that sort of layout, the odds are you shouldn't be using a table in the first place. Commented Oct 22, 2014 at 12:24
  • I need to use tables, it's HTML mailing. Commented Oct 22, 2014 at 12:27

5 Answers 5

2
<table border=1>
  <tr>
    <td colspan="4">Cell</td>
  </tr>
  <tr>
    <td>Cell</td>
    <td colspan="2">Cell</td>
    <td>Cell</td>
  </tr>
  <tr>
    <td colspan="4">Cell</td>
  </tr>
  <tr>
    <td colspan="2">Cell</td>
    <td colspan="2">Cell</td>
  </tr>
</table>
Sign up to request clarification or add additional context in comments.

Comments

1

All cells in the same column have to be the same width, so you need an extra column:

  • First row: one cell colspan=4
  • second row: one cell, on cell colspan=2, one cell
  • Third row: one cell colspan=4
  • Fourth row: one cell colspan=2, one cell colspan=2

The widths for each column then look something like:

  • Column 1 is narrow, let's say width=50px
  • Column 2 is 320 - column1's width, 280px
  • Column 3 same as 2, 280px
  • Column 4 same as 1, e.g. 50px

1 Comment

Thanks, I will choose this one as a right answer because you answered my question first.
0
<table border="1">
        <tr>
            <td colspan="4">cell</td>
        </tr>
        <tr>
            <td>cell</td>
            <td colspan="2">cell</td>
            <td>cell</td>
        </tr>
        <tr>
            <td colspan="4">cell</td>
        </tr>
        <tr>
            <td colspan="2">cell</td>
            <td colspan="2">cell</td>
        </tr>
    </table>

Comments

0
<table border="1" width="100%">   
   <tr>
    <td colspan="4">Cell</td>   
   </tr>   
    <tr>
    <td width="10%">Cell</td>
    <td colspan="2">Cell</td>
    <td width="10%">Cell</td>   
   </tr>   
    <tr>
    <td colspan="4">Cell</td>   
  </tr>   
  <tr>
    <td colspan="2" width="50%">Cell</td>
    <td colspan="2" width="50%">Cell</td>   
 </tr> 

Check the DEMO

Comments

0

Use like this. it works

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style>
    td{
        text-align:center;
    }
    </style>
    </head>

    <body>
    <table width="640" cellspacing="5">
      <tr>
        <td colspan="4">Cell</td>
      </tr>
      <tr>
        <td>Cell</td>
        <td colspan="2">Cell</td>
        <td>Cell</td>
      </tr>
      <tr>
        <td colspan="4">Cell</td>
      </tr>
      <tr>
        <td colspan="2">Cell</td>
        <td colspan="2">Cell</td>
      </tr>
    </table>

    </body>
    </html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.