汇总。

画一条 0.5px 的线

html
<meta name="viewport" content="width=device-width, initial-scale=0.5, minmum-scale=0.5, maxmum-scale=0.5">
html
<div style="height: 1px; background-color: black;margin-bottom: 20px;"></div>
<div style="height: 1px; background-color: red; transform: scaleY(0.5);"></div>

transition 和 animation 的区别

2. transition-duration

3. transition-timing-function

4. transition-delay

5. transition

2. animation-duration

3. animation-timing-function

4. animation-delay

5. animation-iteration-count

6. animation-direction

7. animation-play-state

8. animation-fill-mode

9. animation

css
/* 首先要设置一个关键帧 */
@keyframes move{
    form{
        margin-left:0;
        background-color: seashell;
    }
    30% {
        background-color: red;
    }
    60% {
        background-color: blue;
    }
    to{
        margin-left: 950px;
        background-color: seagreen;
    }
}
css
animation: move 4s infinite linear both 2s;

BFC

原文链接:https://blog.csdn.net/sinat_36422236/article/details/88763187

BFC 定义

BFC(Block formatting context)直译为”块级格式化上下文”。它是一个独立的渲染区域,只有Block-level box参与, 它规定了内部的Block-level Box如何布局,并且与这个区域外部毫不相干。

BFC 布局规则

BFC 创建

BFC 作用

垂直居中的方法

margin: auto 法

html
  <style>
    .box {
      height: 100px;
      width: 100px;
      background-color: red;
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
    }
  </style>
<body>
  <div class="box"></div>
</body>

translate() 法

html
  <style>
    .box {
      height: 100px;
      width: 100px;
      background-color: red;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%); /* 相对自身尺寸平移 */
    }
  </style>
<body>
  <div class="box"></div>
</body>

table-cell(未脱离文档流的)

html
  <style>
    .container {
      width: 600px;
      height: 600px;
      border: 1px solid black;
      display: table-cell;
      vertical-align: middle; /* 只能垂直居中 */
    }
    .box {
      height: 100px;
      width: 100px;
      background-color: red;
    }
  </style>
<body>
  <div class="container">
    <div class="box"></div>
  </div>
</body>

使用 Flex 布局

html
 <style>
    .container {
      width: 600px;
      height: 600px;
      border: 1px solid black;
      display: flex;
      align-items: center; /* 一根主轴垂直居中 */
      justify-content: center; /* 水平居中 */
    }
    .box {
      height: 100px;
      width: 100px;
      background-color: red;
    }
  </style>
<body>
  <div class="container">
    <div class="box"></div>
  </div>
</body>

块元素和行元素

多行文本的溢出省略号

css
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

visibility=hidden, opacity=0,display:none

双边距重叠问题(外边距折叠)

多个相邻(兄弟或者父子关系)普通流的块元素垂直方向 marigin 会重叠折叠的结果为:

57 CSS 之 float 深入了解 CSS 中的浮动布局、BFC、高度塌陷以及外边距折叠等问题。 float 布局float 属性 none 默认值,不浮动 left 元素向左浮动 right 元素向右浮动 注意:... 55 JS 隐式转换 深入了解 JavaScript 里的隐式转换问题。 === 和 == === 称为严格运算符,当对象类型的指向地址(堆)相同或原始类型(栈)如 Number、String、Boolean 相...