开发者

HTML pre no line wrap border

开发者 https://www.devze.com 2023-03-12 15:22 出处:网络
I have a pre tag with some code in it that doesn\'t line w开发者_StackOverflow社区rap. I want to put a border around it (border:1px solid Black;), but the border is limited to the width of the browser

I have a pre tag with some code in it that doesn't line w开发者_StackOverflow社区rap. I want to put a border around it (border:1px solid Black;), but the border is limited to the width of the browser, regardless of the length of the text. How can I force the border to always extend to contain all the text in the pre tag?

Here's the code I'm using:

<pre style="border:2px solid Black;">@Model.Code()</pre>


Use:

<pre style="display: inline-block; border:2px solid Black;">


For displaying code you want to use

pre { white-space:pre-wrap }

And for normal text you may want to use

pre { white-space:pre-line }

pre-line makes from multiple white space characters one space character, pre-wrap doesn't.

Now if you add a border it will be around the entire text, and the text will be wrapped.

pre {
    white-space:pre-line;
    border:2px solid black
}

Or didn't you ask for this?


Try adding display: inline to your pre tag CSS.

0

精彩评论

暂无评论...
验证码 换一张
取 消