I have a div that is styled with overflow-x: hidden
, but I'm finding that when there is a wider div inside it that contains text, the user can still drag sideways with the mouse to view the hidden text.
I would like to prevent that and make the text truly hidden. This jsfiddle should show what I mean: http://jsfiddle.net/YzsGF/11/ or here is the code:
<div id="outer">
<div id="inner">
How can I truly hide the text beyond the margin?
</div>
</div>
#outer {
width: 150px;
height: 300px;
overflow-x: hidden;
border: 1px solid black;
}
#inner {
width: 300px;
overflow-x: hidden;
}
Is there a way that I can prevent the user from being able to see the hidden text?
UPDATE: I need overflow-y to work: it's OK that overflow-x is CSS3 only. It may help to explain the real-life scenario:
Any solutions?
CSS overflow on one axis only So, by restricting the height of the container we are forcing the Y overflow condition to be used, which is either set to 'auto', 'scroll' or 'hidden' when 'overflow-x: hidden' is set. The solution is simple, if not a little bit hacky. Wrap the container in another div.
To activate the overflow property enclose the image, within a div of a particular width and height, and set overflow:hidden . This will ensure that the base container will retain its structure, and any image overflow will be hidden behind the container.
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML.
You could use the CSS clip
property.
This will clip your text as desired by not showing anything beyond the clipping rectangle, and it will also stop the user from scrolling across.
#inner { position:absolute; clip:rect(0px,150px,150px,0px); width: 300px; }
http://jsfiddle.net/DigitalBiscuits/YzsGF/18/
Note: you need to specify an absolute positioning for this the clip property to work it seems.
More Info Here: http://www.w3schools.com/cssref/pr_pos_clip.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With