Display the scroll bar in HTML only when the content exceeds the maximum height

I am trying to display a scrollbar only if the content is larger than the specified max-height. However, it seems that the scrollbar is always enabled.

<div style="text-align: left; font-size: 1.5rem; max-height: 7rem; overflow-y: auto;">
          Some text
        </div>

Here is an example image of my case:

https://i.sstatic.net/0w0LE.png

Answer №1

It's recommended to utilize vh instead of rem for relative height, as rem is primarily used for specifying font size:

Check out this Unit-Reference for more information.

div {
  text-align: left;
  font-size: 1.5rem;
  max-height: 10vh;
  overflow-y: auto;
  border: 1px solid red;
}
<div>
  Some text Before Oracle9 if I had "select any table" privileges there was no problem doing so. ... allow direct access to the v$ tables, do not allow access by stored procedures ... I don't think O7_DICTIONARY_ACCESSIBILITY provides access to sys.link$
  ... Before Oracle9 if I had "select any table" privileges there was no problem doing so. ... allow direct access to the v$ tables, do not allow access by stored procedures ... I don't think O7_DICTIONARY_ACCESSIBILITY provides access to sys.link$ ...
  https://jsfiddle.net/Manju06/3zshy8r0/34/ Before Oracle9 if I had "select any table" privileges there was no problem doing so. ... allow direct access to the v$ tables, do not allow access by stored procedures ... I don't think O7_DICTIONARY_ACCESSIBILITY
  provides access to sys.link$ ...
</div>

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

Running JavaScript code on a webpage using Selenium

I'm currently developing an automated script to enter a person's address details on a webpage. It's important to note that I did not create this webpage myself. While filling in the address details, I encountered an option to select the coun ...

The showdown: JQUERY $(document).click versus $(document).ready

$(document).ready(function(e) { if ($('#sidebar').hasClass('active')) { $('#dismiss, .overlay').on('click', function() { $('#sidebar').removeClass('active'); $('.overlay&apo ...

Inject HTML content with headers using PDO in PHP

With the power of PHP PDO: I want to generate an HTML table (including thead and tbody) by querying a MySQL database using a select statement. This will be done dynamically, only requiring basic credentials and the name of the table. ...

Styling list items (li) on hover without using the li:

I have a menu where I am using the :after element. When I hover over a li in the menu, the hover effect also includes the :after element. HTML: <ul class="main-menu"> <li class="active"><a href="">Menu</a></li> <l ...

Is there a way to toggle the slide effect of one 'div' without affecting another one?

Hey everyone! I am new to jquery and currently working on a project with two div elements that are slidetoggled. The issue I am facing is that when I open or close one div, the other div also moves along with it. I understand what is happening in the back ...

I have configured my CSS styles in the module.css file of my Next.js application, but unfortunately, they are not being applied

I recently developed a nextjs with electron template application: Here is the link to my code on CodeSandbox: https://codesandbox.io/s/sx6qfm In my code, I have defined CSS classes in VscodeLayout.module.css: .container { width: '100%'; he ...

Internet Explorer will automatically apply a blue border to a div element when a CSS gradient is utilized

I'm attempting to create a gradual fading gray line by using a div that is sized at 1x100px with a CSS gradient applied for the fade effect. The only issue I am encountering is in Internet Explorer where the div is displaying a blue border which I am ...

easy method for creating a hyperlink that triggers a "download" pop-up box

Is there a simple and efficient way to have some of my links trigger the 'save file as' prompt (similar to right-clicking) immediately after they are clicked for the first time? ...

Display a page with sections that have opacity applied, identified by the hashtag #section, and utilize JavaScript to automatically scroll to the top of

Check out my app at . I'm working on overriding the scroll bar behavior in CSS to keep the entire app visible, including the logo, header, and controls, as users navigate through different sections. However, I seem to be having trouble with the CSS as ...

What is the best way to create a grid layout that is responsive using HTML and CSS

I have been searching all over the internet and have not been able to find a grid layout like this. The "grid-template-columns" property is not achieving what I need, as I cannot make one box larger than the others. I am looking to create 4 equal boxes an ...

Is there a way to position labels above their corresponding elements using this customized input style?

My CSS for styled inputs has become too complex, making it difficult to remove and fix certain elements. Specifically, I am facing issues in getting labels positioned above my input fields, select options, and output section. /* Cus ...

Retrieve the input value closest to the selected row

I need to extract the price and currency value of a checked row containing a checkbox. The price is specified in a text box while the currency is selected from a dropdown menu. $(document).ready(function() { $('#test').click(function(){ ...

Extracting targeted information from web pages using Python

I'm a newcomer to python and I'm currently working on an interface. My task is to retrieve the top 250 movies from the IMDb website. def clicked(self): movie=self.movie_name.text() url="https://www.imdb.com/chart/top/" ...

A guide to filling an irregular shape (such as a star) based on a percentage using CSS in a React project

I am currently working on developing a React component that showcases a rating percentage using a star icon with two different shades. For example, if the input rating is 79%, I want to display a star with 79% of it in gold color and the remaining 21% in ...

Components from Bower are currently not available

Trying to automate the injection of bower components into my HTML using grunt-wiredep. It seems simple enough, but I'm having trouble setting the correct path to the bower directory when running localhost. Currently, I'm receiving this error: ht ...

When using jquery.hide() and show(), the content within the div disappears momentarily before reappearing

Hello! I am experiencing an issue where the content of my div disappears after using a jQuery hide() and show() function. It seems to be gone. <li class="gg3"><a class="link" href="#" data-rel="content3">Link1</a></li> <div clas ...

Guide to executing specific functions based on selected dropdown options in Angular 5

Several drop down menus need to be implemented. The requirement is that when an option from the drop-down is selected, a corresponding custom function should be called. However, in the code below, what should replace opt.mtd since it is not functioning as ...

Having Trouble with the Bootstrap Responsive Menu Button Not Working

I'm struggling with the Bootstrap menu I created, as it's not collapsing or animating. Everything seems to be working fine except for the button that isn't functioning. <nav class="navbar navbar-expand-lg navbar-light bg-dark alb ...

Dynamically adjusting CSS Max-Height according to scroll position

Is there a CSS only technique to achieve the following scenario: An element is positioned absolutely at x,y coordinates on the screen. The document includes a vertical scrollbar depending on its content. Can the height of the element be adjusted based on ...

Conceal the bootstrap hamburger icon if there are no navigation items present

I am working on dynamically populating nav-items within a navbar bootstrap component. There are instances where no nav-items are present, and during those times, I would like to hide the hamburger icon in device viewports. I have identified that the class ...