Html div com scroll

How to Make a Div Vertically Scrollable

CSS allows us to make a vertically scrollable. It can be easily done by using the overflow property. The overflow property has different values. E.g., overflow: auto; and an axis hiding procedure like overflow-x: hidden; and overflow-y: auto; will make a bar scrollable vertically and horizontally, and the «auto» value will add only a vertically scrollable bar.

For a scrollable bar, use the x and y-axis. Set the overflow-x: hidden; and overflow-y: auto; to automatically hide the horizontal scrollbar and show a vertical scrollbar.

Let’s see an example, where the is vertically scrollable.

Create HTML

body> h2>W3docsh2> div Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when a n unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. div> body>

Add CSS

  • Set the background-color, width, and height properties for the element.
  • Use the overflow-x property to specify whether the content must be hidden, visible or scrolling horizontally when the content overflows the element’s left and right edges. Set the «hidden» value.
  • Use the overflow-y property to specify whether the content must be hidden, visible or scrolling vertically when the content overflows the element’s top and bottom edges. Set the «auto» value.
  • Use the text-align property with its «center» value.
div.scroll < background-color: #fed9ff; width: 600px; height: 150px; overflow-x: hidden; overflow-y: auto; text-align: center; padding: 20px; >

Let’s bring the parts together and see the whole code!

Читайте также:  Fonts names in java

Example of making a vertically scrollable using the overflow-x and overflow-y properties:

html> html> head> title>Title of the document title> style> div.scroll < background-color: #fed9ff; width: 600px; height: 150px; overflow-x: hidden; overflow-y: auto; text-align: center; padding: 20px; > style> head> body> h2>W3docs h2> div class="scroll"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. div> body> html>

Result

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy.

Читайте также:  Get post keys php

Example of making a vertically scrollable using the overflow property:

html> html> head> title>Title of the document title> style> div.scroll < background-color: #fed9ff; width: 600px; height: 150px; overflow: auto; text-align: justify; padding: 20px; > style> head> body> h2>W3docs h2> div class="scroll"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. div> body> html>

Источник

How to Make a Div Scrollable in HTML

In this post, we will go over how to make an HTML scrollable div. To do this we will use the CSS overflow property and set its value to either scroll or auto.

.scrollable-div1 < overflow: scroll; >.scrollable-div2

The main difference between overflow: scroll and overflow: auto is that scroll will always show the scroll bars, where auto will only show them when needed.

Let’s say I have the following HTML:

If we want to make “#div1” scrollable in the example above, we would need to set its CSS overflow property to scroll, and usually give it a fixed height and width.

Examples of HTML Scrollable divs

This first example will just show a simple HTML scrollable div.

The code above will produce the result below:

This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.

Читайте также:  Python file list example

If we want to get rid of the horizontal scroll bar, we can just use the overflow-y property instead of overflow, and set it to scroll.

The code above will produce the result below:

This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.

HTML scrollable div with Dynamic Content

Our final example will show how we can use a scrollable div to only show the scroll bar when more content is added to the scrollable div.

Let’s say I have the following HTML:

#div5 

Keep clicking the button below to add enough divs to show the scrollbar.

We will then use the jQuery appendTo() method to keep adding HTML divs to our scrollable div.

$("#click-me").click(function()< $('
').appendTo("#div5"); >);

The final code and output for this example of how to have an HTML scrollable div is below:

Keep clicking the button below to add enough divs to show the scrollbar.

 #div5 

Keep clicking the button below to add enough divs to show the scrollbar.

Hopefully this article has helped you to understand how to make an HTML scrollable div.

  • 1. What is the Correct HTML for Making a Text Area?
  • 2. What is the Correct HTML for Making a Drop-Down List?
  • 3. What is the Correct HTML for Inserting a Background Image?
  • 4. How Do You Select All p Elements Inside a Div Element?
  • 5. HTML subscript – How to Lower Text in HTML
  • 6. How to Call a JavaScript Function From HTML
  • 7. HTML span width – Set the Width of a Span in HTML
  • 8. Clicking on an Image to Enlarge it in HTML
  • 9. How to Filter a List of Divs with a Text Input Bar Using Javascript
  • 10. What Type of HTML List will Automatically Place a Number in Front of the Items?

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Источник

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