How can I keep content from re-sizing it's wrapper div? - css

I'm a css noob, and though I want this DIV to resize when the window is resized, I don't want inner content to change the size of it.

Use the overflow statement. e.g.
overflow: hidden; /* all content hidden as it spills over */
overflow: auto; /* Scroll bars appear on div when required to allow moving around */
overflow: scroll; /* Scroll bars will be present at all times */

Try using:
div {
overflow: hidden;
}
Read more here.

set overflow: hidden on the containing div

Have you looked into CSS and the overflow directive? You can use this to tell the div to scroll or truncate/hide its content when the content is too large.

Related

Horizontal overflow on mobile site

jsfiddle.net/etto2sdt/
What I'm trying to do is having a touch scrollable div. The body is set to 100% and I want to be able to scroll the contents inside #testnavwrapper
But it's not working... any ideas?
#testnavwrapper {
width: 100%;
overflow-x: scroll;
}
This will give you a horizontal scrollbar on the #testnavwrapper.
width: 2000px, as you put it, will have no effect as the overflow would occur on the body element (which has overflow set to hidden)
Hope it helps

Why am I getting scroll bars in this div?

http://jsfiddle.net/BCTF9/
I have set the overflow as I want to restrict the height of the boxes and have a scroll show up when needed; so I added overflow-y: auto; as that generally does the trick. But now I see horizontal scroll bars on the second box in the example as well, though I'm not sure why?
I tried adding overflow-x: visible; but it didn't work. I don't want to set any widths on these boxes as they just need to be the width of the content + some padding.
You will also see the vertical scroll bars start too soon and don't allow the padding needed.
What can I do here?
jsfiddle Demo
Two reasons and fixes
The content in the second div taking too much width causing horizontal overflow, so increase the width
Instead of overflow-x:visible try overflow-x:hidden to hide horizontal scrollbar even if the width is higher
Try with this
CSS
.cat_list{ height:200px;
background:#e4e4e4;
width:200px;
overflow:hidden;
overflow-y:scroll;
overflow-x:hidden;}
HTML
<div class="cat_list"></div>
The scroll bars are appearing because there are many items in second div.
Try to remove these items, and they'll go away.
Fiddle
.cat_list {
overflow-y: auto;
overflow-x: hidden;
min-width: 200px;
padding: 10px;
}
Replace it

div width is not working?

I have a problem with content from a div, for example if I put a table inside of a div and set a width (width:200px !important)for that div the table it will overwrite that div. So how is possible to keep all content inside that div?
fiddle example:
http://jsfiddle.net/ebG9N/45/
You set the header to white-space: nowrap; therefore, the browser is unable to break the headers, so the width of the table will be bigger than the container div.
You can set, overflow: hidden; to cut the overflowing parts, or overflow: auto; to create a scrollbar, but without them it's the correct rendering.
There are two solutions.
i) IF you want to STRICTLY contain table WITHIN div then overflow:auto; is the way to go.
ii) BUT if you change your mind and want to WRAP div to the width of table then.
display:table; is the way to go.
Generally its bad idea to contain wider element within explicitly known less wider element.
Try using overflow:auto; in the css of the div.
You can't just expect it to somehow fit within a div of any size you wish. What you can do is, at least allow the browser to scroll (overflow: scroll) it using:
div.divano{
width:200px !important;
border:2px solid yellow;
background:#eaeaea;
height:200px;
overflow: scroll;
}
You may also use oveflow: hidden, but it would just hide the parts that are not visible. Also, overflow: scroll, will always show a scroll bar (with or without clipping). You can use overflow: auto to specify that the content should be scrolled only if clipping occurs.

Remove scollbar when no need to scroll

I have a div with a scollbar as a result of the CSS below. However, when there is no need to scroll, the bar is still there. There is no slider/arrows, but an emtpy bar is just there. Is there a way to only show the bar if the content overflows? Thanks.
#id{
overflow: -moz-scrollbars-vertical;
overflow-x: hidden;
overflow-y: scroll;
}
use
overflow: auto;
then overflow will only be displayed if it actually overflows
auto The behavior of auto isn’t specified in any detail in the CSS2.1
specification. In existing implementations it provides scrollbar(s)
when necessary, but it doesn’t show scrollbars unless the content
overflows the element’s box.
http://reference.sitepoint.com/css/overflow

CSS - how to trim text output?

I have an arbitrary amount of text that will be displayed in a confined space.
How can I trim the output so that whatever is "beyond" the box is not displayed, or how can I force the box to create a vertical scroll bar?
For HTML:
<div id="smallBoxWithLotsOfText">There is way more text in here than what
I have typed. I mean, this text is long. There is lots of it.
You can't even imagine how long this text is gonna get. No joking.
It's long; it's very, very long. It keeps going, and going, and going.
It's the Energizer Bunny of text. Like, seriously dude. It's crazy.
Absolutely crazy.
</div>
Try CSS:
#smallBoxWithLotsOfText {
width: 100%;
height: 100px;
overflow: auto;
}
The height property tells the box how high to be. The overflow property tells the box to add a scroll bar when the contents get bigger, but not to always have a scrollbar (like scroll does).
You can see this in action.
usually 'overflow: auto' should work if there is a set height/width. You can force a scroll bar with 'overflow: scroll'. You can hide anything with 'overflow: hidden;'
The key to overflow with CSS styles is the height and width have to be determined by the browser in order for it to know when to start overflowing.
The overflow property. You can set the value to hidden to hide the data and scroll to scroll the data.
<div class="text">this is some text that would be very long...</div>
//Hidden
.text
{
overflow: hidden;
width: 50px;
height: 50px
}
//Scroll
.text
{
overflow: scroll;
width: 50px;
height: 50px
}
Take a look at overflow. overflow: hidden clips content, overflow:Scroll adds a scrollbar.
How can I trim the output so that
whatever is "beyond" the box is not
displayed
Use overflow: hidden
How can I force the box to create a
vertical scroll bar?
Use overflow: auto. To use this, though, make sure you have a width/height specified on the box
You may try using ellipsis by adding the following in CSS:
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
More ways to trim text and show ellipsis can be found here:
http://blog.sanuker.com/?p=631

Resources