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% |
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: 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: 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/\ 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: 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. 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. 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( Let's style the rest of the table tags: Table ( Th, td ( 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 After the closing tag Save your changes. Now the table scrolls and does not go beyond the frame. When scrolling horizontally, the table does not go beyond the frame, but when scrolling to the right in the mobile version, a side menu opens. To ensure that the menu does not interfere with working with the table, you need to make changes to the page code. You need to add the "swipeignore" class to the tag Save your changes. Now, when scrolling the table to the right, the side menu does not open, which interfered with working with the table. You can hide the side menu when scrolling right and on other pages. You need to add the "swipeignore" class to the tag
:
...
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
1
2
3
Table_data_1
Table_data_2
Table_data_3
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
CSS styles
overflow-x: auto;
)
border-collapse: collapse; /* Show only single lines */
border-spacing: 0; /* Distance between cells */
width: 100%;
border: 1px solid #afb42b;
color: #212121;
}
text-align: left;
padding: 8px;
}
add a tag with a class
enter the tag.
...
a tag with classes must be specified
...
The world of free programs and useful tips
2024 whatsappss.ru