Css скроллинг для таблицы

Making Tables Scrollable in CSS

Because HTML tables are set to display: table by default, adding scrollbars to them is a bit nonintuitive.

We can set our tables to display: block and modify their overflow from there, but I’ve found wrapping tables in containers to be more adaptable and flexible.

Vertical table scrollbars

First, let’s set up vertical scrolling.

div class="tableContainer"> table class="table"> . table> div> 

We can set a height for the table’s container and modify the table such that it will fit snug within the container:

.tableContainer < height: 300px; overflow: hidden; > .table < position: sticky; top: 0; width: 100%; > 

In this example, I set the height to 300px — but you can set it to whatever you want!

Our table will now have an inset vertical scrollbar and will expand no further than the height we set.

Horizontal table scrollbars

If you want to implement horizontal scrolling, there is an approach very similar to the vertical scrolling example:

.tableContainer < overflow: hidden; width: 800px; > .table < position: sticky; top: 0; width: 100%; > 

I set the width here to 800px , but again, you can change it to whatever you want.

If you want both horizontal and vertical scrollbars for your table, simply specify both a height and a width in .tableContainer .

And that’s how you can make your tables scrollable with just a bit of CSS!

I refer back to this snippet all the time, and I hope you found it useful too.

Источник

Scrollbar in HTML Table

Scrollbar in HTML Table

Scrollbar in HTML Table is one of the features to scroll the data from horizontal and vertical formats. In default, a vertical scroll bar enables after entering the number of data to maximize size in the vertical mode. But in horizontal mode, after entering the data in paragraph format and not wrapped, the page contains the right arrow as the option to enable the data in the horizontal scroll bar. We have customized the scroll options with the help of mouse pointers. We can also allocate the scroll tables’ border, height, and width.

Web development, programming languages, Software testing & others

Creating a Scrollbar in HTML Table

When the text box’s content is too large to fit in, an HTML Scroll box will ensure that the box grows scroll bars. Some applications, like mobile apps, use scroll boxes, which will display their features, but big mobile screens will display it good some small mobile screens compatibility, it will not display on the screen, i.e.)application feature, which is to be used in the scroll box. Some plugins are needed to show some features in web applications that are to be used in the browser screen. Suppose we want to add a scroll bar option in HTML, use an “overflow” option, and set it as auto-enabled for adding horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.

Читайте также:  Php передача переменных из формы

Using the tag, we will add the scroll options to HTML Page.

Examples of Scrollbar in HTML Table

Given are the examples for the HTML table:

Example #1

    .divScroll  
SivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaramanSivaraman

scrollbar in HTML table

In the above example, we have enabled scrolling in horizontal and vertical bars; scrolls will automatically enable if the text exceeds the text box limits.

Example #2

  .divScroll  
Welcome to my domain

scrollbar in HTML table

In the above example, we used the ; we will show the text within the marquee using the scroll option. We can use animate the text in the scroll bars. Different sets of like Faster Scrolling, Faster Bounce, Text scrolling down, Text Scrolling Up, Jumping Text, Normal Speed, etc., are also used.

Example #3

In the example below, we will use the alert function of how much data will be displayed on the web page in pixel format.

   
Welcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domain

scrollbar in HTML table

Example #4

   
Welcome to my domain Name Email Sivaraman Sivaraman [email protected]

scrollbar in HTML table

Example #5

Here we are going to see the Various Types of Scroll Boxes in HTML

  • Colored Scroll Boxes
  • Customized Scrollbars
  • Scroll box with images
  • Scroll Box with Borders
1. Colored Scroll Boxes

In the scroll box option, we have added the different types of colors in the text box space areas, as shown in the example below:

  
Welcome to my domain.Welcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domainWelcome to my domain

domain

In the above example, we have specified the colors in the text, the same in the scroll panel.

2. Customized Scrollbars

We have customized the scroll bars using Webkit extensions; it will work in the browsers.

    body < margin-bottom: 200%; >.scroll < border: none; padding: 5px; font: 24px/36px sans-serif; width: 200px; height: 200px; overflow: scroll; >::-webkit-scrollbar < width: 12px; height: 12px; >::-webkit-scrollbar-track < border: 1px solid yellowgreen; border-radius: 10px; >::-webkit-scrollbar-thumb < background: yellowgreen; border-radius: 10px; >::-webkit-scrollbar-thumb:hover  
Welcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domainWelcome to My domain

customized scrollbars

In the above codes, we see scroll options on the full page. It’s our customized option; we have enabled the scroll options in the full background screen. Once, we also checked the browser Compatability because sometimes the tool –Webkit in the CSS style does not accept some browsers. For example, Microsoft has the –ms- extensions and other browser vendors like –Webkit- extensions.

3. Scroll Box With Images

We have also used Scroll boxes in background images or foreground images. Let us see some basic examples of this feature.

scroll box images

