CSS总结

CSS

1、基本语法 2、引入方式 3、选择器 4、属性 5、文档流

6、内联元素和块级元素 7、盒子模型 8、浮动 9、定位 10、层叠规则 11、CSS3

1、基本语法

CSS 选择器

2、引入方式

  • 行内样式
  • 内部样式表
  • 外部样式表

3、选择器

  • 通用选择器 *
  • 标签选择器
  • id 选择器
  • class 选择器
  • 属性选择器
  • 派生选择器
    • 后代选择器
    • 子元素选择器
    • 相邻兄弟选择器
  • 组合选择器
  • 伪类选择器
  • 选择器优先级

4、属性

  • 单位

    • px
    • em:1em的默认大小是16px。可以通过下面这个公式将像素转换为em:**px/16=em
    • rem
    • vw
    • vh
  • 背景

    Property描述
    background-color属性指定元素的背景色
    background-image属性指定用作元素背景的图像。默认情况下,图像会重复,以覆盖整个元素。
    background-repeat默认情况下,background-image 属性在水平和垂直方向上都重复图像。
    background-position属性用于指定背景图像的位置
    background-attachment属性指定背景图像是应该滚动还是固定的(不会随页面的其余部分一起滚动
    属性描述
    background在一条声明中设置所有背景属性的简写属性。
    background-attachment设置背景图像是固定的还是与页面的其余部分一起滚动。
    background-clip规定背景的绘制区域。
    background-color设置元素的背景色。
    background-image设置元素的背景图像。
    background-origin规定在何处放置背景图像。
    background-position设置背景图像的开始位置。
    background-repeat设置背景图像是否及如何重复。
    background-size规定背景图像的尺寸。
    body {
        background-image: url("paper.gif");
    }
    
    body {
      background-image: url("gradient_bg.png");
    }
    // 仅在水平方向重复
    body {
      background-image: url("gradient_bg.png");
      background-repeat: repeat-x;
    }
    // 背景图像仅显示一次:
    body {
      background-image: url("tree.png");
      background-repeat: no-repeat;
    }
    
    // 把背景图片放在右上角:
    body {
      background-image: url("tree.png");
      background-repeat: no-repeat;
      background-position: right top;
    }
    //  属性指定背景图像是应该滚动还是固定的(不会随页面的其余部分一起滚动):
    body {
      background-image: url("tree.png");
      background-repeat: no-repeat;
      background-position: right top;
      background-attachment: fixed;
    }
    
    // 指定背景图像应随页面的其余部分一起滚动:
    body {
      background-image: url("tree.png");
      background-repeat: no-repeat;
      background-position: right top;
      background-attachment: scroll;
    }
    
    // 属性简写顺序
    background-color
    background-image
    background-repeat
    background-attachment
    background-position
    
    body {
      background-color: #ffffff;
      background-image: url("tree.png");
      background-repeat: no-repeat;
      background-position: right top;
    }
    // 简写
    body {
      background: #ffffff url("tree.png") no-repeat right top;
    }
    
  • 边框

    属性描述
    border简写属性,在一条声明中设置所有边框属性。
    border-color简写属性,设置四条边框的颜色。
    border-radius简写属性,可设置圆角的所有四个 border-*-radius 属性。
    border-style简写属性,设置四条边框的样式。
    border-width简写属性,设置四条边框的宽度。
    border-bottom简写属性,在一条声明中设置所有下边框属性。
    border-bottom-color设置下边框的颜色。
    border-bottom-style设置下边框的样式。
    border-bottom-width设置下边框的宽度。
    border-left简写属性,在一条声明中设置所有左边框属性。
    border-left-color设置左边框的颜色。
    border-left-style设置左边框的样式。
    border-left-width设置左边框的宽度。
    border-right简写属性,在一条声明中设置所有右边框属性。
    border-right-color设置右边框的颜色。
    border-right-style设置右边框的样式。
    border-right-width设置右边框的宽度。
    border-top简写属性,在一条声明中设置所有上边框属性。
    border-top-color设置上边框的颜色。
    border-top-style设置上边框的样式。
    border-top-width设置上边框的宽度。
  • 文本

  • 属性描述
    color设置文本颜色。
    direction指定文本的方向 / 书写方向。
    letter-spacing设置字符间距。
    line-height设置行高。
    text-align指定文本的水平对齐方式。
    text-decoration指定添加到文本的装饰效果。
    text-indent指定文本块中首行的缩进。
    text-shadow指定添加到文本的阴影效果。
    text-transform控制文本的大小写。
    text-overflow指定应如何向用户示意未显示的溢出内容。
    unicode-bidi与 direction 属性一起使用,设置或返回是否应重写文本来支持同一文档中的多种语言。
    vertical-align指定文本的垂直对齐方式。
    white-space指定如何处理元素内的空白。
    word-spacing设置单词间距。
    // 设置文本的颜色
    body {
      background-color: lightgrey;
      color: blue;
    }
    
    // 文本的水平对齐方式
    h1 {
      text-align: center;
      text-align: left;
      text-align: right;
    }
    // 元素的垂直对齐方式
    img.top {
      vertical-align: top;
      vertical-align: middle;
      vertical-align: bottom;
    }
    
    // 文字装饰
    a {
      text-decoration: none;
      text-decoration: overline;
      text-decoration: line-through;
      text-decoration: underline;
    }
    
    // 文字大小写
    p.uppercase {
      text-transform: uppercase;
      text-transform: lowercase;
      text-transform: capitalize;
    }
    
    p {
      text-indent: 50px;  // 文字缩进
      letter-spacing: 3px;  // 字母间距
      line-height: 0.8;  // 行高
      word-spacing: 10px;  // 字间距
      white-space: nowrap;  //  空白
    }
    
    // 文字阴影
    h1 {
      text-shadow: 2px 2px;  // 最简单的用法是只指定水平阴影(2px)和垂直阴影(2px)
      text-shadow: 2px 2px red;  // 接下来,向阴影添加颜色(红色):
      text-shadow: 2px 2px 5px red;    // 向阴影添加模糊效果(5px):
    }
    
  • 字体

    Property描述
    font在一个声明中设置所有的字体属性
    font-family指定文本的字体系列 Font Family:"宋体
    font-size指定文本的字体大小
    font-style指定文本的字体样式() normal 正常 italic 斜体 oblique 倾斜的文字
    font-variant以小型大写字体或者正常字体显示文本。
    font-weight指定字体的粗细。 font-weight: normal、 bold、900;(正常、加粗、)
  • 列表

    属性描述
    list-style简写属性。在一条声明中设置列表的所有属性。
    list-style-image指定图像作为列表项标记。
    list-style-position规定列表项标记(项目符号)的位置。
    list-style-type规定列表项标记的类型。
    ul.a {
      list-style-type: circle;
    }
    
    ul.b {
      list-style-type: square;
    }
    
    ol.c {
      list-style-type: upper-roman;
    }
    
    ol.d {
      list-style-type: lower-alpha;
    }
    
    ul {
      list-style-image: url('sqpurple.gif');
    }
    
    ul.a {
      list-style-position: outside;
    }
    
    ul.b {
      list-style-position: inside;
    }
    
    // list-style-type:none 属性也可以用于删除标记/项目符号。请注意,列表还拥有默认的外边距和内边距。要删除此内容, // 请在 <ul> 或 <ol> 中添加 margin:0 和 padding:0 :
    
    ul {
      list-style-type: none;
      margin: 0;
      padding: 0;
    }
    
    // 简写
    ul {
      list-style: square inside url("sqpurple.gif");
    }
    
  • 表格

    属性描述
    border简写属性。在一条声明中设置所有边框属性。
    border-collapse规定是否应折叠表格边框。
    border-spacing规定相邻单元格之间的边框的距离。
    caption-side规定表格标题的位置。
    empty-cells规定是否在表格中的空白单元格上显示边框和背景。
    table-layout设置用于表格的布局算法。

5、文档流

  • 标准流

  • 浮动流

  • 定位流

    bottom设置定位框的底部外边距边缘。
    clip剪裁绝对定位的元素。
    left设置定位框的左侧外边距边缘。
    position规定元素的定位类型。
    right设置定位框的右侧外边距边缘。
    top设置定位框的顶部外边距边缘。
    z-index设置元素的堆叠顺序。

6、内联元素和块级元素

7、盒子模型

8、浮动

9、定位

bottom设置定位框的底部外边距边缘。
clip剪裁绝对定位的元素。
left设置定位框的左侧外边距边缘。
position规定元素的定位类型。
right设置定位框的右侧外边距边缘。
top设置定位框的顶部外边距边缘。
z-index设置元素的堆叠顺序。

10、层叠规则

11、CSS3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值