• CSS学习总结1


    1. 文字的水平居中
    将一段文字置于容器的水平中点,只需设置text-align特点即可:
      text-align:center;
    2. 容器的水平居中
    先为该容器设置一个清晰宽度,然后将margin的水平值设为auto即可。
      div#container {
        760px;
        margin:0 auto;
      }
    3. 文字的笔直居中
    单行文字的笔直居中,只需将行高与容器高设为持平即可。
    比方,容器中有一行数字。
      
    1234567890
    然后CSS这么写:
      div#container {height: 35px; line-height: 35px;}
    假如有n行文字,那么将行高设为容器高度的n分之一即可。
    4. 容器的笔直居中
    比方,有一大一小两个容器,请问怎么将小容器笔直居中?
      

        

        

      
    首要,将大容器的定位为relative。
      div#big{
        position:relative;
        height:480px;
      }
    然后,将小容器定位为absolute,再将它的左上角沿y轴下移50%,最终将它margin-top上移自身高度的50%即可。
      div#small {
        position: absolute;
        top: 50%;
        height: 240px;
        margin-top: -120px;
      }
    运用相同的思路,也能够做出水平居中的作用。
    5. 图像宽度的自习惯
    怎么使得较大的图像,能够主动习惯小容器的宽度?CSS能够这么写:
      img {max- 100%}
    可是IE6不支持max-width,所以遇到IE6时,运用IE条件注释,将句子改写为:
      img { 100%}
    6. 3D按钮
    要使按钮具有3D作用,只需将它的左上部边框设为淡色,右下部边框设为深色即可。
      div#button {
        background: #888;
        border: 1px solid;
        border-color: #999 #777 #777 #999;
      }
    7. font特点的方便写法
    font方便写法的格局为:
      body {
        font: font-style font-variant font-weight font-size line-height font-family; 
      }
    所以,
      body { 
        font-family: Arial, Helvetica, sans-serif; 
        font-size: 13px; 
        font-weight: normal; 
        font-variant: small-caps; 
        font-style: italic; 
        line-height: 150%; 
      }
    能够被写成:
      body { 
        font: italic small-caps normal 13px/150% Arial, Helvetica, sans-serif; 
      }
    8. link状况的设置次序
    link的四种状况,需求依照下面的前后次序进行设置:
      a:link 
      a:visited 
      a:hover 
      a:active
    9. IE条件注释
    你能够运用条件注释,设置只对IE发生作用的句子:
      
    还能够区别各种不一样的IE版别:
       
       
       
       
      
    10. IE6专用句子:办法一
    因为IE6不把html视为文档的根元素,所以运用这一点,能够写出只要IE6才干读到的句子:
      /* the following rules apply only to IE6 */
      * html{
      }
      * html body{
      }
      * html .foo{
      }
    IE7专用句子则要写成
      /* the following rules apply only to IE7 */
      *+html .foo{
      }
    11. IE专用句子:办法二
    除了IE6以外,一切浏览器都不能辨认特点前的下划线。而除了IE7以外,一切浏览器都不能辨认特点前的*号,因而能够写出只要这两个浏览器才干读到的句子:
      .element { 
        background: red; /* modern browsers */ 
        *background: green; /* IE 7 and below */ 
        _background: blue; /* IE6 exclusively */ 
      }
    12. CSS的优先性
    假如同一个容器被多条CSS句子界说,那么哪一个界说优先呢?
    根本规矩是:
      行内款式 > id款式 > class款式 > 标签名款式
    比方,有一个元素:
      
    行内款式是最优先的,然后别的设置的优先性,从低到高依次为:
      div < .class < div.class < #id < div#id < #id.class < div#id.class
    13. IE6的min-height
    IE6不支持min-height,有两种办法能够处理这个疑问:
    办法一:
      .element { 
        min-height: 500px; 
        height: auto !important; 
        height: 500px; 
      }
    共有三条CSS句子,榜首句是对于别的浏览器设置最小高度,第三句是对于IE设置最小高度,第二句则是让别的浏览器掩盖第三句的设置。
    办法二:
      .element { 
        min-height: 500px 
        _height: 500px 
      }
    _height只要IE6能读取。
    14. font-size基准
    浏览器的缺省字体大小是16px,你能够先将基准字体大小设为10px:
      body {font-size:62.5%;}
    后边一致选用em作为字体单位,2.4em就表明24px。
      h1 {font-size: 2.4 em}
    15. Text-transform和Font Variant
    Text-transform用于将一切字母成为小写字母、大写字母或首字母大写:
      p {text-transform: uppercase} 
      p {text-transform: lowercase} 
      p {text-transform: capitalize}
    Font Variant用于将字体成为小型的大写字母(即与小写字母等高的大写字母)。
      p {font-variant: small-caps}
    16. CSS重置
    CSS重置用于撤销浏览器的内置款式,请参阅YUI和Eric Meyer的款式表。
    17. 用图像充任列表象征
    默许情况下,浏览器运用一个黑圆圈作为列表象征,能够用图像替代它:
      ul {list-style: none}
      ul li { 
        background-image: url("path-to-your-image"); 
        background-repeat: none; 
        background-position: 0 0.5em; 
      }
    18. 通明
    将一个容器设为通明,能够运用下面的代码:
      .element { 
        filter:alpha(opacity=50); 
        -moz-opacity:0.5; 
        -khtml-opacity: 0.5; 
        opacity: 0.5; 
      }
    在这四行CSS句子中,榜首行是IE专用的,第二行用于Firefox,第三行用于webkit中心的浏览器,第四行用于Opera。
    19. CSS三角形
    怎么运用CSS生成一个三角形?
    先编写一个空元素
      
    然后,将它四个边框中的三个边框设为通明,剩余一个设为可见,就能够生成三角形作用:
      .triangle { 
        border-color: transparent transparent green transparent; 
        border-style: solid; 
        border- 0px 300px 300px 300px; 
        height: 0px; 
         0px; 
      }
    20. 制止主动换行
    假如你期望文字在一行中显现完结,不要主动换行,CSS指令如下:
      h1 { white-space:nowrap; }
    21. 用图像更换文字
    有时咱们需求在标题栏中运用图像,可是又有必要确保搜索引擎能够读到标题,CSS句子能够这么写:
      h1 { 
        text-indent:-9999px; 
        background:url("h1-image.jpg") no-repeat; 
        200px; 
        height:50px; 
      }
    22. 取得焦点的表单元素
    当一个表单元素取得焦点时,能够将其杰出显现:
      input:focus { border: 2px solid green; }
    23. !important规矩
    多条CSS句子互相冲突时,具有!important的句子将掩盖别的句子。因为IE不支持!important,所以也能够运用它区别不一样的浏览器。
      h1 { 
        color: red !important; 
        color: blue; 
      }
    上面这段句子的结果是,别的浏览器都显现赤色标题,只要IE显现蓝色标题。
    24. CSS提示框
    当鼠标移动到连接上方,会主动呈现一个提示框。
      连接文字 提示文字
    CSS这么写:
      a.tooltip {position: relative} 
      a.tooltip span {display:none; padding:5px; 200px;} 
      a:hover {background:#fff;} /*background-color is a must for IE6*/ 
      a.tooltip:hover span{display:inline; position:absolute;}
    25. 固定方位的页首
    当页面翻滚时,有时需求页首在方位固定不变,CSS句子能够这么写,作用拜见;海淘购物一定要选正规平台,海外购物平台欧莱名品http://www.eulike.com/拥有7年海淘购物服务经验,专业的购物团队帮您德国代购、美国代购,支持网站直接注册下单和淘宝下单,安全、方便、放心海淘!http://limpid.nl/lab/css/fixed/header:
      body{ margin:0;padding:100px 0 0 0;}
      div#header{
        position:absolute;
        top:0;
        left:0;
        100%;
        height:;
      }
      @media screen{
        body>div#header{position: fixed;}
      }
      * html body{overflow:hidden;}
      * html div#content{height:100%;overflow:auto;}
    IE6的另一种写法(用于固定方位的页脚):
      * html #footer {
        position:absolute;
        top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px');
    }
    26. 在IE6中设置PNG图像的通明作用
      .classname {
        background: url(image.png);
        _background: none;
        _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader
            (src='image.png', sizingMethod='crop');
      }
    27. 各类浏览器的专用句子
      /* IE6 and below */
      * html #uno { color: red }
      /* IE7 */
      *:first-child+html #dos { color: red } 
      /* IE7, FF, Saf, Opera */
      html>body #tres { color: red }
      /* IE8, FF, Saf, Opera (Everything but IE 6,7) */
      html>/**/body #cuatro { color: red }
      /* Opera 9.27 and below, safari 2 */
      html:first-child #cinco { color: red }
      /* Safari 2-3 */
      html[xmlns*=""] body:last-child #seis { color: red }
      /* safari 3+, chrome 1+, opera9+, ff 3.5+ */
      body:nth-of-type(1) #siete { color: red }
      /* safari 3+, chrome 1+, opera9+, ff 3.5+ */
      body:first-of-type #ocho { color: red }
      /* saf3+, chrome1+ */
      @media screen and (-webkit-min-device-pixel-ratio:0) {
        #diez { color: red }
      }
      /* iPhone / mobile webkit */
      @media screen and (max-device- 480px) {
        #veintiseis { color: red }
      }
      /* Safari 2 - 3.1 */
      html[xmlns*=""]:root #trece { color: red }
      /* Safari 2 - 3.1, Opera 9.25 */
      *|html[xmlns*=""] #catorce { color: red }
      /* Everything but IE6-8 */
      :root *> #quince { color: red }
      /* IE7 */
      *+html #dieciocho { color: red }
      /* Firefox only. 1+ */
      #veinticuatro, x:-moz-any-link { color: red }
      /* Firefox 3.0+ */
      #veinticinco, x:-moz-any-link, x:default { color: red }
      /***** Attribute Hacks ******/
      /* IE6 */
      #once { _color: blue }
      /* IE6, IE7 */
      #doce { *color: blue; /* or #color: blue */ }
      /* Everything but IE6 */
      #diecisiete { color/**/: blue }
      /* IE6, IE7, IE8 */
      #diecinueve { color: blue9; }
      /* IE7, IE8 */
      #veinte { color/***/: blue9; }
      /* IE6, IE7 -- acts as an !important */
      #veintesiete { color: blue !ie; } /* string after ! can be anything */
    28. 容器的水平缓笔直居中
    HTML代码如下:
      
        
        
      
    CSS代码如下:
      .logo {
        display: block;
        text-align: center;
        display: block;
        text-align: center;
        vertical-align: middle;
        border: 4px solid #dddddd;
        padding: 4px;
        height: 74px;
         74px; }
      .logo * {
        display: inline-block;
        height: 100%;
        vertical-align: middle; }
      .logo .photo {
        height: auto;
         auto;
        max- 100%;
        max-height: 100%; }
    29. CSS暗影
    外暗影:
      .shadow {
        -moz-box-shadow: 5px 5px 5px #ccc;
        -webkit-box-shadow: 5px 5px 5px #ccc;
        box-shadow: 5px 5px 5px #ccc;
      }
    内暗影:
      .shadow {
        -moz-box-shadow:inset 0 0 10px #000000;
        -webkit-box-shadow:inset 0 0 10px #000000;
        box-shadow:inset 0 0 10px #000000;
      }
    30. 撤销IE文本框的翻滚条
      textarea { overflow: auto; }

  • 相关阅读:
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作,编写MapReduce作业
    爬虫大作业
    第三章 熟悉常用的HDFS操作
    数据结构化与保存
    获取全部校园新闻
    爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离
    网络爬虫基础练习
    Hadoop综合大作业
    理解MapReduce
  • 原文地址:https://www.cnblogs.com/xm1-ybtk/p/5087264.html
Copyright © 2020-2023  润新知