4. Scroll Box Borders

We have also added the borders in the scroll panel areas. It will appear like highlighted portion Example below:

Welcome to My DomainWelcome to My Domain.Welcome to My Domain.Welcome to My Domain.Welcome to My Domain.Welcome to My Domain.Welcome to My Domain.Welcome to My Domain.

scrollbox borders

The above picture highlights the scroll area. Similarly, we can also add different borders like dotted, dashed, double borders, etc.

Features of Scrollbar in HTML Table

When we use the Scroll box, it may have some features like.,

  • Simple and lightweight
  • Autoplay
  • Multiple instances on one page
  • Useful options for customizing your text in a scrolling
  • We can also use the jquery library in scroll boxes for features like Previous/Next navigation buttons

Conclusion

In General, We have used many features in the HTML language, but the Scroll bar is one of the best features for crisping the data on the web page for displaying the contents. The above examples and points are in basics; meanwhile, we will have many advanced concepts and features in the HTML and CSS with Scroll bar options. The Latest Versions, HTML 5, and CSS 3, may add some options in the text scroll areas.

This article is a guide to the Scrollbar in HTML Table. We discuss creating a Scrollbar in Html Table and some features and examples. You can also go through our other suggested articles to learn more–

89+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5

97+ Hours of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5

HTML & CSS Course Bundle — 33 Courses in 1 | 9 Mock Tests
125+ Hours of HD Videos
33 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5

Источник

How to Create a Table with a Fixed Header and Scrollable Body

In this tutorial, find some methods of creating an HTML table, which has a fixed header and scrollable body. Of course, you need to use CSS.

It is possible to achieve such a result by setting the position property to “sticky” and specifying 0 as a value of the top property for the element.

As usual, you can open the Try it Yourself demo link and play with the properties to understand them better.

You can also read the comments in front of each line to understand the properties better.

Example of creating a table with a scrollable body by using the position property:

html> html> head> title>Title of the document title> style> .tableFixHead < overflow-y: auto; /* make the table scrollable if height is more than 200 px */ height: 200px; /* gives an initial height of 200px to the table */ > .tableFixHead thead th < position: sticky; /* make the table heads sticky */ top: 0px; /* table head will be placed from the top of the table and sticks to it */ > table < border-collapse: collapse; /* make the table borders collapse to each other */ width: 100%; > th, td < padding: 8px 16px; border: 1px solid #ccc; > th < background: #eee; > style> head> body> div class="tableFixHead"> table> thead> tr> th>Col 1 th> th>Col 2 th> tr> thead> tbody> tr> td>1.1 td> td>2.1 td> tr> tr> td>1.2 td> td>2.2 td> tr> tr> td>1.3 td> td>2.3 td> tr> tr> td>1.4 td> td>2.4 td> tr> tr> td>1.5 td> td>2.5 td> tr> tr> td>1.6 td> td>2.5 td> tr> tr> td>1.7 td> td>2.5 td> tr> tr> td>1.8 td> td>2.5 td> tr> tbody> table> div> body> html>

Result

Great! Huh? But let’s face it! I don’t like to see that scrollbar starting from the head section of the table!

So, let’s continue to the next example and fix that issue together!

Thers’s another method of creating a table with a fixed header and scrollable body. In the example below, we set the display to “block” for the element so that it’s possible to apply the height and overflow properties.

Example of creating a table with a scrollable body by using the display property:

html> html> head> title>Title of the document title> style> .fixed_header < width: 400px; table-layout: fixed; border-collapse: collapse; > .fixed_header tbody < display: block; width: 100%; overflow: auto; height: 100px; > .fixed_header thead tr < display: block; > .fixed_header thead < background: black; color: #fff; > .fixed_header th, .fixed_header td < padding: 5px; text-align: left; width: 200px; > style> head> body> table class="fixed_header"> thead> tr> th>Col 1 th> th>Col 2 th> th>Col 3 th> th>Col 4 th> th>Col 5 th> tr> thead> tbody> tr> td>1 td> td>2 td> td>3 td> td>4 td> td>5 td> tr> tr> td>6 td> td>7 td> td>8 td> td>9 td> td>10 td> tr> tr> td>11 td> td>12 td> td>13 td> td>14 td> td>15 td> tr> tr> td>16 td> td>17 td> td>18 td> td>19 td> td>20 td> tr> tr> td>21 td> td>22 td> td>23 td> td>24 td> td>25 td> tr> tbody> table> body> html>

As mentioned before, we used overflow: auto on the tbody along with the display: block .

Here’s our result, and enjoy the difference!

Col 1 Col 2 Col 3 Col 4 Col 5
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

As you have noticed, we didn’t use borders in the previous examples. However, if you need to add borders, you can simply use border property on all td tags.

.fixed_header td < border: 1px solid #797878; >
Col 1 Col 2 Col 3 Col 4 Col 5
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

Источник

Оцените статью