

The overflow:hidden declaration hides any text that would otherwise extend past the right side of the container. The white-space:nowrap declaration keeps all text on one line. The max-width:400px declaration is to ensure the container remains smaller than the amount of text (so there can be an example). Here is a note about each declaration in the above example code. The blue CSS declaration is optional.Īdditional declarations may be added to the class. In the above code, the red CSS declarations are required. The class name "one-long-line" may be any class name that works for you.
#Overflow hidden code
When text must stay on one line, but there is not enough room for it all, this article provides a solution.Īnd here is the code for the example of the line above.

When the mouse pointer hovers over the line below, the rest of the line is revealed. Use the overflow:visible CSS declaration for the class' :hover selector.Īn example incorporating the above CSS declarations follows. However, there is a way so it can be seen when the mouse pointer hovers over the line of text. If the text didn't need to be seen, it wouldn't have been put there in the first place. Of course, merely clipping text is not a solution in most cases. Now, the class for the container with the one long line of text has these three CSS declarations: Optionally, use the CSS declaration text-overflow:ellipsis to print an elipsis where some of the text is clipped. Which may make the text so small it is hard or impossible to read.Īnother way to correct it is to use the CSS declaration overflow:hidden to clip any text that extends past the right side of the container.Īt this point, the class for the container with the one long line of text has these two CSS declarations: One way to correct it is to reduce the font size of the text until it fits within the container.

If there is more text than fits on the line, it will extend past the right side of the div or other container. The CSS declaration white-space:nowrap keeps all text on one line. See from I’ll try to write a follow-up post when I understand everything.When text must stay on one line, but there is not enough room for it all, here is a solution. If you happen to know why, send a self-addressed stamped envelope to twitter dot com slash miketaylr and let me know. Unfortunately at least one site relies on this bug (see this comment). So it seems like non-Edge and non-Firefox browsers treat a position: fixed element as a position: absolute element (or something?), when contained by a position: relative parent that also has a z-index set. The only browser this seems to make a difference in is Chrome on Android, which now clips the child element. Mobile + Desktop Opera (Blink): same as ChromeĪnd now, a 3rd testcase which adds user-scalable=no to the meta (viewport) element (the same effect happens if you constrain intial-scale and maximum-scale to 1. Mobile + Desktop Opera (Presto): same as Safariĭesktop Chrome: if the viewport is smaller than the containing parent, then overflow: hidden on the parent kicks in (resize the browser window to see it). Mobile + Desktop Safari: fixpos element is clipped by parent (meaning overflow: hidden worked). Same as first testcase (what I would expect): Now if you throw in both a z-index: 1 (any number will do) and a position: relative on the parent element, things get…different.

overflow: hidden on the parent is ignored. But how do browsers behave? Open this testcase and have a look:Įverything behaves as the spec describes. So, according that spec text, the parent element’s overflow shouldn’t have any effect because the fixpos’ parent element is the viewport. The only difference is that for a fixed positioned box, the containing block is established by the viewport. If you have an element with position: fixed inside of an element that has overflow: hidden, what’s the expected rendering when you need to, uh, overflow? Should the inner fixpos element be clipped by its parent or not?įixed positioning is similar to absolute positioning.
