开发者

html style not work in FF in MVC view

开发者 https://www.devze.com 2022-12-08 02:28 出处:网络
I have the following view: <div style=\"width:600\"> <fieldset style=\"width:600\"> <table style=\"width:600\" >

I have the following view:

<div style="width:600">
    <fieldset style="width:600">
    <table style="width:600" >
       <tr>
             <td>TEST</td>
             <td ><span class="displayData"><%= Html.Encode(Model.MyDESCRIPTION)%></span></td>  
             <td style="width:100%;" >&nbsp;</td>                  
             <td style="white-space: nowrap;">....</td>
             </tr>
        </table>
    </fieldset>
</div>

I want to the width limited within 600px for printing, So I set the top div to width=600, wich works fine in IE, but doesn't work in Firefox.

For example, if the data for MyDESCRIPTION is something like:

12222222222222332222222132213123..123131111111111111111111111111111 
(no space, its total length will exceed 600).

In IE the line can be warpped to multiple lines within 600 limitation. But in Firefox, the line will b开发者_C百科e extended and there is no warp, so it will be cut by the display. But printing is fine for FF.

I'm very confused. How can I resolve this problem?


You need the following CSS to force the line to break:

td span {
    width: 600px;
    white-space: pre-wrap; /* css-3 */
    white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
    white-space: -pre-wrap; /* Opera 4-6 */
    white-space: -o-pre-wrap; /* Opera 7 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */
}
0

精彩评论

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