在CSS中怎么样完成自动换行,代码是什么
发布时间:2023-10-24 09:36:04 所属栏目:语言 来源:
导读:在这篇文章中,我们来学习一下“在CSS中怎么样实现自动换行,代码是什么”的相关知识,下文有详细的讲解,易于大家学习和理解,有需要的朋友可以借鉴参考,下面就请大家跟着小编的思路一起来学习一下吧。
在这篇文章中,我们来学习一下“在CSS中怎么样实现自动换行,代码是什么”的相关知识,下文有详细的讲解,易于大家学习和理解,有需要的朋友可以借鉴参考,下面就请大家跟着小编的思路一起来学习一下吧。 自动换行的cssdiv/css.html">css教程代码与方法 对于div,p等块级元素 正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义的宽度之后自动换行 html < id="wrap">正常文字的换行元素拥有默认的white-space:normal,当定义< /div > css #wrap{white-space:normal; } 1.(ie浏览器)连续的英文字符和阿拉伯数字,使用word-wrap : break-word ;或者word-break:break-all;实现强制断行 #wrap{word-break:break-all; } 或者 #wrap{word-wrap:break-word; } < id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111< /div > 效果:可以实现换行 2.(firefox浏览器)连续的英文字符和阿拉伯数字的断行,firefox的所有版本的没有解决这个问题,我们只有让超出边界的字符隐藏或者,给容器添加滚动条 #wrap{word-break:break-all; overflow:auto;} < id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111< /div > 效果:容器正常,内容隐藏 对于table 1. (ie浏览器)使用 table-layout:fixed;强制table的宽度,多余内容隐藏 < style="table-layout:fixed" > <> <>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss < /td > < /tr > < /table > 效果:隐藏多余内容 2.(ie浏览器)使用 table-layout:fixed;强制table的宽度,内层td,th采用word-break : break-all;或者word-wrap : break-word ;换行 < style="table-layout:fixed;"> <> < style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz 1234567890 < /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;无法起作用 < style="table-layout:fixed" > <> < style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890< /td > < style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890< /td > < /tr > < /table > 效果:隐藏多于内容 5.(firefox浏览器) 在td,th中嵌套div,p等采用上面提到的对付firefox的方法 (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