Responsive Table 利用@media

html

 <table>
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Job Title</th>
                <th>Favorite Color</th>
                <th>Wars or Trek?</th>
                <th>Porn Name</th>
                <th>Date of Birth</th>
                <th>Dream Vacation City</th>
                <th>GPA</th>
                <th>Arbitrary Data</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>James</td>
                <td>Matman</td>
                <td>Chief Sandwich Eater</td>
                <td>Lettuce Green</td>
                <td>Trek</td>
                <td>Digby Green</td>
                <td>January 13, 1979</td>
                <td>Gotham City</td>
                <td>3.1</td>
                <td>RBX-12</td>
            </tr>
            <tr>
                <td>The</td>
                <td>Tick</td>
                <td>Crimefighter Sorta</td>
                <td>Blue</td>
                <td>Wars</td>
                <td>John Smith</td>
                <td>July 19, 1968</td>
                <td>Athens</td>
                <td>N/A</td>
                <td>Edlund, Ben (July 1996).</td>
            </tr>
            <tr>
                <td>Jokey</td>
                <td>Smurf</td>
                <td>Giving Exploding Presents</td>
                <td>Smurflow</td>
                <td>Smurf</td>
                <td>Smurflane Smurfmutt</td>
                <td>Smurfuary Smurfteenth, 1945</td>
                <td>New Smurf City</td>
                <td>4.Smurf</td>
                <td>One</td>
            </tr>
            <tr>
                <td>Cindy</td>
                <td>Beyler</td>
                <td>Sales Representative</td>
                <td>Red</td>
                <td>Wars</td>
                <td>Lori Quivey</td>
                <td>July 5, 1956</td>
                <td>Paris</td>
                <td>3.4</td>
                <td>3451</td>
            </tr>
            <tr>
                <td>Captain</td>
                <td>Cool</td>
                <td>Tree Crusher</td>
                <td>Blue</td>
                <td>Wars</td>
                <td>Steve 42nd</td>
                <td>December 13, 1982</td>
                <td>Las Vegas</td>
                <td>1.9</td>
                <td>Under the couch</td>
            </tr>
        </tbody>
    </table>

css

   @media
        only screen and (max-width: 760px),
        (min-device-width: 768px) and (max-device-width: 1024px)  {

            /* Force table to not be like tables anymore */
            table, thead, tbody, th, td, tr {
                display: block;
            }

            /* Hide table headers (but not display: none;, for accessibility) */
            thead tr {
                position: absolute;
                top: -9999px;
                left: -9999px;
            }

            tr { border: 1px solid #ccc; }

            td {
                /* Behave  like a "row" */
                border: none;
                border-bottom: 1px solid #eee;
                position: relative;
                padding-left: 50%;
            }

            td:before {
                /* Now like a table header */
                position: absolute;
                /* Top/left values mimic padding */
                top: 6px;
                left: 6px;
                width: 45%;
                padding-right: 10px;
                white-space: nowrap;
            }

            /*
            Label the data
            */
            td:nth-of-type(1):before { content: "First Name"; }
            td:nth-of-type(2):before { content: "Last Name"; }
            td:nth-of-type(3):before { content: "Job Title"; }
            td:nth-of-type(4):before { content: "Favorite Color"; }
            td:nth-of-type(5):before { content: "Wars of Trek?"; }
            td:nth-of-type(6):before { content: "Porn Name"; }
            td:nth-of-type(7):before { content: "Date of Birth"; }
            td:nth-of-type(8):before { content: "Dream Vacation City"; }
            td:nth-of-type(9):before { content: "GPA"; }
            td:nth-of-type(10):before { content: "Arbitrary Data"; }
        }

        /* Smartphones (portrait and landscape) ----------- */
        @media only screen
        and (min-device-width : 320px)
        and (max-device-width : 480px) {
            body {
                padding: 0;
                margin: 0;
                width: 320px; }
        }

        /* iPads (portrait and landscape) ----------- */
        @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
            body {
                width: 495px;
            }
        }

参考资源博客 CSS - TRICKS

时间: 2024-08-24 10:20:48

