Reputation: 991
I have a div and within it a paragraph:
<div id="MyDiv">
<p style="color: #FF8000; font-size: 10pt; font-family: Verdana;">
  This is my first line in the paragraph. This line cannot be broken.<br />
  This is my second line in the paragraph. This line cannot be broken.<br /><br />
This is another line within the paragraph. This line cannot be broken.<br />
</p>
</div>
As seen above, my paragraph has a lot of line. Each line ends with a new line. Some of the end with two new lines.
I would like div's width to be resized automatically to the longest paragraph line width. How can I do this?
Note: I do not want lines to be broken into separate lines until
is reached. Div's width must be resized to the longest line width.
Upvotes: 0
Views: 1620
Reputation: 26949
Set the display of the div to inline-block
and to prevent wrapping of lines add white-space: nowrap;
for the paragraphs:
#MyDiv{
display: inline-block;
}
#MyDiv p{
white-space: nowrap;
}
Fiddle here: http://jsfiddle.net/LMB6L/6/
Upvotes: 2
Reputation: 135
I would suggest width:auto;
or inherit
in the paragraph modification
Upvotes: 0
Reputation: 752
Is this what you mean?
#MyDiv {outline:1px solid red;display:inline-block;}
Upvotes: 1