Add a table table to the article

WordPress twenty-one 5.4K Reading mode

 

 Add a table table to the article

Adding tables to the theme of responsive design has always been a problem. Here are two imperfect examples for your reference:

Example 1 The part of the table that exceeds the page width is hidden, and use the scroll slider to view the hidden part

When editing an article, switch to text mode and add the following code:

  1. < div   class = "table-container" >
  2.      < table >
  3.          < tbody > < tr >
  4.              < th > Header 1 </ th >
  5.              < th > Header 2 </ th >
  6.              < th > Header 3 </ th >
  7.              < th > Header 4 </ th >
  8.              < th > Header 5 </ th >
  9.              < th > Header 6 </ th >
  10.              < th > Header 7 </ th >
  11.              < th > Header 8 </ th >
  12.          </ tr >
  13.          < tr >
  14.              < td > row1_cell1 </ td >
  15.              < td > row1_cell2 </ td >
  16.              < td > row1_cell3 </ td >
  17.              < td > row1_cell4 </ td >
  18.              < td > row1_cell5 </ td >
  19.              < td > row1_cell6 </ td >
  20.              < td > row1_cell7 </ td >
  21.              < td > row1_cell8 </ td >
  22.          </ tr >
  23.          < tr >
  24.              < td > row2_cell1 </ td >
  25.              < td > row2_cell2 </ td >
  26.              < td > row2_cell3 </ td >
  27.              < td > row2_cell4 </ td >
  28.              < td > row2_cell5 </ td >
  29.              < td > row2_cell6 </ td >
  30.              < td > row2_cell7 </ td >
  31.              < td > row2_cell8 </ td >
  32.          </ tr >
  33.          < tr >
  34.              < td > row3_cell1 </ td >
  35.              < td > row3_cell2 </ td >
  36.              < td > row3_cell3 </ td >
  37.              < td > row3_cell4 </ td >
  38.              < td > row3_cell5 </ td >
  39.              < td > row3_cell6 </ td >
  40.              < td > row3_cell7 </ td >
  41.              < td > row3_cell8 </ td >
  42.          </ tr >
  43.      </ tbody > </ table >
  44. </ div >

Add the corresponding style to the theme style.css

  1. table {
  2.      margin : 0;
  3.      border-collapse collapse ;
  4. }
  5. td, th {
  6.      padding : .5em 1em;
  7.      border 1px   solid   #999 ;
  8. }
  9. .table-container {
  10.      width : 100%;
  11.      overflow -y:  auto ;
  12.     _overflow:  auto ;
  13.      margin : 0 0 1em;
  14. }
  15. .table-container::-webkit-scrollbar {
  16.     -webkit-appearance:  none ;
  17.      width 14px ;
  18.      height 14px ;
  19. }
  20. .table-container::-webkit-scrollbar-thumb {
  21.      border -radius:  8px ;
  22.      border 3px   solid   #fff ;
  23.      background-color : rgba(0, 0, 0, .3);
  24. }

Source code from: http://caibaojian.com/simple-responsive-table.html

Example 2 . Use CSS media to query. When the screen is less than 600px, take out the td attribute value and display it in the content area.

Use the same method as in Example 1.

  1. < table >
  2.    < thead >
  3.      < tr >
  4.        < th > payment </ th >
  5.        < th > date </ th >
  6.        < th > amount of money </ th >
  7.        < th > cycle </ th >
  8.      </ tr >
  9.    </ thead >
  10.    < tbody >
  11.      < tr >
  12.        < td   data-label = "Payment" > Payment # 1 </ td >
  13.        < td   data-label = Date > 02/01/2015 </ td >
  14.        < td   data-label = Amount > $2,311 </ td >
  15.        < td   data-label = Period > 01/01/2015 - 01/31/2015 </ td >
  16.      </ tr >
  17.      < tr >
  18.        < td   data-label = "Payment" > Pay # 2 </ td >
  19.        < td   data-label = Date > 03/01/2015 </ td >
  20.        < td   data-label = Amount > $3,211 </ td >
  21.        < td   data-label = Period > 02/01/2015 - 02/28/2015 </ td >
  22.      </ tr >
  23.    </ tbody >
  24. </ table >

