0

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <style>
        .container {
            overflow: auto;
            max-height: 300px;
        }
        table {
            width: 100%;
            padding: 10px;
        }
        td + td {
            border-left: 1px solid #eee;
        }
        td {
            border-bottom: 1px solid #eee;
            background: #ddd;
            color: #000;
            padding: 10px 25px;
        }
        thead tr {
            background-color: #12abcd;
        }
        th {
            height: 20px;
            color: black;
            border: none;
            white-space: nowrap;
        }
        </style>
        <title>Table</title>
    </head>
    
    <body>
        <section>
            <div class="container">
                <table>
                    <thead>
                        <tr class="header">
                            <th>
                                Table attribute name
                            </th>
                            <th>
                                Value
                            </th>
                            <th>
                                Description
                            </th>
    
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Blue</td>
                            <td>left, center, right</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se</td>
                        </tr>
                        <tr>
                            <td>Gray</td>
                            <td>rgb(x,x,x), #xxxxxx, colorname</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se</td>
                        </tr>
                        <tr>
                            <td>Pink</td>
                            <td>1,""</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se</td>
                        </tr>
                        <tr>
                            <td>Gel</td>
                            <td>pixels</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, secell content</td>
                        </tr>
                        <tr>
                            <td>Joe</td>
                            <td>pixels</td>
                            <td>NLorem ipsum dolor sit amet, consectetur adipiscing elit, ses</td>
                        </tr>
                        <tr>
                            <td>John</td>
                            <td>void, above, below, hsides, lhs, rhs, vsides, box, border</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se should be visible</td>
                        </tr>
                        <tr>
                            <td>Drew</td>
                            <td>none, groups, rows, cols, all</td>
                            <td>Not supported in HTML5. Specifies which parts of the inside borders that should be visible</td>
                        </tr>
                        <tr>
                            <td>Bist</td>
                            <td>text</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se</td>
                        </tr>
                        <tr>
                            <td>Frog</td>
                            <td>pixels, %</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se</td>
                        </tr>
                        <tr>
                            <td>Truth</td>
                            <td>pixels, %</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, se</td>
                        </tr>
                        <tr>
                            <td>Dare</td>
                            <td>pixels, %</td>
                            <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>
    </body>
    </html>

Positioning it fixed doesn't seem to work, is there any other alternative for this?

Something like this for example http://www.imaputz.com/cssStuff/bigFourVersion.html. It should work in IE8+, Latest Chrome and Firefox

6
  • If you look at the code in the page you linked to, you will notice that there are applied CSS styles, like: display: block;, width, height and overflow to the <tbody/> element. That makes the effect working ;) Commented Sep 19, 2014 at 14:39
  • It should run in IE8 and above as well. This solution doesnt Commented Sep 19, 2014 at 14:49
  • Like this? : jsfiddle.net/7UZA4/1 Commented Sep 19, 2014 at 14:52
  • possible duplicate of: stackoverflow.com/questions/19559197/… Commented Sep 19, 2014 at 14:52
  • This doesnt seem to work in IE8. Commented Sep 19, 2014 at 14:58

1 Answer 1

2

working fiddle : https://jsfiddle.net/dPixie/byB9d/3/

section {
      position: relative;
      border: 1px solid #000;
      padding-top: 37px;
      background: #500;
    }
    section.positioned {
      position: absolute;
      top:100px;
      left:100px;
      width:800px;
      box-shadow: 0 0 15px #333;
    }
    .container {
      overflow-y: auto;
      height: 200px;
    }
    table {
      border-spacing: 0;
      width:100%;
    }
    td + td {
      border-left:1px solid #eee;
    }
    td, th {
      border-bottom:1px solid #eee;
      background: #ddd;
      color: #000;
      padding: 10px 25px;
    }
    th {
      height: 0;
      line-height: 0;
      padding-top: 0;
      padding-bottom: 0;
      color: transparent;
      border: none;
      white-space: nowrap;
    }
    th div{
      position: absolute;
      background: transparent;
      color: #fff;
      padding: 9px 25px;
      top: 0;
      margin-left: -25px;
      line-height: normal;
      border-left: 1px solid #800;
    }
    th:first-child div{
      border: none;
    }



<section class="">
  <div class="container">
    <table>
      <thead>
        <tr class="header">
          <th>
            Table attribute name
            <div>Table attribute name</div>
          </th>
          <th>
            Value
            <div>Value</div>
          </th>
          <th>
            Description
            <div>Description</div>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>align</td>
          <td>left, center, right</td>
          <td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of a table according to surrounding text</td>
        </tr>
        <tr>
          <td>bgcolor</td>
          <td>rgb(x,x,x), #xxxxxx, colorname</td>
          <td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the background color for a table</td>
        </tr>
        <tr>
          <td>border</td>
          <td>1,""</td>
          <td>Specifies whether the table cells should have borders or not</td>
        </tr>
        <tr>
          <td>cellpadding</td>
          <td>pixels</td>
          <td>Not supported in HTML5. Specifies the space between the cell wall and the cell content</td>
        </tr>
        <tr>
          <td>cellspacing</td>
          <td>pixels</td>
          <td>Not supported in HTML5. Specifies the space between cells</td>
        </tr>
        <tr>
          <td>frame</td>
          <td>void, above, below, hsides, lhs, rhs, vsides, box, border</td>
          <td>outside borders that should be visible</td>
        </tr>
        <tr>
          <td>rules</td>
          <td>none, groups, rows, cols, all</td>
          <td>inside borders that should be visible</td>
        </tr>
        <tr>
          <td>summary</td>
          <td>text</td>
          <td>Specifies a summary of the content of a table</td>
        </tr>
        <tr>
          <td>width</td>
          <td>pixels, %</td>
          <td>Not supported </td>
        </tr>
      </tbody>
    </table>
  </div>
</section>
Sign up to request clarification or add additional context in comments.

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.