[CSS]CSS换行问题

强制不换行 white-space:nowrap

white-space 属性设置如何处理元素内的空白。
属性[ http://www.w3school.com.cn ]:

描述
normal默认。空白会被浏览器忽略。
pre空白会被浏览器保留。其行为方式类似 HTML 中的
 标签。
nowrap文本不会换行,文本会在在同一行上继续,直到遇到
标签为止。
pre-wrap保留空白符序列,但是正常地进行换行。
pre-line合并空白符序列,但是保留换行符。
inherit规定应该从父元素继承 white-space 属性的值。

自动换行 word-wrap:break-word

当长单词或网页地址一行无法显示的时候在下一行显示。
属性[ http://www.w3school.com.cn ]:

描述
normal默认。 只在允许的断字点换行。
pre在长单词或 URL 地址内部进行换行。

强制断行 word-break:break-all

word-break 属性规定自动换行的处理方法
属性[ http://www.w3school.com.cn ]:

描述
normal默认。 使用浏览器默认的换行规则。
break-all允许在单词内换行。
keep-all只能在半角空格或连字符处换行。

超出内容显示省略号 text-overflow:ellipsis

text-overflow 属性规定当文本溢出包含元素时发生的事情。
属性[ http://www.w3school.com.cn ]:

描述
clip修剪文本。
ellipsis显示省略符号来代表被修剪的文本。
string使用给定的字符串来代表被修剪的文本。

**注意:**ellipsis只对单行文本生效,且容器overflow:hidden。

点击查看测试页
wrap-example.jpg

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>css换行</title>
    <style>
        .lists{
            width: 400px;
            height: auto;
            margin: 50px auto;
            padding: 20px;
            font-size: 14px;
            line-height: 1.6em;
            font-family: 'Microsoft YaHei Light';
        }
        .list{
            width: 100%;
            height: auto;
            padding: 5px;
            border-radius: 3px;
            border: #aaa 1px solid;
            background: #fafafa;
            margin:0 0 25px;
            text-indent: 2em;
        }
        small{
            font-size: 14px;
            color: #aaa;
            font-weight: bold;
            line-height: 1em;
        }
        .nowrap{
            white-space:nowrap;
        }
        .break-word{
            word-wrap:break-word;
        }
        .break-all{
            word-break:break-all;
        }
        .ellipsis{
            white-space: nowrap;
            overflow: hidden;
            text-overflow:ellipsis;
            height: 20px;
        }
    </style>
</head>
<body>
<div class="lists">
    <small>white-space:nowrap</small>
    <div class="list nowrap">我说道,“爸爸,你走吧。”他望车外看了看,说,“我买几个橘子去。你就在此地,不要走动。”我看那边月台的栅栏外有几个卖东西的等着顾客。走到那边月台,须穿过铁道,须跳下去又爬上去。</div>
    <small>word-wrap:break-word</small>
    <div class="list break-word">Finally, he found another field where he could hide.He lay down, unable to sleep, his mind filled with visions of the dead girl. Her wide, dead eyes stared at him, watching him through a curtain of blood.</div>
    <small>word-break:break-all</small>
    <div class="list break-all">Finally, he found another field where he could hide.He lay down, unable to sleep, his mind filled with visions of the dead girl. Her wide, dead eyes stared at him, watching him through a curtain of blood.</div>
    <small>text-overflow:ellipsis</small>
    <div class="list ellipsis">我说道,“爸爸,你走吧。”他望车外看了看,说,“我买几个橘子去。你就在此地,不要走动。”我看那边月台的栅栏外有几个卖东西的等着顾客。走到那边月台,须穿过铁道,须跳下去又爬上去。</div>
    <small>normal</small>
    <div class="list normal">我说道,“爸爸,你走吧。”他望车外看了看,说,“我买几个橘子去。你就在此地,不要走动。”我看那边月台的栅栏外有几个卖东西的等着顾客。走到那边月台,须穿过铁道,须跳下去又爬上去。</div>
</div>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值