Creating a DIV with vertical scroll-bars exclusively for lengthy paragraphs in HTML: What's the best approach?

I need to display terms and conditions on my website without using a text field or taking up the entire page. Instead, I want to show the text in a specific area with only a vertical scroll bar for users to navigate through the content.

Here is the current code I am using:

<div style="width:10;height:10;overflow:scroll" >
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
</div>

There are two issues with this approach:

  1. The width and height of the div element do not adjust to fit all the text properly.
  2. A horizontal scroll bar appears when it should not be visible.

Answer №1

To apply a vertical overflow to an element, you can utilize the overflow-y CSS property which is part of CSS 3.

Answer №2

To eliminate the horizontal scrollbars from view, simply adjust the overflow-x property to hidden in your CSS:

overflow-x: hidden;

Answer №3

To ensure proper display, make sure to specify the width and height in px:

width: 10px; height: 10px;

Additionally, you can utilize overflow: auto; to prevent the horizontal scrollbar from appearing.

Here is a suggestion on how to implement these properties effectively:

<div style="width:100px; height:100px; overflow: auto;" >
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
</div>

Answer №4

To contain any overflow, I recommend setting overflow-x to hidden and incorporating max-height to restrict the height expansion of the div. Your updated code will appear as follows:

overflow-y: scroll;
overflow-x: hidden;
max-height: 450px;

Answer №5

Firstly, I wanted to express my gratitude.

I found that using the overflow:auto property resolved the issue for me.

The horizontal scroll bar vanished completely after implementing this solution.

Answer №6

If you want to display a vertical scroll bar within your div, simply include the following CSS:

height: 100px;   
overflow-y : scroll;

Alternatively, you can use:

height: 100px; 
overflow-y : auto;

Answer №7

overflow-y : scroll;
overflow-x : hidden;

height can be omitted if desired

Answer №8

To implement a vertical scroll bar on an element, you can utilize the overflow property

style="overflow-y: auto; max-height: 300px; width: 60%;"

Answer №9

When encountering a similar challenge, I found success by following these steps:

        .scrollBbar 
        {
        position:fixed;
        top:50px;
        bottom:0;
        left:0;
        width:200px;
        overflow-x:hidden;
        overflow-y:auto;
       }

Answer №10

Check out the mix I've created:

overflow-y: scroll;
height: 13em; // Starting height.
resize: vertical; // Users can adjust the vertical size.
max-height: 31em; // Limiting the maximum size.

Answer №11

One helpful tip to keep in mind is that the vertical scrollbar can also affect horizontal space. For example, if you have a display set up with width: 100% and not enough content to trigger a vertical scrollbar, everything looks fine. However, once you add more content and the vertical scrollbar appears as expected, you may notice an additional horizontal scrollbar emerge. This occurs because the vertical scrollbar itself occupies some horizontal space, prompting the appearance of the horizontal scrollbar to allow scrolling beneath it. To avoid this issue, consider reducing the width setting. For instance, using width: 95% instead would eliminate the horizontal scrollbar, leaving only the vertical one visible.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing v-for and CSS Grid to showcase data effectively

I'm having trouble organizing my Vuex data with CSS GRID. It's turning out messy. My setup includes two columns: the first one for labels and the second for values. {{$store.state.stepOne.textfield[idx].label}} The code above is used to displa ...

Showing Information without NgFor Directives

I have successfully displayed data without using a ngFor loop. However, it is currently showing all the quote information from multiple customers. The CSS is arranged in such a way that the discount div is positioned next to the customerinfo div. Below is ...

React - Material UI Divider not centered

Is the title says - my divider is not centered in the middle of my text. The current result displays a misalignment: https://i.sstatic.net/0FjKN.png However, I am aiming for my divider to be placed in the center like this (refer to red line): https://i. ...

Issue with random pages where global header.php is not showing a specific image

I'm currently revamping a website that was originally developed using codeigniter. The backend is quite chaotic with no clear identifiers for anything. I recently updated the banner in the header.php file, adjusting the style to suit the requirements. ...

Enhancing the functionality of radio buttons through event changes and optimizing related features

