Adapt table css. What information is important?

It's no secret to any layout designer that tables are evil. They are difficult to adapt and customize. If on the desktop version of the site it is still quite easy to create a table, then when adaptive layout begins, everything goes to hell.

Actually, one of the effective options is to create a horizontal scroll for the table. It’s not difficult to do, but that’s not what today’s post is about. However, I will show it for you.

First adaptation method

<div class = "table-wrap" > <table > <thead > <tr > <th > Service</th> <th > Description</th> <th > Price</th> <th > Discount</th> </tr> </thead> <tbody > <tr > <td > Mobile layout</td> <td > Layout for phones</td> <td >$3000</td> <td > 50%</td> </tr> <tr > <td > Landing on CMS WordPress</td> <td ></td> <td >$3000</td> <td > 30%</td> </tr> </tbody> </table> </div>

Service Description Price Discount
Mobile layout Layout for phones $3000 50%
Landing on CMS WordPress Website creation with admin. panel $3000 30%

Let's style the whole thing (mainly we need to style table-wrap).

1 2 3 4 5 6 7 8 9 10 11 12 13 .table-wrap ( text-align : center ; display : inline-block; background-color : #fff ; padding : 2rem 2rem; color : #000 ; ) .table-wrap ( overflow-y: scroll ; ) )

Table-wrap ( text-align: center; display: inline-block; background-color: #fff; padding: 2rem 2rem; color: #000; ) @media screen and (max-width: 600px) ( .table-wrap ( overflow-y: scroll; ) )

As a result, at a width of UP TO 600 pixels, the table will scroll, but the site will not. Convenient, but today I would like to talk about something else.
I found another interesting approach to table responsiveness. It consists of using data attributes and pseudo-classes. Now I'll show you everything.

Second adaptation method

First, let's change the markup:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Service Description Price Discount
Mobile layout Layout for phones $3000 50%
Landing on CMS WordPress Website creation with admin. panel $3000 30%

Service Description Price Discount
Mobile layout Layout for phones $3000 50%
Landing on CMS WordPress Website creation with admin. panel $3000 30%

Assigned an attribute to each column data-label, which will be useful to us in the future.

Set the basic styles:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 body ( text-align : center ; padding-top : 10% ; font-family : sans-serif ; background-image : url ("bg.jpg" ) ; background-size: cover; height : 100vh; color : #fff ; ) .table-wrap ( text-align : center ; display : inline-block; background-color : #fff ; padding : 2rem 2rem; color : #000 ; ) table ( border : 1px solid #ccc ; width : 100% ; margin : 0 ; padding : 0 ; border-collapse : collapse ; border-spacing : 0 ; ) table tr ( border : 1px solid #ddd ; padding : 5px ; ) table th, table td ( padding : 10px ; text-align : center ; border-right : 1px solid #ddd ; ) table th ( color : #fff ; background-color : #444 ; text-transform : uppercase ; font-size : 14px ; letter-spacing : 1px ; )

body ( text-align: center; padding-top: 10%; font-family: sans-serif; background-image: url("bg.jpg"); background-size: cover; height: 100vh; color: #fff ; ) .table-wrap ( text-align: center; display: inline-block; background-color: #fff; padding: 2rem 2rem; color: #000; ) table ( border: 1px solid #ccc; width: 100% ; margin:0; padding:0; border-collapse: collapse; border-spacing: 0; ) table tr ( border: 1px solid #ddd; padding: 5px; ) table th, table td ( padding: 10px; text-align : center; border-right: 1px solid #ddd; ) table th ( color: #fff; background-color: #444; text-transform: uppercase; font-size: 14px; letter-spacing: 1px; )

It looks like a regular table, naturally, by moving the site by 320-420 pixels, we will see a horizontal scroll of the entire site. Not the point.

How to fix it? add styles:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 @media screen and (max-width: 600px) ( table ( border : 0 ; ) table thead ( display : none ; ) table tr ( margin-bottom : 10px ; display : block ; border-bottom : 2px solid #ddd ; ) table td ( display : block ; text-align : right ; font-size : 13px ; border-bottom : 1px dotted #ccc ; border-right : 1px solid transparent ; ) table td:last-child ( border-bottom : 0 ; ) table td:before ( content : attr(data- label) ; float : left ; text-transform : uppercase ; font-weight : bold ; ) )

@media screen and (max-width: 600px) ( table ( border: 0; ) table thead ( display: none; ) table tr ( margin-bottom: 10px; display: block; border-bottom: 2px solid #ddd; ) table td ( display: block; text-align: right; font-size: 13px; border-bottom: 1px dotted #ccc; border-right: 1px solid transparent; ) table td:last-child ( border-bottom: 0; ) table td:before ( content: attr(data-label); float: left; text-transform: uppercase; font-weight: bold; ) )

Here we made the table rows block-like, removed the column names, and aligned the text of the columns themselves to the right. In turn, using the pseudo-class :before we append our date attributes to the left margin. It turns out like this:

Here's another pen:

As you can see, we turned the table rows into a small block that contains all the information. I think this table adaptability option is suitable for small tables. Enjoy it, friends!

Data tables don't handle responsive design very well. Unfortunately, this moment exists. Responsive design is all about customizing your design to accommodate different screen sizes. So what happens when the screen is narrower than the minimum data table width? You can zoom out and see the entire table, but the text size will be too small to read. Or you can zoom in on the reading point, but you'll need to scroll vertically horizontally and (sadly) to view the table. Data tables can be quite broad and certainly are. Tables can be made flexible in width (weight=100%), but the contents of the cells can become so narrow that it simply cannot be seen.

In order to avoid this unpleasant moment, adaptive tables are used. Such a table will display a horizontal scroll bar if the screen is too small to display the full content.

How to Make a Responsive Table Using CSS

To create a responsive table, add a container element overflow-x:auto around

:

...

Note. In OS X Lion (on Mac), scrollbars are hidden by default and only appear when in use (even if set to "overflow:scroll" or auto).

Windows : Internet Explorer 10.0+, Firefox 1.5+, Google Chrome, Opera 9.5+, Safari 3.1+, SeaMonkey 1.0+ [1].

Linux: Firefox 1.5+, Google Chrome / Chromium, Opera 9.5+, SeaMonkey 1.0+ [2].

If an HTML table contains too much data, it becomes wider than the available space on the page and begins to overflow. To remedy the situation, you can add horizontal scrolling to the table. Example:

1 2 3 4 5 6 7 8 9 10
Table_data_1 Table_data_2 Table_data_3 Table_data_4 Table_data_5 Table_data_6 Table_data_7 Table_data_8 Table_data_9 Table_data_10

HTML/XHTML. Code:

<table>

<tr>

<th>1</th>

<th>2</th>

<th>3</th>

<th>4</th>

<th>5</th>

<th>6</th>

<th>7</th>

<th>8</th>

<th>9</th>

<th>10</th>

</tr>

<tr>

<td>Table_data_1</td>

<td>Table_data_2</td>

<td>Table_data_3</td>

<td>Table_data_4</td>

<td>Table_data_5</td>

<td>Table_data_6</td>

<td>Table_data_7</td>

<td>Table_data_8</td>

<td>Table_data_9</td>

<td>Table_data_10</td>

</tr>

</ table>

table(display: block; overflow-x: auto;)

/* Additional CSS, just to give the example some appearance: */

table(border-collapse: collapse;)

table td,th(padding: 10px; border: 1px #000 solid;)

Note: CSS property display: block makes it so that the table takes up only as much width as it needs to accommodate the data without visual distortion. No more, without stretching across the entire width of the available space on the page. Even if the CSS code is added width: 100%. Example:

1 2 3
Table_data_1 Table_data_2 Table_data_3

Aliosque subditos et theme

There are quite a few online services to create sitemap.xml. However, you can do it yourself on your computer using the lynx browser and several utilities command line Linux. The following is an example of a bash script called "sitemap.sh" that uses them. Bash script that creates the sitemap.xml file: #!/bin/bash cd /home/me/sitemap/www/ lynx -crawl -traversal -accept_all_cookies -connect_timeout=30 http://www.compmiscellanea.com/ > / dev/null cd /home/me/sitemap/www2/ lynx -crawl -traversal -accept_all_cookies -connect_timeout=30 http://compmiscellanea.com/ > /dev/null cat /home/me/sitemap/www2/traverse.dat >> /home/me/sitemap/www/traverse.dat cat /home/me/sitemap/www/traverse.dat | sed -e "s/\ \.//g" | sort | uniq > /home/me/sitemap/sitemap/sitemap.xml sed -i "s/\&/\&\;/g" /home/me/sitemap/sitemap/sitemap. xml sed -i "s/"/\&apos\;/g" /home/me/sitemap/sitemap/sitemap.xml sed -i "s/"/\"\;/g" /home/me/sitemap/ sitemap/sitemap.xml sed -i "s/>/\>\;/g" /home/me/sitemap/sitemap/sitemap.xml sed -i "s//" /home/me/sitemap/sitemap/sitemap.xml sed -i -e "s/$/<\/loc><\/url>/" /home/me/sitemap/sitemap/sitemap.xml sed -i -e "1 i\r\r \r\r\r\r" /home/me/sitemap/sitemap/sitemap.xml sed -i -e "$ a \\r" /home/me/sitemap/sitemap/sitemap.xml sed -i "/static/d" /home/me/sitemap/sitemap/sitemap.xml echo "...Done" After the bash script file ready: "chmod +x sitemap.sh" to make it executable. Download sitemap.sh in the archive sitemap.sh.tar.gz (After the archive is downloaded and unpacked, replace http://www.compmiscellanea in the file .com/ with the desired domain name of the site with "www" and replace http://compmiscellanea.com/ with the desired domain name of the site without "www". Instead of "static" in the last line of the file, put the line that the links should contain, so that they have been removed from the list. Then "chmod +x sitemap.sh". Then run sitemap.sh). Comments Download sitemap2.sh with line-by-line comments in the sitemap2.sh.tar.gz archive. Before running the bash script, you need to create three folders. Since the lynx browser in some cases may miss some links if the site's domain name is specified with or without "www", the bash script runs lynx twice, processing the site by domain name with "www" and processing the site using a domain name without "www". The resulting two files are placed in two different folders, here they are "/home/me/sitemap/www/" and "/home/me/sitemap/www2/". And the directory "/home/me/sitemap/sitemap/" is intended for the created sitemap.xml. 1. Path to bash #!/bin/bash 2. Go to the folder - the lynx browser will place there the files received when processing the site by domain name with "www" cd /home/me/sitemap/www/ 3.

There is no "float: bottom" property in CSS, but the effect can be achieved in several other ways. Example: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Link 1 Link 2 Link 3 Float bottom HTML / XHTML. Code:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Float bottom
CSS. Code: .box1 (position: relative; top: 0px; left: 0px; float: left; height: auto; width: 100%;) .content1 (position: relative; top: 0px; left: 0px; float: left; height: auto; width: 100%;) .left1 (position: relative; top: 0px; left: 0px; float: left; height: auto; width: 64%;) .menu1 (position: relative; top: 0px; left: 0px; float: left; height: auto; width: 36%;) .bottom1 (position: absolute; bottom: 0px; right: 0px;) /* Additional CSS, just to give the example some appearance */ . box1 (color: #ddd; text-align: center;).content1 (background: #bbb;).left1 (min-height: 100px; padding: 2%; text-align: justify; background: #006; -moz -box-sizing: border-box; -webkit-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box;).menu1 (padding: 2%; float: right; background: #060; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box;) . menu1 p (position: relative; top: 0px; left: 0px; float: left; height: auto; width: 100%; padding: 0px; margin: 0px;).menu1 a (color: #ddd; text-decoration: none;).menu1 a:hover (text-decoration: underline;).bottom1 (padding: 2%; color: #eee; background: # 600;) All content of the web page is contained in the box1 container. Inside it are two div containers: 1. content1 with the actual content on the left and a menu on the right. 2. bottom1 after content1.

If tables could adapt well to different screen resolutions, then humanity would still be making table layouts to this day. I still found that time and I know what I’m talking about.

However, we live in a different time, table layout has sunk into oblivion, but the need to use classic tables on websites still remains. Therefore, we will not deny the existence of tables, but rather learn about the simplest method, how to make a table responsive.

Responsive table demo .

HTML markup



























































Name Surname Points Points Points Points Points Points Points Points Points Points
Julia Smirnova 50 50 50 50 50 50 50 50 50 50
Evelyn Yakovleva 94 94 94 94 94 94 94 94 94 94
Andrey Petrov 67 67 67 67 67 67 67 67 67 67

We created a simple HTML table, as long as it fits on the screen, everything is OK. When the screen width is reduced, the table will be cut off and we will not see its data, or it will become very small and we will again not see anything.

You probably noticed that I placed the table inside the tag div and obviously for a reason. The tag itself div does not give anything until we assign styles to it.

CSS styles

By setting just one property, the table adapts, a horizontal scrollbar will automatically appear when the content is inside the tag div will no longer fit into the current screen width along the axis X.

Div(
overflow-x: auto;
)

Let's style the rest of the table tags:

Table (
border-collapse: collapse; /* Show only single lines */
border-spacing: 0; /* Distance between cells */
width: 100%;
border: 1px solid #afb42b;
color: #212121;
}

Th, td (
text-align: left;
padding: 8px;
}

Tag styling tr(row) deserves a separate comment. It has already become the norm for table rows to have a striped appearance (zebra). A pseudo-class is used for this :nth-child with meaning in brackets even. Meaning even, assigns properties to all even elements, in our case this is the background color. Thus, the table will be striped.

In Aspro: Next, starting from version 1.1.7, you can adapt tables for the mobile version. It is necessary to make changes to the source code of the page - add a class that is responsible for the adaptability of tables.

A simple table in the mobile version goes beyond the page.

To make the table responsive, go to edit the page where the table was added. Then go to source code editing mode.

Before the opening tag

add a tag with a class
.

After the closing tag

enter the tag