Table with variable number of columns in CSS -
as example, how on desktop
and on mobile
i know can js modifying structure of table, haven't been able find css solution minimal js.
try this: link
css:
table { width: 100%; border-collapse: collapse; } /* zebra striping */ tr:nth-of-type(odd) { background: #eee; } th { background: #333; color: white; font-weight: bold; } td, th { padding: 6px; border: 1px solid #ccc; text-align: left; } @media screen , (max-width: 760px), (min-device-width: 768px) , (max-device-width: 1024px) { /* force table not tables anymore */ table, thead, tbody, th, td, tr { display: block; } /* hide table headers (but not display: none;, accessibility) */ thead tr { position: absolute; top: -9999px; left: -9999px; } tr { border: 1px solid #ccc; } td { /* behave "row" */ border: none; border-bottom: 1px solid #eee; position: relative; padding-left: 50%; } td:before { /* table header */ position: absolute; /* top/left values mimic padding */ top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; } /* label 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 , landscape) ----------- */ @media screen , (min-device-width : 320px) , (max-device-width : 480px) { body { padding: 0; margin: 0; width: 320px; } } /* ipads (portrait , landscape) ----------- */ @media screen , (min-device-width: 768px) , (max-device-width: 1024px) { body { width: 495px; } }
Comments
Post a Comment