I am searching for a more efficient method to reuse functions that serve a similar purpose. For example, I would like to modify various radio buttons that toggle a hide class on different divs. JSFiddle Link How can jQuery be used to create a reusable fu ...

Adding class names dynamically to div elements using jQuery can enhance the interactivity and styling of a webpage

I need to dynamically add a class name to multiple divs using jQuery. Specifically, I have 10 divs in mind. <div class="sec"></div> <div class="sec"></div> <div class="sec"></div> <div class="sec"></di ...

limited growth of float variable

I am utilizing CSS code to create column a and column b, using float in the code to dynamically expand column a as content is added to column b. However, this expansion is not occurring as expected. To see my code, please visit http://jsfiddle.net/hadinetc ...

What is the correct method of implementing the "OnChange" event to a WooCommerce select element?

My task is to include the onchange="myFunction()" in the select menu below. However, because the select menu is part of woocommerce, I want to ensure that the onchange="myFunction()" remains intact even after updating my theme. How can I achieve this goal ...

Exploring Web Scraping Through Dual System Security

I come seeking guidance on how to navigate a website with two different security systems in place. The first system requires a username and password, which I have successfully managed to handle. However, the second security system only requires a password ...

Folding without extending

My button has a div inside it with content. I've set it up so that when the div is clicked, the collapsed content expands. The hover effect changes color and pointer as expected. But for some reason, clicking on the div doesn't expand the content ...

How can I ensure that the Hamburger menu fully covers the entire viewport when it is open?

My hamburger menu is fully functional using CSS alone. However, when the menu opens, it doesn't fill the entire screen as I would like. Currently, my page content appears below the open menu, creating a cluttered look. https://i.sstatic.net/EtTsr.png ...

What could be causing me to see a basic checkbox instead of a toggle switch in my React application?

I've been attempting to create a toggle switch that activates dark mode using Bootstrap switches, but when I save the code, it reverts back to a basic checkbox. According to the documentation, for older assistive technologies, these switch elements wi ...

Is there a way to embed an AJAX submit form into a notification without the need for page refresh?

I have integrated the jQuery plugin toastr js () for notifications on my website. I am facing an issue where I want to include a contact form within the notification popup and submit it using AJAX. Despite having the form working fine outside of the toastr ...

Double Row Navbar Struggles in Bootstrap 4

I have been experimenting with creating two bootstrap navbars. The first one features the website's domain name in the center, accompanied by a dropdown menu to navigate to other sections. Each of these sections has its own subbar containing specific ...

Is there a way for me to view the output of my TypeScript code in an HTML document?

This is my HTML *all the code has been modified <div class="testCenter"> <h1>{{changed()}}</h1> </div> This is my .ts code I am unsure about the functionality of the changed() function import { Component, OnInit } f ...

Updating existing text to create personalized HTML dropdown menus

I have designed a unique set of dropdowns by using divs and checkboxes instead of the traditional elements My goal is to dynamically change the 'select-wrapper--title' text (e.g. the first option) based on the selected option in the dropdown I ...

Having trouble accessing the value of an item in a dropdown box on a website

I am currently developing a webpage using HTML5 and Knockout Js. I am facing an issue where I am unable to retrieve the ID of the selected item from a dropdown box in order to insert a value into an SQL table. As an example, consider the following SQL tab ...

Having difficulty adjusting the padding of the Material UI table

I have been using the Table component provided by the material-ui library in my React project. However, I have encountered an issue where each row, including the header, has a padding of 24px on the top and bottom that I am unable to modify or overwrite. D ...

Unable to retrieve file on Linux system through PHP

<?php // Ensuring that an ID is provided include('include/function.php'); if(isset($_GET['id'])) { // Retrieving the ID $id = intval($_GET['id']); // Validating the ID if($id <= 0) { die('Th ...

Issue with Angular: Mobile view toggle button in the navbar is unresponsive

While the dropdowns are functioning correctly in web mode, the navbar toggle isn't working as expected in small screens or mobile mode. I've been trying to figure out the issue by referring to code from CodePen that I am learning from. Despite i ...