I want to make a calendar with fixed width and height, and if the content in that day is too much, it will have a scroll bar in side the day (Only appear if there have many contents).
I am trying to limit the height of the calendar even if there are content inside each day. However, if the content inside the day is more than the height, it will:
Code:
td {
border: 1px solid #ccc;
text-align: center;
vertical-align: top;
padding: 10px;
height: 100px;
}
When I try to add a scroll bar with display: block;
and overflow-y: scroll;
it become:
Code:
td {
border: 1px solid #ccc;
text-align: center;
padding: 10px;
height: 100px;
display: block;
overflow-y: scroll;
}
But it does give me what I want for that particular day:
SO, how can I add a scroll bar for the day that have longer content than the height?
2
Answers
From the MDN documentation for the values of the
overflow-y
CSS property:Therefore you should be using
auto
if you want the scrollbars only to be displayed when content is actually clipped.Setting the
td
todisplay: block
will change the way thetd
works.I suggest that you add the content of the table cell inside of another
div
and manipulate thewidth
,height
andoverflow
on the div instead of thetd
This way the table elements will act as table elements.
https://jsfiddle.net/tpsznme3/15/