zoukankan      html  css  js  c++  java
  • 一些常被你忽略的CSS小知识

      1.CSS的color属性并不是仅仅能用于文本显示

         对于CSS的color属性,相信全部Web开发者都使用过。假设你并不是一个特别有经

    验的程序猿,我相信你未必知道color属性除了能用在文本显示,还能够用作其他地方。它

    能够把页面上的全部的东西都变颜色。比方:

          无法显示的图片的alt文字、 list元素的边框、无序list元素前面的小点、有序list元素前面的数字和hr元素等


      <span style="font-size:14px;"> 1: <html>
    
       2: <head>
    
       3:     <meta http-equiv="content-type" content="text/html;charset=utf-8">
    
       4:     <style type="text/css">
    
       5:         #div1
    
       6:         {
    
       7:              375px;
    
       8:             height: 265px;
    
       9:             border: 1px solid blue;
    
      10:         }
    
      11:     </style>
    
      12: </head>
    
      13: <body>
    
      14: <div id="div1">
    
      15:      <img src="test.jpg" alt="图片载入失败" style="color:blue">
    
      16:     <ol style="color:red;">
    
      17:         <li style="border: 1px solid">一</li>
    
      18:         <li>二</li>
    
      19:         <li>三</li>
    
      20:     </ol>
    
      21:     <hr style="color:red" />
    
      22: </div>
    
      23: </body>
    
      24: </html></span>

    有图为证:

    1

        2.CSS里的visibility属性有个collapse属性值:collapse

           对于CSS里的visibility属性,相信你用过不下几百次。大多时候,你会把它的值设置

    成visible(这是全部页面元素的缺省值),或者是hidden。后者相当于display: none,但仍

    然占用页面空间。事实上visibility能够有第三种值,就是collapse。


    2



        3.CSS的background简写方式里新增了新的属性值

         在CSS2.1里,background属性的简写方式包括五种属性值 – background-color, background-

    image,background-repeat, background-attachment, and background-position。从CSS3開始,又添加�了3个新的属性值,加起来一共8个。以下是按顺序分别代表的意思:

    background: [background-color] [background-image] [background-repeat] [background-attachment]

    [background-position] / [ background-size] [background-origin] [background-clip];注意里面的反斜杠,它

    更font和border-radius里简写方式使用的反斜杠的使用方法相似。反斜杠能够在支持这样的写法的浏览器里在

    position后面接着写background-size。除此之外,你开能够添加�另外两个描写叙述它的属性值: background-

    origin 和 background-clip.它的语法用起来像以下这个样子:


       1: .example {
    
       2: background: aquamarine url(img.png)
    
       3: no-repeat
    
       4: scroll
    
       5: center center / 50%
    
       6: content-box content-box;
    
       7: }

        4.CSS的clip属性仅仅在绝对定位的元素上才会生效

            在style中添�

       1: img
    
       2:  {
    
       3:      200px;
    
       4:     height: 200px;
    
       5:     clip: rect(0px 50px 200px 0px)
    
       6:  }

           在HTML中

    1: <img src="bei.jpg" alt="图片载入失败" style="color:blue">
         

         发现并没有裁剪

         3

           对img进行绝对定位


       1: img
    
       2:     {
    
       3:          200px;
    
       4:         height: 200px;
    
       5:         position: absolute;
    
       6:         clip: rect(0px 50px 200px 0px)
    
       7:     }

          clip有效:

    4


        5.元素竖向的百分比设定是相对于容器的宽度,而不是高度

             当按百分比设定一个元素的宽度时,它是相对于父容器的宽度计算的,可是,对于一些表示竖向距离的属性,比如padding-top,padding-bottom,margin-top,margin-bottom等,当按百分比设定它们时,根据的也是父容器的宽度,而不是高度。给图片添加�一个padding-top:

     1: padding-top: 10%;

        依据效果和估算的距离就可以证明是依据宽度来算的

    5


        6.border-width属性能够使用提前定义常量值

           除了能够使用标准宽度值(比如5px或1em)外,border-width属性能够接受提前定义的常量值:medium, thin, 和 thick其实,假设你不给border-width属性赋值,那它的缺省值是“medium”。

    6


        7、你知道table里的empty-cells属性吗?

             css里的empty-cells属性是全部浏览器都支持的,甚至包含IE8,它的使用方法是以下这个样子:

     1: table { empty-cells: hide;}

    预计你从语义上已经猜出它的作用了。它是为HTML table服务的。它会告诉浏览器,当一个table单元格里没有东西时,就隐藏它。

      7 

    可是,empty-cells仅用于“分离边框”模式,即:border-collapse:separate;


        8、font-style的oblique属性值

             对与css的font-style属性,我预计大家每次见到的都是使用“normal”或 “italic”两个属性值。但其实,你还能够让它赋值为“oblique”。


        9、word-wrap和overflow-wrap是等效的

             word-wrap并非一个非经常常使用的CSS属性,但在特定的环境中确实非常实用的。我们经常使用的一个样例是让页面中显示一个长url时换行,而不是撑破页面。在原本的div中加入�一个子div,设置word-wrap属性

     

       1: <div style="250px;height:250px;border:1px solid red;word-wrap:break-word">
    
       2:          My father was a self-taught mandolin player.
    
       3:     He was one of the best string instrument players in our town.
    
       4:     He could not read music, but if he heard a tune a few times,
    
       5:     he could play it. When he was younger,
    
       6:  </div>

    效果

    8

    没有对长单词进行裁剪,而是将长单词作为总体另起一行显示。将word-wrap替换为overflow-wrap,效果一样。

    可是,须要注意的是word-break属性,其会对长单词进行裁剪


       1: <div style="250px;height:250px;border:1px solid red;word-break:break-all">
    
       2:          My father was a self-taught mandolin player.
    
       3:     He was one of the best string instrument players in our town.
    
       4:     He could not read music, but if he heard a tune a few times,
    
       5:     he could play it. When he was younger,
    
       6:     </div>

    效果

          9

    附:word-wrap取值:

    10

    word-break取值:

    11

    原文:http://www.ido321.com/450.html











  • 相关阅读:
    C#函数复习
    ADO数据库访问类查询、属性扩展
    ADO.NET完整的删除与修改, 实体类和数据访问类
    ADO.NET增删改查
    类库、委托
    多态
    面向对象:封装、继承
    面向对象思想:对象和类
    sql 存储过程、事务、视图、触发器
    连接查询,结构、循环语句
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/3998112.html
Copyright © 2011-2022 走看看