What is the best way to include a scroll bar in a calendar day when the content exceeds the predefined height limit?

My goal is to create a calendar with fixed width and height, where if the content within a day exceeds the allotted space, a scroll bar will appear inside that specific day.

I have been attempting to restrict the height of each day on the calendar, but allow for a scroll bar to appear if the content overflows beyond that limit. Here is my current code:

td {
  border: 1px solid #ccc;
  text-align: center;
  vertical-align: top;
  padding: 10px;
  height: 100px;
}

When I tried adding a scroll bar using display: block; and overflow-y: scroll;, it did not achieve the desired outcome:

td {
  border: 1px solid #ccc;
  text-align: center;
  padding: 10px;
  height: 100px;
  display: block;
  overflow-y: scroll;
}

The result was not what I expected:

https://i.sstatic.net/x4zTs.png

Therefore, I am seeking advice on how to properly add a scroll bar to days with content that exceeds the set height limit.

Answer №1

By setting the td element to have a display: block property, you can alter its behavior.

I recommend wrapping the content of the table cell within another div and adjusting the width, height, and overflow properties on the div instead of the td.

This approach ensures that the table elements maintain their intended functionality.

Here is an example illustrating this concept.

Answer №2

According to the information found in the MDN documentation regarding the values of the overflow-y CSS property:

scroll: Content will be clipped if it needs to fit vertically within the padding box. Scrollbars will always be displayed by browsers, even if no content is actually clipped. This ensures that scrollbars do not appear or disappear when the content changes. However, printers may still print any overflowing content.

auto: The behavior depends on the user agent being used. If the content fits inside the padding box, it appears as visible but still creates a new block-formatting context. Desktop browsers will show scrollbars if the content overflows beyond the box.

Therefore, using auto would be more appropriate if you want the scrollbars to only appear when the content is truly clipped.

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

Delete the child element if it is present in an HTML document

removeConnection(event) { let parentElement = document.getElementById('RemoveElement'); let childElement = document.getElementById(event.target.id); parentElement.removeChild(childElement); } Whenever I try to remove the child ...

Ajax request results in a 400 error code

Here is the structure of my Ajax call: function Submit() { var objectData = { email: $("#email").val(), firstName: $("#firstName").val(), lastName: $("#lastName").val(), loginMode: $("#login ...

What could be causing the malfunction of the Bootstrap-3 Modal?

<div class='container row'> <div style='padding-top:2em;' class='col-md-4 col-sm-4 col-xs-4'> <img data-toggle='modal' href='#modal-id' src='img/".$row_now[' image ']."&a ...

bourbon neat quadrilateral layout

Attempting to revamp someone else's messy, yet effective, CSS3 template into a more organized format. The transition to bourbon/neat has been smooth, but I'm facing a roadblock when it comes to creating a responsive image grid. <section class ...

Implementing multiline ellipsis without relying on -webkit-line-clamp

Content is dynamically loaded in this p tag. I am looking to implement text ellipsis after a specific line (for example, show text ellipsis on the 4th line if the content exceeds). p { width: 400px; height: 300px; text-align: justify; } <! ...

Best method to determine if three points in time are less than thirty minutes apart

In the form, there are 3 date/time input boxes with a requirement that the user cannot select times within half an hour of each other. I successfully converted all values to epoch format using a Javascript version of strtotime. However, I am unsure how to ...

Python: The soup/parser module is unable to locate the element with the id "div"

I am facing a challenge locating anything within the "div" with the id "bbOffers" (including the div itself) on this particular page: from bs4 import BeautifulSoup from urllib.request import urlopen url = "https://lubimyczytac.pl/ksiazka/5076165/fute ...

Ways to create distance between 2 select elements with CSS?

Having trouble with the spacing between two select fields on a form? Specifically, you want the start time, start time meridian, end time, and end time meridian all in a single line. Any suggestions or solutions to this issue would be greatly appreciated! ...

The Info button in Bootstrap5 is sporting a sleek combination of blue background and black text, deviating from the traditional blue and

Check out my full code for the Random Quote Generator Project on Codepen: here I implemented Bootstrap5 from this link: Bootstrap CDN. The button style btn-info is not displaying correctly in my project. I'm puzzled and would like to understand why ...

Applying CSS to Dynamic JavaScript Elements: A Guide to Styling Without In-line Code

I'm a beginner in web development and I've been experimenting with applying styles to dynamically generated div elements using JavaScript. So far, I've only been able to manually add inline styling through this function: function applyStyle( ...

Using dynamic classes within a v-for loop

Edited How can I dynamically assign classes to multiple elements within a v-for loop? Since I cannot utilize a computed property due to the presence of v-for, I attempted using a method by passing the index of the element, but that approach did not yield t ...

What is causing the z-index to not function properly on my elements?

In my current code setup, I have positioned the hero image at the bottom with an overlay on top that contains text and a button. Additionally, there is a navigation bar with a z-index applied. However, I am facing an issue where the button for viewing my r ...

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 ...

Achieve vertical center alignment of elements within the sticky-top class using Bootstrap 4

I have been attempting to center elements within a div using the sticky-top class, but so far, I have not been successful. I have tried using the following classes: d-flex justify-content-center align-items-center flex-column body, html { height: 100 ...

Unable to locate the React Native variable named "NetworkStatus"

I have been working on implementing a code to test internet connectivity using react native NetInfo from '@react-native-community/netinfo'. Unfortunately, I keep running into an error that says "Can't find variable: connectionStatus&quo ...

Saving the accurate x and y coordinates into the database

My website features draggable images that each have their own x and y positions. I am attempting to pass these values into a MySQL database, but I'm facing an issue where all the images are getting assigned the same x and y values in the database. In ...

Issues related to javascript in Oracle ADF application

Recently, I've been facing a perplexing issue. My custom JavaScript file functions flawlessly until I execute any ADF's JS action. For instance, when I trigger an action that slides down a component, everything works as expected. However, the mom ...

What occurs when you use the statement "import someModuleName from someModule" in JavaScript?

When reusing a module in multiple places, you typically use module.exports = yourModuleClassName to make the module exportable. Then, when you want to use it elsewhere, you can simply import it with import yourModuleClassName from 'yourmodulePath&apos ...

Switching between menu options and buttons

My game has a menu for selecting the class. Each class has its own button - Knight, Mage, Archer. I want to use jquery so that when any of these buttons are clicked, a new set of buttons appears to choose the race. I tried using .replaceWith() but it does ...

Include a requirement within an application/ld+json formatted script

I have a task to create an application using a script in the js+json format. It is crucial to include the person schema, which signals to Google and other search engines how to effectively interpret the structure of the page and its content. My current cod ...