Forum Moderators: not2easy

Message Too Old, No Replies

Clipped Scrollbar and Border in Webkit

         

Rain_Lover

6:37 am on May 5, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Part of the textarea scrollbar and border is cut off:

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Clipped Scrollbar and Border in Webkit</title>
<style>
textarea,
iframe {
display: block;
width: 300px;
margin: 0;
padding: 0;
}
textarea {
height: 200px;
resize: none;
outline: 0;
border: solid red;
border-width: 0 0 5px;
}
iframe {
height: 0;
border: 0;
}
</style>
</head>

<body>
<textarea>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
<p>Hello, world!</p>
</textarea>
<iframe srcdoc="<p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>"></iframe>
</body>

</html>


DEMO: [jsfiddle.net ]

Why does it happen? What's the fix?

birdbrain

10:42 am on May 5, 2014 (gmt 0)



Hi there Rain Lover,

The cause of your problem appears to be...


iframe {
height:0;
border:0;
}

If you don't want it behave oddly, why not just use this instead...


iframe {
display:none;
}



birdbrain

Fotiman

7:12 pm on May 5, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It looks like the iframe is creating a visual element where the vertical scrollbar would appear, which then overlaps the bottom of your textarea. I've read that overflow on iframes is not reliable in all browsers and the only way to get rid of it is to include the the scrolling attribute on the iframe, like this:
<iframe scrolling="no" srcdoc="..."></iframe>

That does seem to fix the problem.

Fotiman

7:24 pm on May 5, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Adding this CSS also seems to remove the scrollbar completely:

iframe::-webkit-scrollbar {
display: none;
}

Rain_Lover

4:08 am on May 6, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Dear Fotiman,

<iframe scrolling="no" srcdoc="..."></iframe>


The scrolling attribute on the iframe element is obsolete and I'd prefer to avoid it.

iframe::-webkit-scrollbar {
display: none;
}


I'm working on a small application in which the user can change the iframe height size. Removing the scrollbar needs a JavaScript function to restore it when the iframe height is greater than 0.

I just learned it seems like a z-index problem: the textarea scrollbar bottom and border hide behind the iframe horizontal scrollbar when they overlap:
DEMO: [jsfiddle.net ]

What do you think?

Fotiman

12:01 pm on May 6, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, that's what I was saying. It does seem like a WebKit bug to me. I think you might need JavaScript to get around it, unfortunately.

Fotiman

1:59 pm on May 6, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




The scrolling attribute on the iframe element is obsolete and I'd prefer to avoid it.

Understandable. Plus, I think that would raise the same problem as the JavaScript solution... you'd need to modify that value as the user modified the height.

I'm working on a small application in which the user can change the iframe height size.

How do they change the height? Is it using JavaScript? If so, then restoring the scrollbar when the height is greater than 0 should be easy. If not, are you using CSS resize? With the CSS resize approach, wouldn't you still need a handle for the user to grab if they wanted to change the height, even when the height was 0?

Note, I don't think I would say it's a "z-index" problem per se. That is, in this particular case, you have 2 positioned elements and one of them (the iframe) is showing a scrollbar area even when the height is zero, and so (being the latter item in the DOM) will overlap the other positioned element because they both have the same z-index. Changing the z-index so that the second one is lower than the first will work in your example, but only because you're letting the textarea cover the visible area of the iframe. It hasn't really fixed the issue, just covered it up. If you ever add more content between the textarea and the iframe, then the problem will return (unless you also position that content and give it a higher z-index than the iframe). So I would consider that a fragile solution.

Rain_Lover

5:39 pm on May 6, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Many thanks for the points you mentioned! :)