2013-10-09 180 views
1

因爲這一點,我要離開我的腦海了。我正在嘗試使用僅CSS和HTML在移動設備上響應表格。搜索谷歌和stackoverflow幾個小時,仍然不知道如何抓住這個問題。嘗試了不同的方法,仍然沒有。嘗試div表和正常。CSS響應表

確定在這裏不言而喻,我試圖讓這個表>http://postimg.org/image/62upgmozv/通過媒體查詢480像素轉換成以下>http://postimg.org/image/5brtspn5x/

顏色和名稱是非常重要的。我只需要一個建議或想法如何解決這個問題。主要問題是使用DATE(橙色)單獨的div製作div表格,然後將其分類爲移動版本(請參閱第二張圖片),然後重複下一個日期。

+0

使用引導程序http://getbootstrap.com/可能是一個好主意。 – nilobarp

+0

這裏最主要的是你正在採取一個'name'元素(標題單元格)並複製它,每個'日期'部分一次。 CSS不能做到這一點。 –

+0

@Kolink:CSS可以做到這一點。 OP:你能提供你桌子的實際代碼嗎? –

回答

2

你可以看一下我做了這樣一個例子:http://www.f1time.com/mobile/

我沒有從你的表中的代碼,所以我想我會分享一個我做了該功能。

@media only screen and (max-width: 500px) { 
/* 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; 
    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: "Current Position"; } 
td:nth-of-type(2):before { content: "Position Change"; } 
td:nth-of-type(3):before { content: "Manager"; } 
td:nth-of-type(4):before { content: "Lap"; } 
td:nth-of-type(5):before { content: "Gap"; } 
td:nth-of-type(6):before { content: "Gap to Front"; } 
td:nth-of-type(7):before { content: "Lap Time"; } 
td:nth-of-type(8):before { content: "Fastest"; } 
td:nth-of-type(9):before { content: "Pits"; } 
td:nth-of-type(10):before { content: "Status"; } 
} 
+0

現在問我自己好幾年了,這些該死的桌子有什麼用處了,我終於明白了他們的力量。 +爲答案。 – matewka

+0

我沒有完全理解這一點。那麼transformig第一個td(日期)就像一個頭,然後將頭(名稱)和數據放在它下面呢?然後再次顯示另一個日期並在它下面!!再次輸入名稱和數據 – frog

+0

所有需要關注的是最後一位代碼。只需改變'td:nth-​​of-type(1):before {content:「當前位置」; }'content屬性和第一列的標題,等等......檢查我發佈的鏈接,並調整瀏覽器的大小(<500px寬),然後你會看到會發生什麼:) –