Responsive Table 利用@media的相关文章

实现网页布局的自适应 利用@media screen

利用@media screen实现网页布局的自适应,IE9一下不支持 @media screen /*1280分辨率以上(大于1200px)*/ @media screen and (min-width:1200px){ .p1{color: #f00}; } /*1100分辨率(大于960px,小于1199px)*/ @media screen and (min-width: 960px) and (max-width: 1199px) { .p2{color: #f00}; } /*880分

Bootstrap dropdown menu within a responsive table

Bootstrap 的 dropdown menu 在 responsive table内 会被外层遮挡住 解决办法: $('.table-responsive').on('show.bs.dropdown', function () { $('.table-responsive').css( "overflow", "inherit" ); }); $('.table-responsive').on('hide.bs.dropdown', function ()

利用media query让背景图适应不同分辨率的设备

随着上网方式的多样化,用户选择上网的工具不再仅是PC,而可以是手机,或者平板电脑.随之而来的问题是如何让网页适应不同分辨率,这给前端工程师们带来了新的挑战,其中重要的一点是如何让图片能在不同的分辨率下都能给用户带来良好的用户体验? 方法概述 CSS3中的media query属性让我们可以根据浏览器的高宽,设备的像素比等来使用不同的CSS.当然它还一些别的用法,具体请参考这里. device-pixel-ratio是media query一查询条件,用于获得设备的像素比.一般来说iPhone4/

利用media query写响应式布局

最近才接触到响应式布局的概念,之前用到的bootstrap就是一种响应式布局的框架.学习的时候参考了http://blog.csdn.net/shoyer/article/details/8293011这篇文章. 简单记录一下用css写响应式布局的方法.大概可以这么理解,通过判断屏幕的大小来调整css的样式从而达到适应不同屏幕的目的. 首先先贴一个html,css都放在同级的css文件夹下面,因为有个简单的轮播,所以要引入jquery <!DOCTYPE html> <html>

利用@media screen实现网页布局的自适应

优点:无需插件和手机主题,对移动设备友好,能够适应各种窗口大小.只需在CSS中添加@media screen属性,根据浏览器宽度判断并输出不同的长宽值 1280分辨率以上(大于1200px) @media screen and (min-width:1200px){ #page{ width: 1100px; }#content,.div1{width: 730px;}#secondary{width:310px} } 1100分辨率(大于960px,小于1199px) @media scree

HTML table利用 JS动态增加行列 并且设置colspan

如题  在给一个借书系统做子表时需要进行这个动态添加行的操作: 主要思想: 1.获取table对象 2.增加行以及相应的列 3.设置列的colspan以及innerHTML就是内容. function AddTableRow() { var Table = document.getElementById("booktable"); //取得自定义的表对象 NewRow = Table.insertRow(); //添加行 NewCell1= NewRow.insertCell(); /

利用@media screen实现网页布局的自适应,@media screen and

开始研究响应式web设计,CSS3 Media Queries是入门.Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表.换句话说,其允许我们在不改变内容的情况下,改变页面的布局以精确适应不同的设备.那么,Media Queries是如何工作的?两种方式: 一种是直接在link中判断设备的尺寸,然后引用不同的css文件: 1 <link rel="stylesheet" type="text/css" href=

[CSS3] Responsive Table -- no more table

When the screen size is small, we can use "no more table" solution. So instead of render table is row layout, we render it in column layout. Given the table below: <table> <thead> <tr> <th>Team</th> <th>1st<

Responsive Design ------响应式设计

什么是响应式设计呢?维基百科是这样对响应式作的描述:“Responsive设计简单的称为RWD,是精心提供 各种设备都能浏览网页的一种设计方法,RWD能让你的网页在不同的设备中展现不同的设计风格.”从这一点描述来说,RWD不是流体布局,也不是网格布局, 而是一种独特的网页设计方法. 响应式设计要考虑元素布局的秩序,而且还需要做到“有求必应”,那就需要满足以下三个条件:网站必须建立灵活的网格基础:引用到网站的图片必须是可伸缩的:不同的显示风格,需要在Media Queries上写不同的样式. 要想