CSS基础知识小结

CSS,全称Cascading Style Sheets,中文翻译为“层叠样式表”。

一、样式表的引入

  1. 嵌入式:在<head></head>标签内
    <style type="text/css">
        CSS样式规则
    </style>
  2. 链接式:在<head></head>标签内
    <link href="main.css" rel="Stylesheet">
  3. 引入式:在<head></head>标签内
    <style type="text/css">
              @import url(main.css);
    </style> 
    

二、CSS样式规则

  1. 类别选择符

    p.bold { font-weight:bold; }
    <p class="bold">这个段落是粗体</p>
    
  2. ID选择符

    p#bold { font-weight:bold; }
    <p id="bold">这个段落是粗体</p>
  3. 群选择符

    可以同时为多个选择符应用同一套规则,每个选择符之间用逗号隔开。
    p, h1, h2{
        text-align: left;
    }

    还可以在群选择符中掺杂ID选择符或类别选择符

    p.navigation, h1#title{
        font-weight: bold;
    }
    
  4. Color属性

    p { color: red; }
    5种定义颜色的方法
    PropertyValueDescription
    color:<color keyword>设置颜色为给定的值,如red
    color:#rrggbb用HTML的16进制表示,如#FF00BB
    color:rgb(rrr,ggg,bbb)通过RGB三种颜色的数值(0到255),如rgb(100,200,255)
    color:rgb(rrr%,ggg%,bbb%)通过RGB三种颜色的百分比指定,如rgb(0%,100%,0% )
    color:inherit继承父值
  5. 背景颜色属性

    p { background-color: red; }
    5种定义背景颜色的方法
    PropertyValueDescription
    background-color:<color keyword>设置颜色为给定的值,如red
    background-color:#rrggbb用HTML的16进制表示,如#FF00BB
    background-color:rgb(rrr,ggg,bbb)通过RGB三种颜色的数值(0到255),如rgb(100,200,255)
    background-color:rgb(rrr%,ggg%,bbb%)通过RGB三种颜色的百分比指定,如rgb(0%,100%,0% )
    background-color:inherit继承父值
  6. 布局



  7. 边框

    (1) 边框宽度

    可以用关键字来指定边框宽度

    可以用具体的数值来指定


    边框宽度规则
    PropertyValueNotes
    border-width:thin 
    border-width:medium默认边框宽度
    border-width:thick 
    border-width:<length>用具体数值来指定
    border-top-width:<length>设置上边框
    border-right-width:<length>设置右边框
    border-bottom-width:<length>设置下边框
    border-left-width:<length>设置左边框

    (2) 边框颜色



    边框颜色规则
    PropertyValue TypeExampleResult
    border-color:color namered关键字设定边框颜色
    border-color:hex value#FFFFFF指定边框颜色
    border-color:rgb() valuergb(10%, 80%, 0)指定边框颜色

    (3) 边框风格



  8. 边界距

    边界距属性是用来指定两个元素边框之间的距离


    边界距规则
    PropertyValueNotes
    margin-top:<length>设置上边界距
    margin-right:<length>设置右边界距
    margin-bottom:<length>设置下边界距
    margin-left:<length>设置左边界距
    margin:<top> <right> <bottom> <left>设置每个边界距

  9. 填充属性

    填充属性用来控制元素边框内空间的大小


    填充属性规则
    PropertyValueNotes
    padding-top:<length>设置上填充
    padding-right:<length>设置右填充
    padding-bottom:<length>设置下填充
    padding-left:<length>设置左填充
    padding:<top> <right> <bottom> <left>设置每个填充

  10. 背景图片

    在CSS中,可以对任何元素指定背景图片
    body { 
        background-image: url("...");
    }
    
    Property
    ValueNotes
    background-image:url("<location>")通过网址来指定背景图片
    background-image:none无背景图片
    background-image:inherit继承父值

  11. 背景重复

    通过 background-repeat 属性来指定背景的重复方式

    背景重复规则
    PropertyValueNotes
    background-repeat:repeat重复背景
    background-repeat:repeat-x仅平行重复
    background-repeat:repeat-y仅垂直重复
    background-repeat:no-repeat不重复
    background-repeat:inherit继承父值

  12. 背景附着

    通过 background-attachment 属性控制背景是否随网页滚动

    背景附着规则
    PropertyValueNotes
    background-attachment:scroll背景随着滚动
    background-attachment:fixed背景固定
    background-attachment:inherit继承父值

  13. 背景定位

    此属性用来指定背景图片在网页的展示位置

    背景定位规则
    PropertyValueNotes
    background-position:<x> <y>用具体数值或百分比指定
    background-position:[top \ center \ botton]
    [left \ center \ right]
    用关键字定位

  14. 字体属性

    p { font-family: Verdana }

    字体规则
    PropertyValue
    font-family:Verdana
    font-family:Times
    font-family:Georgia
    font-family:Arial, Verdana, sans-serif
    font-family:Times New Roman, serif
    font-family:I Don't Have This Font, sans-serif
    说明:当 font-family 的属性值为多个值时,浏览器会先去找第一种字体,若没有第一种字体,则找第二种字体,以此类推。

  15. 字体风格属性

    此属性用来控制字体是否斜体
    p { font-style: italic; }

    PropertyValueNotes
    font-style:oblique斜体
    font-style:italic斜体
    font-style:normal正常

  16. 字体的粗细属性

    此属性用来设置字体的粗细程度
    p { font-weight: bold; }

    PropertyValue
    font-weight:normal
    font-weight:bold
    font-weight:bolder
    font-weight:lighter
    font-weight:<100 - 900>

  17. 字体大小属性

    设置字体的大小(绝对和相对)
    p { font-size: 12pt; }

    PropertyValueUnit Type
    font-size:12ptAbsolute
    font-size:12pxAbsolute
    font-size:mediumAbsolute
    font-size:smallerRelative
    font-size:normalRelative
    font-size:largerRelative
    font-size:50%Relative

  18. 行间距属性

    此属性用来指定行与行之间的垂直间距。
    p { line-height: 14pt; }

  19. 字体变量属性

    font-variant 用来控制小写变大写

    PropertyValue
    font-variant:normal
    font-variant:small-caps

     设置 font-variant:small-caps 属性后变为

  20. 文本缩进

    通过此属性可以在CSS中对每个段落的首行缩进。

    PropertyValueDescription
    text-indent:<length>根据具体数值对段落首行进行缩进
    text-indent:<percentage>根据百分比缩进

  21. 文本对齐属性

    CSS支持水平的对齐和适当的文本。

    PropertyValueDescription
    text-align:left文本左对齐
    text-align:right文本右对齐
    text-align:center文本居中对齐
    text-align:justify文本两端对齐

  22. 文本装饰

    在CSS中,文本装饰效果涉及到上划线,下划线,删除线等对文本的一些装饰效果。

    PropertyValueExample
    text-decoration:none
    text-decoration:underline
    text-decoration:overline
    text-decoration:line-through

  23. 文本变形

    文本变形是指大小写转换首字母大写等属性。

    PropertyValueDescription
    text-transform:none不变
    text-transform:capitalize首字母大写
    text-transform:uppercase全部变大写
    text-transform:lowercase全部变小写

  24. 链接与化类别

    用CSS的 :link 化类别用来指定没有访问过链接的属性。

    Pseudo-ClassExample UseDescription
    :linka:link { ... }设置未访问链接属性
    :visiteda:visited { ... }设置访问过链接属性
    :activea:active { ... }鼠标点击与释放之间时
    :hovera:hover { ... }鼠标悬停时



    整理来源:http://www.caopeng.org/css/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值