3

I have a div which is resizable but now I have the problem that there is a y-scrollbar. The problem is that this scrollbar isn't necessary, because all content is visible.

Image

scrollbar

HTML

<script>$( "#pc_test" ).resizable({handles: \'n, s\'});</script>
<div id="panel_test">
    <div class="panelheadbar pgrau">Test</div>
    <div id="pc_test" class="panelcontent ui-resizable" style="font-size: 14px;">
    Test<br>Test<br>Test<br>Test<br>Test<br>Test<br>Test<br>
    </div>
</div>

CSS

.panelheadbar { padding: 5px; font-weight: bold; color: #000; height: auto; }
.pgrau { background-color: #ccc; }
.panelcontent { overflow-y: auto; overflow-x: hidden;padding: 10px; background-color: #FFF; border: 1px solid #ccc; }

How can I fix this, that there is only a scrollbar when it's needed?

Edit: I want a scrollbar if the user resized it too much.

Edit 2: here there should be a scrollbar enter image description here

Edit3: The result should look like this enter image description here

3 Answers 3

1

A Good Manners Answer

The problem might be on the <div> hierarchy. Because when you have one <div> inside another, the first <div> will need to be set as relative and the sequence set of <div> need to be set to absolute position.

HTML

The HTML will stay as it is.

<script>$( "#pc_test" ).resizable({handles: \'n, s\'});</script>
<div id="panel_test">
    <div class="panelheadbar pgrau">Test</div>
    <div id="pc_test" class="panelcontent ui-resizable" style="font-size: 14px;">
    Test<br>Test<br>Test<br>Test<br>Test<br>Test<br>Test<br>
    </div>
</div>

CSS

That way you should have on CSS:

.panelheadbar {
    position: relative;
    overflow: hidden;
    padding: 5px;
    font-weight: bold;
    color: #000;
    height: auto;
}

.pgrau {
    background-color: #ccc;
}

.panelcontent {
    position: absolute;
    overflow: hidden;
    overflow-x: hidden;
    padding: 10px;
    background-color: #FFF;
    border: 1px solid #ccc;
}

That way it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

So <div id="panel_test"> has to be relative and the others absolute?
I added a second image to my question. With your solution I get this response but in that case there should be a scrollbar.
0

A Simple Answer

You just need to change overflow: auto; to overflow: hidden; property:

.panelheadbar {
    overflow: hidden;
    padding: 5px;
    font-weight: bold;
    color: #000;
    height: auto;
}

.pgrau {
    background-color: #ccc;
}

.panelcontent {
    overflow: hidden;
    overflow-x: hidden;
    padding: 10px;
    background-color: #FFF;
    border: 1px solid #ccc;
}

The overflow property specifies what to do if the content of an element exceeds the size of the element's box.

5 Comments

Oh sry, at this position should stand "overflow-y; auto;", because I want to have a scrollbar when you resized it to much.
Nope because I want a scrollbar, but not if it's not needed. My problem is that there is a scrollbar even if there is enough height.
Try it on .panelheadbar and then tell me if it works please.
.panelheadbar with overflow:hidden and .panelcontent with overflow-y: auto; overflow-x: hidden; didn't work
So please give us more from your CSS.
0

Box Re-size Problem Answer

For the second problem you will need to use height: auto; in the .panelcontent field:

.panelheadbar {
    position: relative;
    overflow: auto;
    padding: 5px;
    font-weight: bold;
    color: #000;
    height: auto;
}

.pgrau {
    background-color: #ccc;
}

.panelcontent {
    height: auto;
    position: absolute;
    overflow: auto;
    overflow-x: auto;
    padding: 10px;
    background-color: #FFF;
    border: 1px solid #ccc;
}

The options for overflow are:

overflow: visible | hidden | scroll | auto | inherit

As you can see on the description of CSS overflow Property:

http://www.w3schools.com/cssref/pr_pos_overflow.asp

I recommend you as well to watch this link:

https://css-tricks.com/almanac/properties/o/overflow/

8 Comments

I added a picture how the result should look like (edit 3)
Try to change position: absolute; to position: relative; on the .panelcontent and see how it works please.
With that solution I get no scrollbar at all.
But the problem is, even if I have enough height for the text, the scrollbar is still there. And in this case the scrollbar should be hidden
Isn't overflow: auto the correct choice when I want a scrollbar only if it's needed? And I think the height-variable comes from the ui-resizable.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.