Is it possible to make display:table-cell layout responsive?

后端 未结 2 630
鱼传尺愫
鱼传尺愫 2020-12-31 17:29

In my code there is a table in which I have divisions which has table row consisting checkboxes horizontally. Here is my sample code, full code is in fiddle Here

HTM

2条回答
  •  感情败类
    2020-12-31 18:03

    Here is what you want:

    HTML

    Color:

    CSS

    .table {
        width: 100%;
    }
    .table caption {
        font-size: 15px;
        font-weight: 700;
        text-align: left;
        margin-bottom: 20px;
        color: #333;
        text-transform: uppercase;
    }
    .table thead {
        background-color: #444;
    }
    .table thead tr th {
        padding: 10px;
        font-weight: 700;
        color: #f2f2f2;
        text-transform: uppercase;
    }
    .table thead tr th:first-child {
        text-align: left;
    }
    .table tbody {
        background-color: #fcfcfc;
    }
    .table tbody tr td {
        padding: 10px;
        text-align: left;
    }
    .table tbody tr td:first-child {
        text-align: left;
        color: #333;
        font-weight: 700;
    }
    .table tbody tr:nth-of-type(odd) {
        background: #eee;
    }
    
    @media only screen and (min-width: 320px) and (max-width: 767px) {
        .table tbody {
            border: 0;
        }
        .table tbody tr {
            margin-bottom: 10px;
            display: block;
            border-bottom: 2px solid #ffffd;
        }
        .table tbody td {
            display: block;
            text-align: right;
            font-size: 13px;
            border-bottom: 1px dotted #ccc;
        }
        .table tbody td:last-child {
            border-bottom: 0;
        }
        .table tbody td:before {
            content: attr(data-label);
            float: left;
            text-transform: uppercase;
            font-weight: bold;
        }
    }
    

    As you can see there is a media query for phones and tablets min-width 320 to max width 767

    Basically, turn the table from desktop viewing

    to phone/tablet viewing

    JSFiddle: http://jsfiddle.net/loginet/nctzk4f3/3/

    Resource: https://css-tricks.com/accessible-simple-responsive-tables/?utm_source=dlvr.it&utm_medium=facebook

提交回复
热议问题