0

I have a div and within it a paragraph:

<div id="MyDiv">
    <p style="color: #FF8000; font-size: 10pt; font-family: Verdana;">
        &ensp;&ensp;This is my first line in the paragraph. This line cannot be broken.<br />
        &ensp;&ensp;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.

4

3 回答 3

2

将 div 的显示设置为inline-block并防止换行为white-space: nowrap;段落添加:

#MyDiv{
    display: inline-block;
}

#MyDiv p{
    white-space: nowrap;    
}

在这里小提琴:http: //jsfiddle.net/LMB6L/6/

于 2013-11-01T20:47:26.303 回答
1

你是这个意思吗?

#MyDiv {outline:1px solid red;display:inline-block;}

http://jsfiddle.net/62CQt/

于 2013-11-01T20:46:54.143 回答
0

我会建议width:auto;inherit在段落修改中

于 2013-11-01T20:47:49.157 回答