AlexZ33 / lessions

自己练习的各种demo和课程
12 stars 2 forks source link

【CSS 教程】--- 总览 #83

Open AlexZ33 opened 4 years ago

AlexZ33 commented 4 years ago

【CSS 基础】--- 总览

1.css简介

  1. font-size 文字大小

    font-size: 12px;  (父元素)
    font-size: 16px;  (子元素)
    font-size: 2em;   (子元素,24px)
    font-size: 200%;   (子元素,24px)
    em, % 参照物是父元素字体大小
  2. font-family 字体

    font-family: arial; (英文是arial字体,中文是系统默认字体)
    font-family: arial, Verdana, sans-serif; (arial, Verdana都是英文字体,先用arial。中文字体用系统设置的sans-serif)
  3. font-weight 加粗: normal 、 bold

  4. font-style 倾斜:normal、 italic

  5. line-height 行高

    line-height: 40px; (父元素,行高为40px,字体大小为30px)
    line-height: 3em; (子元素,行高90px)
    line-height: 300%; (子元素,行高90px)
    line-height: 3; (子元素,行高90px)
    line-height: 300%; (父元素,行高90px)
    font-size: 16px(子元素,行高90px。行高为%的时候,先计算父元素行高是90px,然后子元素再计算)
    line-height: 3; (父元素,行高90px)
    font-size: 16px(子元素,行高48px。行高为%的时候,子元素直接继承父元素line-height: 3; 然后计算得到48px)
  6. font 文字缩写

    font: 30px arial;
    font: italic bold 30px/2 arial;
  7. color 文字颜色

  8. text-align 水平对齐 left、right、center、justify(两端对齐)

  9. vertical-align 垂直对齐 baseline(基线、默认)、 sub(上标)、super(上标)、top(这一行最高点)、text-top(文本最高点)、middle、bottom、text-bottom、60%(参照物行高)、20px(基线为起点上移20px)

  10. text-indent 首行缩进 2em(缩进2个字)、 10px、20%(参照物是容器的宽度)

  11. white-space 换行、空格、tab要不要保留 - 换行 空格、tab 自动换行
    'normal' 合并 合并 换行
    'nowrap' 合并 合并 不换行
    'pre' 保留 保留 不换行
    'pre-wrap' 保留 保留 换行
    'pre-line' 保留 合并 换行
  12. word-wrap 单词换行 normal、break-word

  13. word-break 字母换行 normal、 break-all

  14. text-shadow 文字阴影

    text-shadow: 1px 2px red;  (x轴偏移1px、y轴偏移2px、阴影为红色)
    text-shadow: 1px 2px 3px;  (x轴偏移1px、y轴偏移2px、模糊半径为3px、阴影为文字颜色)
  15. text-decoration: none、underline、overline、linethrough (可以同时写多个 )

  16. text-overflow: clip、ellipsis

    超出文字省略号
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  17. cursor 鼠标形状: (图片)、default(光标)、auto、help、none(消失)、pointer(手)、zoom-in(放大镜)、zoom-out(缩小镜)、move

  18. inherit 强制继承

    line-height: inherit;

    4.盒模型

  19. width: 200px、 50%(参照物父元素)max-width min-width

  20. height max-height min-height

  21. padding

    padding: 20px 10px; == padding: 20px 10px 20px 10px;
    padding: 20px 10px 30px; == padding: 20px 10px 30px 10px;
  22. margin :

    • 比padding多一个auto值
    • 水平合并: margin:0 auto;
    • margin合并
      1. 相邻元素取margin大的那个值
      2. 父元素与第一个、最后一个子元素合并
  23. border

    • border-color默认是内部字体颜色
  24. border-radius:

    • top-left、top-right、bottom-right、bottom-left
      border-radius: 0px 5px 10px 15px / 20px 15px 10px 5px;
      第一个角水平半径0px 垂直半径20px;
      border-top-left-radius: 10px;
  25. overflow 内容超出、overflow-x、overflow-y: visible、hidden、scroll、auto

  26. box-sizing: content-box、border-box

  27. box-shadow:

    box-shadow: 4px 6px 3px 0px red; 
    水平偏移、垂直偏移、模糊半径(往外1.5px模糊,往内1.5px模糊)、阴影大小
    颜色默认文字颜色
    box-shadow: inset 0px 0px 3px red; inset 内阴影
    阴影不占空间
  28. outline 轮廓,不占空间,在border以外

    outline: 1px solid red;

    5.背景

  29. background-color: transparent(默认值)

  30. background-image:

    background-image: url(red.png), url(blue.png);
    可以同时引入多个图片,先写的在上一层
  31. background-repeat: repeat、repeat-x、repeat-y、space(平铺的背景与背景见留空隙,使得平铺的背景不被截掉)、round(把背景缩放,使得平铺的背景不被截掉)、no-repeat

    background-image: url(red.png), url(blue.png);
    background-repeat: repeat-x;
    两个背景图,一个background-repeat值。两个背景图都按照repeat-x平铺
    background-repeat: repeat-x, repeat-y;
  32. background-attachment: scroll(默认值、背景图片不动,内容动)、local(背景图片随内容动)

  33. background-position:

    background-position:10px 20px;
    x轴偏移10px,y轴偏移20px
    background-position:10% 20%;
    图片的x轴10% y轴20%位置与 容器x轴10% y轴20%位置重合
    background-position:right;
    x轴居右,y轴默认居中
    background-position:right 10px top 20px;
  34. linear-gradient 线性渐变:

    backgroud-image: linear-gradient(red,blue);
    从上到下 红色渐变到蓝色
    backgroud-image: linear-gradient(to top,red,blue);
    backgroud-image: linear-gradient(to right bottom,red,blue);
    从左上角到右下角 红色渐变到蓝色
    backgroud-image: linear-gradient(0deg,red,blue);
    从下到上 红色渐变到蓝色
    linear-gradient(45deg,red,blue);
    0度是从下往上, 45deg是0deg的时候顺时针旋转45deg 红色渐变到蓝色
    backgroud-image: linear-gradient(red,green,blue);
    backgroud-image: linear-gradient(red,green 20%,blue);
    green在20%的位置
  35. radial-gradient 径向渐变:

    backgroud-image: radial-gradient(closet-side,red,blue);
    向最近的那条边渐变
    默认形状是椭圆
    backgroud-image: radial-gradient(circle,red,blue);
    渐变圆默认半价是  从元素圆心到farthest-corner(元素左上角)
    backgroud-image: radial-gradient(100px 50px at 0 0,red,green 20%,blue);
    椭圆x轴半径100px,y轴半径50px, 椭圆圆心移动到(0,0)位置
  36. 渐变repeat

    backgroud-image: repeating-linear-gradient(red,blue 20px, red40px);
    backgroud-image: repeating-radial-gradient(red,blue 20px, red40px);
  37. background-origin 背景从哪里开始出现: padding-box(默认值)、border-box、content-box

  38. background-clip 背景从哪里开始裁剪: border-box(默认值)、padding-box、content-box

  39. background-size 背景大小

    background-size: 50% 50%;
    宽高都是容器的50%
    background-size: cover;
    最小宽高=容器宽高
    background-size: contain;
    最大宽高=容器宽高
  40. background

    background: url(red.png) 0 0/20px 20px no-repeat content-box green;
    注:position(0,0)/size(20px 20px)
    content-box 即是origin又是clip
    背景颜色是绿色

    6.布局

  41. display:

    • block
    • inline
    • inline-block : 可以设置宽高、同行显示 input select button
    • none
    • visibility: hidden 不显示,但还占据原来的位置
    • 块元素水平居中 margin: 0 auto;
  42. position:

    • static
    • relative 在文档流中,设置了top、left后 仍然占据之前的元素
    • absolute: 脱离文档流、默认宽度为内容宽度、参照物是第一个定位元素或者根元素
    • fixed 脱离文档流、默认宽度为内容宽度、参照物为窗口
    • z-index 未设置z-index的时候,后面元素盖在前面元素上面
  43. float:left right none

    • 半脱离文档流(对后续元素脱离文档流 对于后续元素内容在文档流)
    • clear: both left right none 清楚浮动元素对后续元素的影响
      .clearfix:after { display: block; content: "."; clear: both; height: 0; overflow: hidden; visibility: hidden; }
  44. flex

    //在flex容器,设置 
    display: flex;
    //flex item 在文档流的子元素才是弹性元素 (孙元素不是)

    对flex容器设置

  1. rotate()

    //绕z轴顺时针旋转45度
    transform: rotate(45deg);
  2. translate()

    //往x轴正方向偏移50px
    transform: translate(50px);
    //往x轴正方向偏移50px,往y轴正方向偏移自身高度的20%
    transform: translate(50px, 20%);
    //往x轴反方向偏移50px
    transform: translateX(-50px);