Matching style:

  1. table {
  2.     border: 1px solid #ccc;
  3.     width: 80%;
  4.     margin: 0;
  5.     padding: 0;
  6.     border-collapse: collapse;
  7.     border-spacing: 0;
  8.     margin: 0 auto;
  9. }
  10. table tr {
  11.     border: 1px solid #ddd;
  12.     padding: 5px;
  13. }
  14. table th, table td {
  15.     padding: 10px;
  16.     text-align: center;
  17. }
  18. table th {
  19.     text-transform: uppercase;
  20.     font-size: 14px;
  21.     letter-spacing: 1px;
  22. }
  23. @media screen and (max-width: 600px) {
  24.     table {
  25.         border: 0;
  26.     }
  27.     table thead {
  28.         display: none;
  29.     }
  30.     table tr {
  31.         margin-bottom: 10px;
  32.         display: block;
  33.         border-bottom: 2px solid #ddd;
  34.     }
  35.     table td {
  36.         display: block;
  37.         text-align: right;
  38.         font-size: 13px;
  39.         border-bottom: 1px dotted #ccc;
  40.     }
  41.     table td:last-child {
  42.         border-bottom: 0;
  43.     }
  44.     table td:before {
  45.         content: attr(data-label);
  46.         float: left;
  47.         text-transform: uppercase;
  48.         font-weight: bold;
  49.     }
  50. }

Source code from: http://www.webhek.com/responsive-tables-in-pure-c ss

The above methods are only suitable for relatively simple tables. Copying from Excel to include dimension styles in table codes cannot be adaptive.

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments twenty-one    Visitors twenty-one
    •  Online earning blog
      Online earning blog one

      Thanks for sharing

      •  I love sports bike network
        I love sports bike network seven

        Learned, :arrow: How to add a form to the article? I have never been able to do so. I am very depressed about it!

          •  I love sports bike network
            I love sports bike network seven

            @ I love sports bike network I have always wanted to create a combination of "recently published+popular articles+category directory+tag cloud" for my blog in the right column, but it is impossible for technology to do so. Can bloggers share when and how the sidebar implements tab technology? thank you!

          •  Koolight
            Koolight four

            So far, it seems that no tables have been added to the article.

            •  Boke112 navigation
              Boke112 navigation five

              It seems that there are some tools that can be converted into adaptive tables, but this one is seldom used. It's OK to do some manual work

              •  Summer Blog
                Summer Blog three

                I edit the table directly in dw, and then copy it to the wp editor.

                •  Ink, water bottle
                  Ink, water bottle four

                  Not bad, like one
                  BootStrap Table can also be adaptive

                  •  aunsen
                    aunsen five

                    Brother Bird, it rains in time

                    •  namesilo
                      namesilo zero

                      Universal wp. It would be better if you could edit the statistical chart directly.

                      •  Pseudo geek
                        Pseudo geek four

                        Uncle Bird's theme is very fast

                        •  Handsome little Qiqi
                          Handsome little Qiqi five

                          In fact, it is more appropriate to write this as a short code

                          •  Yang Zeye
                            Yang Zeye two

                            I found a serious problem with this blog theme. It's just that what I bought is not the official genuine (mainly because I can't bear to pay so much). Anyone who is online can test it with me. I think there are also official genuine 299

                            •  Meteor Shower Blog
                              Meteor Shower Blog zero

                              Leave a message! two hundred and thirty-three

                              •  Laogao Crown Club
                                Laogao Crown Club zero

                                Will too many forms in the website affect the collection of the website

                                •  Idle fish
                                  Idle fish one

                                  You can simply use the online editor to make a table, and then copy it into the text editor

                                  •  Pseudo geek
                                    Pseudo geek four

                                    Learning mark

                                    •  Picking Notes
                                      Picking Notes one

                                      Haha, in fact, you can use Baidu's "html online editor" to generate tables with the table tools inside, which should be adaptive. :grin:
                                      I use this: http://zaixianwangyebianji.51240.com/
                                      effect: https://www.needsth.wang/ougishi.html

                                      •  Fanbaohui Blog
                                        Fanbaohui Blog zero

                                        This is easy to use

                                        •  Chemical plant smoke exhaust system
                                          Chemical plant smoke exhaust system one

                                          Thanks for sharing~

                                         anonymous

                                        Comment

                                        Anonymous netizens
                                         :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

                                        Drag the slider to complete validation