Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Responsive Table Split for Mobile

One of the issues we are facing while making Willmaster.com into a responsive site is deciding what to do with wide tables — tables too wide to fit into most mobile devices.

The solution, we found, is to make two versions of the table.

For responsive wide tables in web pages, create one version for desktop and laptop computers. Create another version for mobile phones and tablets. Use CSS to responsively switch between the two.

The CSS declares the computer table version as display:block; and the mobile version as display:none;. A @media selector with a max-width declaration reverses the display property values.

When you look at the CSS code (further below), you'll see it's relatively simple to implement.

Depending on your table, the challenge may be creating the mobile version.

Below is an example of a wide table for computers and the two narrow tables it was split into for mobile devices.

The wide table was first published in a blog post way back in year 2006. It was designed to fit into the then-width of the content column.

Some devices will let you scroll the div itself when the content extends beyond the right edge. Touch the table and slowly scroll toward the left.

Title/Link Displays on top of or within existing content Location where layer will display
On top Within At natural location Specified in div tag Bottom-right of cursor
Floating Layer At Cursor Position Yes Yes
Show/Hide a Content Layer Yes Yes
Quick 'N Easy Div Show/Hide Yes Yes

The two narrow tables created for mobile devices each contain the text labels for the rows. It allows the reader to associate the data of the two tables with each other.

Title/Link Displays on top of or within existing content
On top Within
Floating Layer At Cursor Position Yes
Show/Hide a Content Layer Yes
Quick 'N Easy Div Show/Hide Yes
Title/Link Location where layer will display
At natural location Specified in div tag Bottom-right of cursor
Floating Layer At Cursor Position Yes
Show/Hide a Content Layer Yes
Quick 'N Easy Div Show/Hide Yes

Different tables have different requirements. For some, it will be obvious how to create the mobile version. For others, there will be more of a challenge. You may be required to split wide tables into three or more separate narrow tables.

Now that you have your two versions of the table, let me get down to the nitty-gritty and show you how easy it is to responsively publish the correct version of the table.

Here's the code. Notes follow.

<style type="text/css">

#wide-version-of-table { display:block; }
#narrow-version-of-table { display:none; }

@media (max-width:435px) /* The maximum width for the mobile device version. */
{
   #wide-version-of-table { display:none; }
   #narrow-version-of-table { display:block; }
}

</style>

<div id="wide-version-of-table">
[WIDE TABLE GOES HERE]
</div>

<div id="narrow-version-of-table">
[MOBILE VERSION GOES HERE]
</div>

Notes:

The CSS declares the wide version table as display:block; (colored blue) and the mobile version as display:none; (colored green).

The @media selector specifies a width (colored red). Adjust that width to the maximum width for the mobile device version.

That's it for the CSS part. When the screen is narrower than the max-width specified at the @media tag, the wide version is replaced with the mobile version.

The divs are color coded to match the CSS that displays them.

The id values of the divs correspond to the CSS selectors.

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC