<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我的java天地

    CSS 長英文字母自動換行

    自動換行問題,正常字符的換行是比較合理的,而連續的數字和英文字符常常將容器撐大,挺讓人頭疼,下面介紹的是CSS如何實現換行的方法


    對于div,p等塊級元素
    正常文字的換行(亞洲文字和非亞洲文字)元素擁有默認的white-space:normal,當定義的寬度之后自動換行
    html
    <div id="wrap">正常文字的換行(亞洲文字和非亞洲文字)元素擁有默認的white-space:normal,當定義</div>
    css
    #wrap{white-space:normal; width:200px; }

    1.(IE瀏覽器)連續的英文字符和阿拉伯數字,使用word-wrap : break-word ;或者word-break:break-all;實現強制斷行

    #wrap{word-break:break-all; width:200px;}
    或者
    #wrap{word-wrap:break-word; width:200px;}

    <div id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>

    效果:可以實現換行

    2.(Firefox瀏覽器)連續的英文字符和阿拉伯數字的斷行,Firefox的所有版本的沒有解決這個問題,我們只有讓超出邊界的字符隱藏或者,給容器添加滾動條


    #wrap{word-break:break-all; width:200px; overflow:auto;}

    <div id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>

    效果:容器正常,內容隱藏

    對于table

    1. (IE瀏覽器)使用 table-layout:fixed;強制table的寬度,多余內容隱藏

    <table style="table-layout:fixed" width="200">
    <tr>
    <td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss
    </td>
    </tr>
    </table>

    效果:隱藏多余內容

    2.(IE瀏覽器)使用 table-layout:fixed;強制table的寬度,內層td,th采用word-break : break-all;或者word-wrap : break-word ;換行

    <table width="200" style="table-layout:fixed;">
    <tr>
    <td width="25%" style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz 1234567890
    </td>
    <td style="word-wrap : break-word ;">abcdefghigklmnopqrstuvwxyz 1234567890
    </td>
    </tr>
    </table>

    效果:可以換行

    3. (IE瀏覽器)在td,th中嵌套div,p等采用上面提到的div,p的換行方法

    4.(Firefox瀏覽器)使用 table-layout:fixed;強制table的寬度,內層td,th采用word-break : break-all;或者word-wrap : break-word ;換行,使用overflow:hidden;隱藏超出內容,這里overflow:auto;無法起作用


    <table style="table-layout:fixed" width="200">
    <tr>
    <td width="25%" style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
    <td width="75%" style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
    </tr>
    </table>

    效果:隱藏多于內容

    5.(Firefox瀏覽器) 在td,th中嵌套div,p等采用上面提到的對付Firefox的方法
    運行代碼框
    最后,這種現象出現的幾率很小,但是不能排除網友的惡搞。

    下面是提到的例子的效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>字符換行</title>
    <style type="text/css">
    table,td,th,div { border:1px green solid;}
    code { font-family:"Courier New", Courier, monospace;}
    </style>
    </head>
    <body>
    <h1><code>div</code></h1>
    <h1><code>All white-space:normal;</code></h1>
    <div style="white-space:normal; width:200px;">Wordwrap still occurs in a td element that has its WIDTH attribute set to a value smaller than the unwrapped content of the cell, even if the noWrap property is set to true. Therefore, the WIDTH attribute takes precedence over the noWrap property in this scenario</div>

    <h1><code>IE \ word-wrap : break-word ;</code></h1>
    <div style="word-wrap : break-word ; width:200px;">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>
    <h1><code>IE \ word-break:break-all;</code></h1>
    <div style="word-break:break-all;width:200px;">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>

    <h1><code>Firefox/ word-break:break-all; overflow:auto;</code></h1>
    <div style="word-break:break-all; width:200px; overflow:auto;">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>
    <h1><code>table</code></h1>
    <h1><code>table-layout:fixed;</code></h1>
    <table style="table-layout:fixed" width="200">
    <tr>
    <td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>
    </tr>
    </table>
    <h1><code>table-layout:fixed; word-break : break-all; word-wrap : break-word ;</code></h1>
    <table width="200" style="table-layout:fixed;">
    <tr>
    <td width="25%" style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>
    <td style="word-wrap : break-word ;">abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>
    </tr>
    </table>
    <h1><code>FF \ table-layout:fixed; overflow:hidden;</code></h1>
    <table style="table-layout:fixed" width="200">
    <tr>
    <td width="25%" style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
    <td width="75%" style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
    </tr>
    </table>
    </body>
    </html>

    posted on 2009-09-28 10:49 tobyxiong 閱讀(481) 評論(0)  編輯  收藏 所屬分類: show page

    <2009年9月>
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    導航

    統計

    常用鏈接

    留言簿(3)

    隨筆分類(144)

    隨筆檔案(157)

    相冊

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产亚洲精品影视在线| 亚洲精品国产手机| 免费精品视频在线| 国产成人免费永久播放视频平台| 亚洲狠狠成人综合网| 成人奭片免费观看| 亚洲乱理伦片在线观看中字| 最新猫咪www免费人成| 亚洲综合av一区二区三区不卡 | 日日摸夜夜添夜夜免费视频| 国产免费看插插插视频| 美女被免费网站在线视频免费| 四虎在线播放免费永久视频| 黄色免费网址在线观看| 亚洲日本一区二区一本一道 | 日韩在线永久免费播放| 亚洲欧洲自拍拍偷综合| 国产一卡2卡3卡4卡2021免费观看| 亚洲乱码一区二区三区国产精品| 成在人线AV无码免费| 麻豆安全免费网址入口| 国产亚洲一区二区精品| 最近免费最新高清中文字幕韩国 | 中国一级特黄高清免费的大片中国一级黄色片 | 免费无码又爽又刺激网站| 亚洲一二成人精品区| 综合在线免费视频| 亚洲AV无码片一区二区三区| 亚洲福利在线播放| 久久美女网站免费| 最新国产成人亚洲精品影院| 国产极品美女高潮抽搐免费网站| 永久免费观看黄网站| 亚洲人成在线影院| 国产美女被遭强高潮免费网站| 一区二区三区视频免费观看| 亚洲美女视频网址| 又黄又爽一线毛片免费观看 | MM1313亚洲国产精品| 情人伊人久久综合亚洲| 成人au免费视频影院|