Let the height <p> determine the height of the <div>
I have a paragraph of text inside a <div> that depends on length and therefore on height. I want the div to have a minimum height of 100px , but grows when the height of the <p> increases above 80px . I set the css height: 100px for the <div> , but when the <p> exceeded 80px , the text just spills out from the <div> , and the height of the <div> remains unchanged. What should I do?
Code:
<div id="outer_box"> <div id="box"> <p class="content"> Some long paragraph of content here </p> </div> </div> CSS
#outer_box { width: 300px; min-height: 100px; } #box{ width: 300px; min-height: 90px; } div with id="box" changed its height to fully contain <p> , but div with id="outer_box" did not change its height!
Interested in CSS solution, not jQuery, if possible, I will use everything that works. The reason for choosing a clean CSS solution is because the div does not exist until the user hovers over the mouse. Wondering how to target a div on css that doesn't exist yet
It seems to you that the word-wrap property is missing. I tested the following styles in ie9 and chrome. It seems to be working fine.
<!DOCTYPE html> <html> <head> <style> #outer_box { width: 300px; min-height: 100px; background-color:blue; } #box{ width: 300px; background-color:green; word-wrap:break-word; } </style> </head> <body> <div id="outer_box"> <div id="box"> <p class="content"> Some long paragraph of content here kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk</p> </div> </div> </body> </html> Some long paragraph of content here kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk </ p> <!DOCTYPE html> <html> <head> <style> #outer_box { width: 300px; min-height: 100px; background-color:blue; } #box{ width: 300px; background-color:green; word-wrap:break-word; } </style> </head> <body> <div id="outer_box"> <div id="box"> <p class="content"> Some long paragraph of content here kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk</p> </div> </div> </body> </html>