Home  >  Article  >  Web Front-end  >  CSS + DIV 使用方法总结_html/css_WEB-ITnose

CSS + DIV 使用方法总结_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:481003browse

(原文链接:)


CCS = Cascading Style Sheets


行间样式表(不推荐):


内部样式表(不推荐):

    p{color:#F00;}

    ……


外部样式表(一般在head的title下面):


CSS书写结构:

{

    : ;

    ……

}

如:

p {

    color: #F00;

    font-size: 12px;

}


基本类型选择器:

  • 标签选择器:写在里面的标签,如:p{}。选中所有这一标签的内容。支持自定义标签。
  • class选择器:以“.”开头,如:.30font{},表示选取class为“30font”所有元素。
  • id选择器:以“#”开头。

  • 复合类型选择器:

  • 伪类选择器:用“:”隔开,如针对于的“a:link”、“a:hover”、“a:active”(鼠标按下)、“a:visited”;或“.myClass:hover”
  • 群组选择器:用“,”隔开,同时选择几个元素,如:“a,p,h3”
  • 标签指定选择器:如p.aa表示class="aa"的p标签,p#aa表示id="aa"的p标签
  • 包含选择器:以空格隔开,表示A里面的B,如“#top a”表示id="top"里面的标签
  • 兄弟相邻选择器:以“+”隔开,如“h1+p”表示与

    相邻的

    标签

  • 属性选择器:以“[]”隔开,如“p[align]”表示有align属性的

    标签

  • 通配符选择器:“*”,表示选择所有的元素

  • 字体和文本属性:

  • font-family:字体名称
  • font-size:字体大小,需要带单位px
  • font-weight:加粗。bold,bolder, lighter, 100, 200, ... 900 (表示百分之100, 200...)
  • font-style:字体风格。normal, italic, oblique(也是斜体,只对一些特殊字体有效)
  • font-variant:转换英文字母为大写。normal : 正常的字体,small-caps : 小型的大写字母字体
  • line-hight:行高
  • text-transform:capitalize:首字母大写,uppercase:全部大写,lowercase:全部小写,none:不变
  • text-decoration:文本修饰。underline,overline, line-through, blink, none,可以多个,用空格隔开
  • color:颜色
  • text-indet:首行缩进(需要带单位)
  • text-align:文本对齐,left, right, center, justify(两端对齐)
  • letter-spacing:字间隔(需要带单位px)

  • 背景属性:

  • background-color:背景颜色
  • background-image:背景图片(优先于背景颜色)
  • background-repeat:是否平铺背景图片。repeat(缺省), no-repeat, repeat-x, repeat-y(横向、纵向平铺)
  • background-attachment:是否跟随滚动条移动。fixed:不移动,scroll:移动(缺省)
  • background-position:背景定位,背景图片左上角原点坐标(x,y)的相对位移,或right, left,top, bottom, center
  • 背景属性可以合写,把属性值罗列出来,用空格隔开,如:

    body{

        background: #F00 url(images/bg.jpg) no-repeat fixed 50px 100px;

    }

    背景平铺:repeat-x 或 repeat-y,把图片按x轴或y轴(横向或竖向)平铺


    优先级排序:默认


    框模型(或盒模型):

  • 内联对象,按行显示:display:inline,由line-hight决定行高。如

    ,

  • 块对象,按块显示:display:block,由width和height决定宽和高,默认占一行。如

  • 内联对象转换为块对象后,就可以使用width和height属性了:a{display:block; width=10px; height:20px;}


  • padding:内填充(分top, bottom, left, right)
  • margin:外边距(分top, bottom, left, right)
  • border:边框(分top, bottom, left, right)
  • width:内容的宽度
  • height:内容的高度
  • 注:当两个元素上下排列时,他们间的margin会自动合并(都不是float或绝对定位的情况下)


    border的属性(分top, bottom, left, right):

  • style:线条样式(dotted, solid, double, 等)
  • width:粗细(单位px)
  • color:颜色
  • 可以缩写:border: solid 1px #FFF;

    单独设置一条边:

  • border-bottom: solid 2px #00F;
  • border-bottom-width: 2px;
  • (注:后面会覆盖前面的)


    margin和padding的设置:

  • margin: 1px (上下左右)
  • margin: 1px 2px 3px 4px; (上 右 下 左)
  • margin: 1px 2px; (上下 左右)
  • margin: 1px 2px 3px; (上 左右 下)
  • (注:padding的设置方法跟margin一样)


    浮动(float):

  • 浮动到普通流的上一层
  • float: left,浮动后向左,直到左边碰到边界或碰到同一层元素的右边界
  • float: right,浮动后向右,直到右边碰到边界或碰到同一层元素的左边界

  • 清理(clear):

  • 使浮动层继续在普通流保留占位
  • clear: both, left, right,应用于普通流,使普通流根据上一层的占位情况来决定自己的位置
  • 一般可以在浮动层和普通流直接加一个clear div来分隔排版,如:

        .clear{clear:both;}


    块水平居中:

    1. margin左右:auto(如:margin:0px auto;)
    2. 块要有具体的宽度值(width)

    注:body默认有8px的margin,取消方法:body{margin:0px;}

    块垂直居中(较少用):

    1. width:500px; height:200px; position: absolute; top:50%; left:50%; margin-top:-100px; margin-left:-250px;

    块内文本居中:

    1. 水平居中:text-align: center
    2. 垂直居中:行高=框高, 如:height:200px; line-height:200px(一行撑满整个div)


    ul列表:

  • 默认有padding和margin,取消的方法:ul{padding:0px; margin:0px;}
  • list-style:列表的样式(none, )
  • list-style-image:url(images/a.jpg);
  • 横排:li{float:left}
  • 设置分割线:li{ background:url(images/1.png) no-repeat bottom center;} 

  • 定位(通过position属性):

  • static:默认的定位方式,按行、按块显示。
  • relative:相对定位,元素偏移某个距离(使用top, right, bottom, left定位相对于原来的位置,原来空间占位不会释放)
  • absolute:元素从文档流完全删除(与float类似),并相对于其父框定位(使用top, right, bottom, left定位)。如:#aaa{position:absolute; top:100px; left:50px;}
  • fixed:跟absolute类似,不同的是定位为和浏览器窗口的距离。(可以用来做浮动广告)
  • 注:如果重叠,可以用z-index属性决定谁在上面,值大的在上。


    尺寸:

  • 固定值:如 width: 100px;
  • 缺省值:不填
  • 百分比:占父框的百分之多少,如 width: 80%;
  • min-height, min-width:元素的最小高度、宽度
  • max-height, max-width:元素的最大高度、宽度

  • 内容超出父框的处理:

  • overflow:hidden:超出的内容被剪切
  • overflow:scroll:总是显示滚动条
  • overflow:auto:当内容被剪切时,显示滚动条(body和textarea的缺省值为auto)
  • overflow-x:hidden:禁止横向滚动条
  • overflow-y:scroll:总是显示纵向滚动条
  • 注:如果父框不设置height,则父框会被撑高,直到达到max-height为止。


    浏览器滚动条设置:

    如:   html{

        scrollbar-base-color:#F00;

       }

    注:貌似只对IE有效。




    Photoshop切图过程:

    1. 使用参考线
    2. 使用切片工具
    3. 取消背景,使图片透明 
    4. 存储为web所用格式...
    5. 保存:切片:所有用户切片
    6. 保存
    7. 重命名

    原创文章,转载请注明转自Clement-Xu的csdn博客。)

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Previous article:CSS3画图3-手机模型_html/css_WEB-ITnoseNext article:使用CSS3各个属性实现小人的动画_html/css_WEB-ITnose

    Related articles

    See more