Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

how to force <p> text to remain inside div

Hey all,

I have been trying to force paragraph text to remain inside a div when the div is resized smaller. The problem is the text spills outside the div when the div is smaller. How can i lock the text or div at the point it will spill out preventing overflow?

overflow: auto; creates a scroll bar which I prefer not to use.

I created a codepen

https://codepen.io/digitalrambo/pen/WjZVLE

I have googled and re watched many CSS videos but still cant solve it.

Would appreciate help

thank you (:

Have you tried giving your div an invisible border? That should force the content to stay inside.

3 Answers

I tried adding border to the div and it didnt work. border: 2px solid red;

it has to do with max width or min width I think but ive tried all combinations on both elements and its still not contained.

put a min-height on your div.

@Juan I tried adding

height: 100%; to the div and it worked!!!!!! woo

do i still need min-height?

I removed all the CSS for p and still works :D https://codepen.io/digitalrambo/pen/WjZVLE