css3--文字效果

text-shadow

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>css3文本</title>  
<style type="text/css">
  * {
      margin: 0;
      padding: 0;
  }

  h1 {
      text-shadow: 5px 5px 5px red; /*x轴,y轴,模糊程度,颜色*/
  }
</style>
</head>
<body>
  <h1>Marvel Comics</h1>
</body>
</html>

效果如下:

 

 

CSS3文本溢出属性指定应向用户如何显示溢出内容

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>css3文本效果</title>  
<style type="text/css">
  * {
      margin: 0;
      padding: 0;
  }

  div.test {
      width: 12em;
      white-space: nowrap; /*文本显示在一行*/
      overflow: hidden;    /*超出文本的区域隐藏掉*/
      border: 1px solid #000;
  }
</style>
</head>
<body>
  <div class="test" style="text-overflow: ellipsis;">
    This is some long text that will not fit in the box
  </div>

  <div class="test">
    This is some long text that will fit in the box
  </div>

  <div class="test" style="text-overflow: '>>'">
    This is some long text that will fit in the box
  </div>
</body>
</html>

效果如下:

clip:默认

ellipsis:文本溢出显示省略号

text-overflow: '>>':只在火狐浏览器下有效

 

 

如果某个单词太长,不适合在一个区域内,它扩展到外面:

CSS3中,自动换行属性允许您强制文本换行 - 即使这意味着分裂它中间的一个字:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>css3文本效果</title>  
<style type="text/css">
  * {
      margin: 0;
      padding: 0;
  }

  .test {
      width: 11em;
      border: 1px solid #000;
      word-wrap: break-word; /*换行*/

  }
</style>
</head>
<body>
    <p class="test">This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.
    </p>
</body>
</html>

效果如下:

没加换行之前效果如下:

 

 

CSS3 单词拆分换行属性指定换行规则:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>文本效果</title>
<style> 
p.test1
{
    width:9em; 
    border:1px solid #000000;
    word-break:keep-all;
}

p.test2
{
    width:9em; 
    border:1px solid #000000;
    word-break:break-all;
}
</style>
</head>
<body>

<p class="test1"> This paragraph contains some text. This line will-break-at-hyphenates.</p>
<p class="test2"> This paragraph contains some text: The lines will break at any character.</p>

<p><b>注意:</b>  word-break 属性不兼容 Opera.</p>

</body>
</html>

效果如下:

word-wrap的break-word是沿用浏览器默认的换行方式,因此“Ooops too”后面空出了一段空白,右图word-break的break-all是改变浏览器默认的换行方式,让浏览器无视半角空格,直接根据容器尺寸换行,因此遇到长单词时,直接断词换行。效果上看 word-break: break-all;word-wrap: break-word;更节省页面空间。

转载于:https://www.cnblogs.com/qjuly/p/9028213.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值