table > tbody {
height: 600px;
display: block;
overflow: auto;
}
table > tbody > tr {
width:100%;
height: 1440px;
display:table;
table-layout:fixed;
}
This css makes a scrollable 'table', or scrollable 'tr'. It WORKS. But my problem is that I have a 'div' inside 'td's inside the 'tr'. And when I set the height of 'div' to 100%, or any height so that the whole 'div' is not within the visible range of tbody, in this case within 600px, the scrollbar for the document appears. The scrollbar for the table is the same with and without 'div'.
The scrollbar of the document extends as long as where the bottom of 'div' should be "behind" the 'tbody'. When I scroll the table, there is NO change to the scrollbar of the document.
Here is a very rough version of my problem: https://jsfiddle.net/hL8hemka/14/
As you can see, there are two scrollbars. If you can't see two, try deleting div { height: 100% } in the css section. You will notice one of two bars on the right (where the document scrollbar should be) disappearing.
How do I make a div with 100% height of tr without scrollbar on the document?
I'm not seeing two scrollbars in your fiddle, unless you mean that there is a horizontal and a vertical scrollbar?
Either way, if you want to hide a scrollbar on any element simply set the overflow-x or overflow-y (depending on if the scrollbar is vertical or horizontal) to hidden. For example, if I wanted to hide a vertical scrollbar I would set overflow-x to hidden in my css like so:
body {
overflow-x: hidden;
}
Just disable the scrollbar:
body
{
overflow: hidden;
}
fiddle
That's because of you have added a border to td, remove that and it fit everything properly. The scrollbar at x-axis hides.
td {
border:none;
}
div {
border: 1px solid #111;
height: 100%; /* Removing this hides the 'document' scrollbar*/
}
If you don't have any other element in the table cells i suggest you to use a different approach.
Instead of set height to the div you can position it as an absolute element. This way you can dimension it using top, left, right and bottom properties.
td {
position:relative;
}
td > div {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
Related
I am trying to make a horizontal menu which consists of a parent div with overflow:hidden and a child with overflow:auto. This allows me to have a scrollable div with no scrollbar.
However, to prevent a break in the li elements, the child element has a white-space:nowrap attribute. This makes the scrollbar appear again.
I tried using a display:table as an alternative to the nowrap but that doesn't allow scrolling.
Any ideas on how to proceed?
Thanks
UPDATE:
Seeing as I have not been able to explain myself correctly, I have uploaded a small example of what I want on jsfiddle: LINK
I want a list of items next to each other which is wider than container and for the user to be able to scroll but without the scrollbar showing. If I have the white-space:nowrap attribute, the scrollbar is present but if I remove it, the elements will go under each other.
Thanks!
#wrapper {
width: 250px;
overflow: hidden;
outline: 1px solid blue;
}
#scroller {
width: 270px;
height: 100px;
overflow: auto;
}
<div id="wrapper">
<div id="scroller">
foo<br>bar<br>baz<br>foo<br>bar<br>baz<br>foo<br>bar<br>baz<br>
foo<br>bar<br>baz<br>foo<br>bar<br>baz<br>foo<br>bar<br>baz<br>
foo<br>bar<br>
Try This One For E.g
I've been working on making a drop-down menu that has a max-height, and puts vertical scrollbars on the element if it exceeds it. For some reason, when this vertical scrollbar is added, the width does not automatically adjust to compensate for the width of the vertical scrollbar, and creates a horizontal one as well.
Here is a fiddle so you can see a simplified version of my problem. Anyone have a good solution (besides setting a width on it, because I want it to adjust to the content inside, and preferably no JavaScript)?
.wrapper { display:inline-block; max-height:200px; overflow-y:auto; background:#f00;}
.wrapper > a { display:inline-block; padding:20px; white-space:nowrap; }
You can use overflow-y:scroll.
.wrapper {
overflow-y:scroll;
overflow-x:hidden;
}
Fiddle: http://jsfiddle.net/4e00dp7w/2/
Note that overflow-x:hidden is not really needed, but just in case.
When the vertical scrollbar is added, it will take some space from inside the container, in this case .wrapper. To avoid this, you can add overflow-x: hidden to your .wrapper. class like this:
.wrapper {
display:inline-block;
max-height:200px;
overflow-y:auto;
background:#f00;
}
However, as i said, it takes space from inside the container, so your content may be overlayed by the scrollbar. A workaround to this problem is adding a little padding to your .wrapper class to compensate this space ocupied by the scrollbar.
.wrapper {
display:inline-block;
max-height:200px;
overflow-y:auto;
background:#f00;
overflow-x: hidden;
padding-right: 10px;
}
Working sample: http://jsfiddle.net/4e00dp7w/7/
I would set...
.wrapper{
overflow-x:hidden;
overflow-y:auto;
}
that way a scroll bar will only show if the inner content is taller than the wrapper.
I am trying to make a div featuring thumbnails to have a set width (330px) and set height (100px), and make it so the content is arranged horizontally, so that a horizontal scroll bar is used to view the content.
Please see the row of thumbnails in the bottom right corner of my website: http://stevenlloydarchitecture.co.nz/building.html
I want to make it so that only four of the thumbnails are visible, and you scroll horizontally to see the others.
However when I try to specify width the thumbnails get moved below each other (as is currently displayed). I tried making a parent Div (with id "slider" in my example) to set the width and height, and have tried as many combinations of specifying width,height and overflow to the divs on the hope of forcing a horizontal scroll but nothing has worked and I am completely stumped. Thanks in advance for any tips.
You can add the following styles to the #slider div to get only a horizontal scrollbar that scrolls through the images. Afterwards, its just sizing and positioning the div. The white-space: nowrap property tells the images not to wrap to next "lines".
#slider {
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
#thumbset {
overflow: visible;
}
You can try the following css :
#slider {
width: 330px;
overflow-x: scroll;
overflow-y: hidden;
}
#thumbset {
width: 550px;// whatever width you want
}
Use this code:
<div style="width: 300px; height: 40px; border: 1px solid black; overflow: auto; white-space: nowrap; font-size: 14px">
Here's a random text .............
</div>
see how this code works in this fiddle, it's an easy way : add horizontal scroll bar
I have a page with the following structure:
div.wrapper > div.content > div.item + div.item
The wrapper has a width of 320px, whereas the two div.item come out to around 600px. I need those two to be displayed inline (right now they are display: inline-block;, and have the wrapper's contents scroll horizontally. When I set the div.content width to auto, it takes the width of the wrapper (320px). Setting the width to 200% obviously gets the horizontal scrolling to work, but how do I get div.content to take on the width of its contents to allow for horizontal scrolling?
Note: The wrapper is set to a fixed width and height and has overflow-y: hidden and overflow-x: scroll set, because I do not want vertical scrolling-- only horizontal.
JSFiddle with an example:
http://jsfiddle.net/kh5k7/
As you can see, the red divs will vertically stack. Changing the .content width to 200% (or some value) will cause horizontal scrolling to occur properly. I want this done automatically though, because I have no clue how many elements are going to be in the .content div before hand.
Use white-space:nowrap; on .content
.content{
width: auto;
white-space:nowrap;
}
http://jsfiddle.net/kh5k7/1/
You can have something like this:
.wrapper {
overflow-x: auto;
overflow-y: hidden;
}
.content {
width: auto;
white-space: nowrap;
}
.item {
display: inline-block;
}
If I have a table like this very very simple example:
table {
table-layout:fixed;
width:300px;
}
.td1 {
width:100px;
}
.td2 {
width:200px;
}
and in one of my .td2 contains an image that is, lets say, 300px in width. I would like to show scroll bars to allow users to scroll to see it all. However I don't think this is possible, is it?
So my questions are:
Are there any other options apart from hidden for handling overflow in tables?
Is it possible to show scroll-bars only when content pushes beyond a set width? (I swear I've seen it in some forum software but I can't remember which one)
What about
overflow: auto
Content is clipped and scrolling is
added only when necessary.
Put the image inside a div in the table cell and make the width and height of the div to be 100% of the td and style it to overflow: auto
<style>
.test { width: 100%; height: 100%; overflow: auto; }
</style>
<td>
<div class="test">
your image
</div>
</td>