【CSS】CSS 使用全教程

CSS 使用全教程

介紹

CSS(層疊樣式表,Cascading Style Sheets)是一種樣式表語言,用于描述 HTML 或 XML 文檔的布局和外觀,它允許開發者將文檔的內容結構與樣式表現分離,通過定義一系列的樣式規則來控制網頁元素的字體、顏色、布局、響應式設計等多方面的視覺效果,從而實現網站的美觀和一致性,并且CSS 功能豐富,不僅僅是布局頁面,還能夠提高網頁的維護性和可訪問性。

一個簡單的小例子:

在這里插入圖片描述
在經過CSS 樣式潤色后:
在這里插入圖片描述

<link
  href="./path/to/stylesheet/style.css"
  rel="stylesheet"
  type="text/css"
>
內部樣式表 <style>
<style>
  body {
    background-color: linen;
  }
</style>
內聯樣式 style
<h2 style="text-align: center;">
  居中文本
</h2>
<p style="color: blue; font-size: 18px;">
  藍色,18像素文本
</p>

添加 class 類

<div class="classname"></div>
<div class="class1 ... classn"></div>

支持一個元素上的多個類

!important

.post-title {
    color: blue !important;
}

覆蓋所有以前的樣式規則

選擇器

h1 { } 
#job-title { }
div.hero { }
div > p { }

查看: CSS 選擇器

文本顏色

color: #2a2aff;
color: green;
color: rgb(34, 12, 64, 0.6);
color: hsla(30 100% 50% / 0.6);

查看: Colors

背景

background-color: blue;
background-image: url("nyan-cat.gif");
background-image: url("../image.png");

查看: Backgrounds

字體

.page-title {
  font-weight: bold;
  font-size: 30px;
  font-family: "Courier New";
}

查看: Fonts

定位

.box {
  position: relative;
  top: 20px;
  left: 20px;
}

另見: Position

動畫

animation: 300ms linear 0s infinite;
animation: bounce 300ms linear infinite;

查看: Animation

注釋

/* 這是一行注釋 */
/* 這是
   多行注釋 */

Flex 布局

div {
  display: flex;
  justify-content: center;
}
div {
  display: flex;
  justify-content: flex-start;
}

查看: Flexbox | Flex Tricks

Grid 布局

#container {
  display: grid;
s  grid: repeat(2, 60px) / auto-flow 80px;
}
#container > div {
  background-color: #8ca0ff;
  width: 50px;
  height: 50px;
}

查看: Grid Layout

變量和計數器

counter-set: subsection;
counter-increment: subsection;
counter-reset: subsection 0;
:root {
  --bg-color: brown;
}
element {
  background-color: var(--bg-color);
}

查看: 動態內容

CSS 選擇器

示例

組選擇器
h1, h2 {
    color: red;
}
鏈選擇器
h3.section-heading {
    color: blue;
}
屬性選擇器
div[attribute="SomeValue"] {
    background-color: red;
}
第一個子選擇器
p:first-child {
    font-weight: bold;
}
無子選擇器
.box:empty {
  background: lime;
  height: 80px;
  width: 80px;
}

基礎

選擇器說明
*所有元素
div所有 div 標簽
.classname具有類的所有元素
#idname帶 ID 的元素
div,p所有 div 和段落
#idname *#idname 中的所有元素

另見: 元素 / 類 / ID / 通配 選擇器

組合器

選擇器說明
div.classname具有特定類名的 div
div#idname具有特定 ID 的 div
div pdiv 中的所有段落
div > p父元素是 div 的 P 標簽
div + pdiv 之后的第一個同級 P 標簽
div ~ pdiv 之后所有的同級 P 標簽

另見: 相鄰兄弟 / 通用兄弟 / 子 選擇器

屬性選擇器

選擇器說明
a[target]帶有 target 屬性 #
a[target="_blank"]在新標簽中打開 #
a[href^="/index"]以 /index 開頭 #
[class|="chair"]以chair開頭 #
[class*="chair"]包含chair #
[title~="chair"]包含單詞 chair #
a[href$=".doc"]以 .doc 結尾 #
[type="button"]指定類型 #

另見: 屬性選擇器

用戶操作偽類

選擇器說明
a:link鏈接正常 #
a:active鏈接處于點擊狀態 #
a:hover鼠標懸停鏈接 #
a:visited訪問鏈接 #

/* 未訪問鏈接 */
a:link { color: blue; }        
/* 已訪問鏈接 */
a:visited { color: purple; }   
/* 用戶鼠標懸停 */
a:hover { background: yellow; }
/* 激活鏈接 */
a:active { color: red; }       

偽類

選擇器說明
p::after在 p 之后添加內容 #
p::before在 p 之前添加內容 #
p::first-letterp中的第一個字母 #
p::first-linep 中的第一行 #
::selection由用戶選擇 #
::placeholder占位符 屬性 #
:root文檔根元素 #
:target突出顯示活動錨點 #
div:empty沒有子元素的元素 #
p:lang(en)帶有 en 語言屬性的 P #
:not(span)不是跨度的元素 #
:hostshadowDOM 中選擇自定義元素 #
::backdrop處于全屏模式的元素樣式 #
::markerli 項目符號或者數字 #
::file-selector-buttontype="file" input 按鈕 #

輸入偽類

選擇器說明
input:checked檢查 input #
input:disabled禁用 input #
input:enabled啟用的 input #
input:default有默認值的元素 #
input:blank空的輸入框 #
input:focusinput 有焦點 #
input:in-range范圍內的值 #
input:out-of-rangeinput 值超出范圍 #
input:validinput 有效值 #
input:invalidinput 無效值 #
input:optional沒有必需的屬性 #
input:required帶有必需屬性的 input #
input:read-only具有只讀屬性 #
input:read-write沒有只讀屬性 #
input:indeterminate帶有 indeterminate 狀態 #

結構偽類

選擇器說明
p:first-child第一個孩子 #
p:last-child最后一個孩子 #
p:first-of-type第一個 p 類型的元素 #
p:last-of-type某種類型的最后一個 #
p:nth-child(2)其父母的第二個孩子 #
p:nth-child(3n42)Nth-child(an + b) 公式 #
p:nth-last-child(2)后面的二孩 #
p:nth-of-type(2)其父級的第二個 p #
p:nth-last-of-type(2)...從后面 #
p:only-of-type其父級的唯一性 #
p:only-child其父母的唯一孩子 #
:is(header, div) p可以選擇的元素 #
:where(header, div) p:is 相同 #
a:has(> img)包含 img 元素的 a 元素 #
::first-letter第一行的第一個字母 #
::first-line第一行應用樣式 #

CSS 字體

屬性

屬性說明
font-family:字體族名或通用字體族名 #
font-size:字體的大小 #
letter-spacing:文本字符的間距 #
line-height:多行文本間距 #
font-weight:粗細程度 #
font-style:字體樣式 #
text-decoration:文本的修飾線外觀 #
text-align:相對它的塊父元素對齊 #
text-transform:指定文本大小寫 #

另見: Font

速記

font: italic    400     14px    /     1.5        sans-serif
      ┈┈┬┈┈┈    ┈┬┈     ┈┬┈┈          ┈┬┈        ┈┬┈┈┈┈┈┈┈┈
       樣式      粗細    大小(必需的)    行高        字體(必需的)

示例

font-family: Arial, sans-serif;
font-size: 12pt;
letter-spacing: 0.02em;

大小寫

div {
  /* 首字母大寫 Hello */
  text-transform: capitalize;
  /* 字母大寫 HELLO */
  text-transform: uppercase;
  /* 字母小寫 hello */
  text-transform: lowercase;
}

@font-face

@font-face {
  font-family: 'Glegoo';
  src: url('../Glegoo.woff');
}

CSS 顏色

命名顏色

color: red;
color: orange;
color: tan;
color: rebeccapurple;

更多標準顏色

十六進制顏色

color: #090;
color: #009900;
color: #090a;
color: #009900aa;

rgb() 顏色

color: rgb(34, 12, 64, 0.6);
color: rgba(34, 12, 64, 0.6);
color: rgb(34 12 64 / 0.6);
color: rgba(34 12 64 / 0.3);
color: rgb(34.0 12 64 / 60%);
color: rgba(34.6 12 64 / 30%);

HSL 顏色

color: hsl(30, 100%, 50%, 0.6);
color: hsla(30, 100%, 50%, 0.6);
color: hsl(30 100% 50% / 0.6);
color: hsla(30 100% 50% / 0.6);
color: hsl(30.0 100% 50% / 60%);
color: hsla(30.2 100% 50% / 60%);

其它

color: inherit;
color: initial;
color: unset;
color: transparent;
color: currentcolor; /* 關鍵字 */

全局值

/* 全局值 */
color: inherit;
color: initial;
color: unset;

CSS 背景

屬性

屬性說明
background:(速記)
background-color:查看: Colors
background-image:一個或者多個背景圖像
background-position:背景圖片設置初始位置
background-size:背景圖片大小
background-clip:背景(圖片或顏色)是否延伸到邊框、內邊距盒子、內容盒子下面
background-repeat:圖像重復方式
background-attachment:scroll/fixed/local

速記

background: #ff0   url(a.jpg)   left     top    /  100px auto   no-repeat   fixed;
            #abc   url(b.png)   center   center /  cover        repeat-x    local;
            ┈┬┈┈    ┈┬┈┈┈┈┈┈┈   ┈┬┈┈     ┈┬┈       ┈┈┬┈┈┈┈┈┈┈   ┈┈┬┈┈┈┈┈┈   ┈┈┬┈┈┈
            顏色     圖片         位置x    位置x       圖片大小     圖像重復方式  位置是在視口內固定

示例

background: url(img_flwr.gif) right bottom no-repeat, url(paper.gif) left top repeat;
background: url(img_man.jpg) no-repeat center;
background: rgb(2,0,36);
background: linear-gradient(90deg, rgba(2,0,36,1) 0%,
  rgba(13,232,230,1) 35%,
  rgba(0,212,255,1) 100%);

CSS 盒子模型

最大值/最小值

.column {
  max-width: 200px; /* 最大寬度 200 像素 */
  width: 500px;     /* 寬度 500 像素 */
}

另見: max-width / min-width / max-height / min-height

邊距/補白

.block-one {
  margin: 20px;  /* 邊距 20 像素 */
  padding: 10px; /* 補白 10 像素 */
}

另見: 邊距(margin) / 補白(padding)

Box-sizing

.container {
  /* 設置的邊框和補白的值是包含在 width 內的 */
  box-sizing: border-box;
}

另見: box-sizing

能見度

.invisible-elements {
  visibility: hidden; /* 隱藏元素 */
}

另見: Visibility

Auto 關鍵字

div {
  /* 覽器自己選擇一個合適的外邊距 */
  margin: auto;
}

另見: 邊距(margin)

溢出(Overflow)

.small-block {
  /* 瀏覽器總是顯示滾動條 */
  overflow: scroll;
}

另見: 溢出(overflow)

CSS 動畫

速記

animation:  bounce   300ms      linear     100ms    infinite   alternate-reverse  both                   reverse  
            ┈┬┈┈     ┈┬┈┈┈      ┈┬┈┈┈┈     ┈┈┬┈┈    ┈┈┈┬┈┈┈┈   ┈┈┬┈┈┈┈┈┈┈┈┈┈┈┈┈┈  ┈┈┬┈┈┈                 ┈┈┬┈┈┈
            動畫名    動畫時間     緩動函數    延遲     運行的次數   動畫是否反向播放      如何將樣式應用于其目標    是否運行或者暫停

屬性

屬性說明
animation:(速記)
animation-name:動畫名 #
animation-duration:動畫周期的時長 #
animation-timing-function:緩動函數 #
animation-delay:延遲 #
animation-iteration-count:運行的次數 #
animation-direction:動畫是否反向播放 #
animation-fill-mode:如何將樣式應用于其目標 #
animation-play-state:是否運行或者暫停 #

另見: 動畫(Animation)

示例

/* @keyframes duration | timing-function | delay |
   iteration-count | direction | fill-mode | play-state | name */
animation: 3s ease-in 1s 2 reverse both paused slidein;
/* @keyframes duration | timing-function | delay | name */
animation: 3s linear 1s slidein;
/* @keyframes duration | name */
animation: 3s slidein;
animation: 4s linear 0s infinite alternate move_eye;
animation: bounce 300ms linear 0s infinite normal;
animation: bounce 300ms linear infinite;
animation: bounce 300ms linear infinite alternate-reverse;
animation: bounce 300ms linear 2s infinite alternate-reverse forwards normal;

Javascript 事件

.one('webkitAnimationEnd oanimationend msAnimationEnd animationend')

CSS Flexbox

簡單實例

.container {
  display: flex;
}
.container > div {
  flex: 1 1 auto;
}

容器

.container {
  display: flex;
  display: inline-flex;
  
  flex-direction: row;            /* ltr - 行(左向右) ? */
  flex-direction: row-reverse;    /* rtl - 行(右向左) ? */
  flex-direction: column;         /* top-bottom ▼ */
  flex-direction: column-reverse; /* bottom-top ▲ */
  
  flex-wrap: nowrap;       /* 擺放到一行 */
  flex-wrap: wrap;         /* 被打斷到多個行中 */
  
  align-items: flex-start; /* 垂直對齊 - 頂部 */
  align-items: flex-end;   /* 垂直對齊 - 底部 */
  align-items: center;     /* 垂直對齊 - 中間 */
  align-items: stretch;    /* 所有人都一樣的高度 (默認) */
  
  justify-content: flex-start;    /* [???        ] */
  justify-content: center;        /* [    ■■■    ] */
  justify-content: flex-end;      /* [        ???] */
  justify-content: space-between; /* [?    ■    ?] */
  justify-content: space-around;  /* [ ■   ■   ■ ] */
  justify-content: space-evenly;  /* [  ■  ■  ■  ] */
}

子元素

.container > div {

  /* 這個: */
  flex: 1 0 auto;
  /* 相當于這個: */
  flex-grow: 1;
  flex-shrink: 0;
  flex-basis: auto;

  order: 1;

  align-self: flex-start;  /* left */
  margin-left: auto;       /* right */
}

justify-content

justify-content: flex-start | flex-end | center | space-between

flex-start:左對齊(默認值)

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆╭┈┈╮╭┈╮╭┈┈┈╮                     ┆
┆╰┈┈╯╰┈╯╰┈┈┈╯                     ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

flex-end:右對齊

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆                     ╭┈┈╮╭┈╮╭┈┈┈╮┆
┆                     ╰┈┈╯╰┈╯╰┈┈┈╯┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

center: 居中

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆          ╭┈┈╮╭┈╮╭┈┈┈╮           ┆
┆          ╰┈┈╯╰┈╯╰┈┈┈╯           ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

space-between:兩端對齊,項目之間的間隔都相等

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆╭┈┈╮           ╭┈╮          ╭┈┈┈╮┆
┆╰┈┈╯           ╰┈╯          ╰┈┈┈╯┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

space-around:每個項目兩側的間隔相等,項目之間的間隔比項目與邊框的間隔大一倍

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆   ╭┈┈╮        ╭┈╮       ╭┈┈┈╮   ┆
┆   ╰┈┈╯        ╰┈╯       ╰┈┈┈╯   ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

上面示例,假設主軸為從左到右

flex-wrap

flex-wrap: nowrap | wrap | wrap-reverse;

nowrap:不換行(默認)

1╮╭2╮╭3╮╭4╮╭5╮╭6╮╭7╮╭8╮╭9╮╭10╰┈╯╰┈╯╰┈╯╰┈╯╰┈╯╰┈╯╰┈╯╰┈╯╰┈╯╰┈┈╯

wrap:換行,第一行在 上方

1┈╮ ╭2┈╮ ╭3┈╮ ╭4┈╮ ╭5┈╮ ╭6┈╮ ╭7┈╮
╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯
8┈╮ ╭9┈╮ ╭10╰┈┈╯ ╰┈┈╯ ╰┈┈╯

wrap-reverse:換行,第一行在 下方

8┈╮ ╭9┈╮ ╭10╰┈┈╯ ╰┈┈╯ ╰┈┈╯
1┈╮ ╭2┈╮ ╭3┈╮ ╭4┈╮ ╭5┈╮ ╭6┈╮ ╭7┈╮
╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯

項目都排在一條線(又稱"軸線")上

flex-direction

flex-direction: row | row-reverse | column | column-reverse;

╭┈┈╮  ▲         ╭┈┈╮  ┆
╰┈┈╯  ┆         ╰┈┈╯  ┆
╭┈┈╮  ┆         ╭┈┈╮  ┆
╰┈┈╯  ┆         ╰┈┈╯  ┆     ┈┈┈┈┈┈┈┈┈┈┈?    ?┈┈┈┈┈┈┈┈┈┈┈
╭┈┈╮  ┆         ╭┈┈╮  ┆    ╭┈┈╮ ╭┈┈╮ ╭┈┈╮  ╭┈┈╮ ╭┈┈╮ ╭┈┈╮
╰┈┈╯  ┆         ╰┈┈╯  ▼    ╰┈┈╯ ╰┈┈╯ ╰┈┈╯  ╰┈┈╯ ╰┈┈╯ ╰┈┈╯
┈┬┈┈┈┈┈┈        ┈┬┈┈┈┈┈┈    ┈┬┈┈┈┈┈┈┈┈┈┈┈   ┈┬┈┈┈┈┈┈┈┈┈┈┈ 
column-reverse  column       row             row-reverse

屬性決定主軸的方向(即項目的排列方向)

align-items

align-items: flex-start | flex-end | center | baseline | stretch;

  ? flex-start(起點對齊)    ? flex-end(終點對齊)
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮  ╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆ ╭┈┈╮ ╭┈┈╮ ╭┈┈╮ ╭┈┈╮ ┆  ┆                     ┆
┆ ┆  ┆ ┆  ┆ ╰┈┈╯ ┆  ┆ ┆  ┆      ╭┈┈╮           ┆
┆ ╰┈┈╯ ┆  ┆      ╰┈┈╯ ┆  ┆ ╭┈┈╮ ┆  ┆      ╭┈┈╮ ┆
┆      ╰┈┈╯           ┆  ┆ ┆  ┆ ┆  ┆ ╭┈┈╮ ┆  ┆ ┆
┆                     ┆  ┆ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯  ╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯
  ? center(中點對齊)        ? stretch(占滿整個容器的高度)
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮  ╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆      ╭┈┈╮           ┆  ┆ ╭┈┈╮ ╭┈┈╮ ╭┈┈╮ ╭┈┈╮ ┆
┆ ╭┈┈╮ ┆  ┆      ╭┈┈╮ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆
┆ ┆  ┆ ┆  ┆ ╭┈┈╮ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆
┆ ┆  ┆ ┆  ┆ ╰┈┈╯ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆
┆ ╰┈┈╯ ┆  ┆      ╰┈┈╯ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆  ┆ ┆
┆      ╰┈┈╯           ┆  ┆ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈╯ ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯  ╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯
  ? baseline(第一行文字的基線對齊)
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆  ╭┈┈┈┈┈┈╮               ╭┈┈┈┈┈┈╮             ┆
┆  ┆      ┆ ╭┈┈┈┈╮ ╭┈┈┈┈╮ ┆      ┆ ╭┈┈┈┈╮╭┈┈┈┈╮┆
┆  ┆ text ┆ ┆text┆ ┆text┆ ┆ text ┆ ┆text┆┆text┆┆
┆  ┆      ┆ ╰┈┈┈┈╯ ┆    ┆ ┆      ┆ ╰┈┈┈┈╯┆    ┆┆
┆  ╰┈┈┈┈┈┈╯        ╰┈┈┈┈╯ ╰┈┈┈┈┈┈╯       ╰┈┈┈┈╯┆
┆                                              ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

align-content

align-content: flex-start | flex-end | center | space-between | space-around | stretch;

 ? flex-start(起點對齊)     ? flex-end(終點對齊)
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮  ╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆ ╭┈┈╮╭┈╮╭┈┈┈╮╭╮╭┈┈┈┈╮ ┆  ┆                      ┆
┆ ╰┈┈╯╰┈╯╰┈┈┈╯╰╯╰┈┈┈┈╯ ┆  ┆ ╭┈┈╮╭┈╮╭┈┈┈╮╭╮╭┈┈┈┈╮ ┆
┆ ╭┈┈┈╮╭╮              ┆  ┆ ╰┈┈╯╰┈╯╰┈┈┈╯╰╯╰┈┈┈┈╯ ┆
┆ ╰┈┈┈╯╰╯              ┆  ┆ ╭┈┈┈╮╭╮              ┆
┆                      ┆  ┆ ╰┈┈┈╯╰╯              ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯  ╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯
 ? center(中點對齊)         ? stretch(滿整個交叉軸)
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮  ╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆                      ┆  ┆ ╭┈┈╮╭┈╮╭┈┈┈╮╭╮╭┈┈┈┈╮ ┆
┆ ╭┈┈╮╭┈╮╭┈┈┈╮╭╮╭┈┈┈┈╮ ┆  ┆ ┆  ┆┆ ┆┆   ┆┆┆┆    ┆ ┆
┆ ╰┈┈╯╰┈╯╰┈┈┈╯╰╯╰┈┈┈┈╯ ┆  ┆ ╰┈┈╯╰┈╯╰┈┈┈╯╰╯╰┈┈┈┈╯ ┆
┆ ╭┈┈┈╮╭╮              ┆  ┆ ╭┈┈┈╮╭╮╭┈╮           ┆
┆ ╰┈┈┈╯╰╯              ┆  ┆ ┆   ┆┆┆┆ ┆           ┆
┆                      ┆  ┆ ╰┈┈┈╯╰╯╰┈╯           ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯  ╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯
 ? space-between(兩端對齊)  ? space-around(均勻分布項目)
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮  ╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮ 
┆ ╭┈┈╮╭┈┈╮╭┈┈╮╭┈┈╮╭┈┈╮ ┆  ┆                      ┆ 
┆ ╰┈┈╯╰┈┈╯╰┈┈╯╰┈┈╯╰┈┈╯ ┆  ┆ ╭┈┈╮╭┈┈╮╭┈┈╮╭┈┈╮╭┈┈╮ ┆ 
┆                      ┆  ┆ ╰┈┈╯╰┈┈╯╰┈┈╯╰┈┈╯╰┈┈╯ ┆ 
┆                      ┆  ┆                      ┆ 
┆                      ┆  ┆ ╭┈┈╮                 ┆ 
┆ ╭┈┈╮                 ┆  ┆ ╰┈┈╯                 ┆ 
┆ ╰┈┈╯                 ┆  ┆                      ┆ 
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯  ╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯ 

order

.item {
  order: <integer>;
}

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮ ╭┈┈┈┈┈┈┈┈┈╮
┆ ╭1┈╮ ╭1┈┈╮ ╭1┈╮ ╭2┈╮ ╭3┈┈┈┈┈┈╮ ┆ ┆ ╭2┈┈┈┈╮ ┆
┆ ╰┈┈╯ ╰┈┈┈╯ ╰┈┈╯ ╰┈┈╯ ╰┈┈┈┈┈┈┈╯ ┆ ┆ ╰┈┈┈┈┈╯ ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯ ┆ ╭2┈┈┈┈╮ ┆
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮ ┆ ╰┈┈┈┈┈╯ ┆
┆ ╭-┈┈╮ ╭┈┈┈╮ ╭┈┈┈┈┈┈┈┈╮ ╭┈┈┈╮   ┆ ┆ ╭99┈┈┈╮ ┆
┆ ┆-1 ┆ ┆ 1 ┆ ┆ 2      ┆ ┆ 5 ┆   ┆ ┆ ┆     ┆ ┆
┆ ╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈┈┈┈┈┈╯ ╰┈┈┈╯   ┆ ┆ ╰┈┈┈┈┈╯ ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯ ╰┈┈┈┈┈┈┈┈┈╯

屬性 order 定義項目的排列順序。數值越小,排列越靠前,默認為 0

flex-grow

.item {
  flex-grow: <number>; /* default 0 */
}

╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆ ╭┈┈1┈┈╮╭┈┈2┈┈╮╭┈┈1┈┈╮ ┆
┆ ╰┈┈┈┈┈╯╰┈┈┈┈┈╯╰┈┈┈┈┈╯ ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
┆ ╭┈1┈╮╭┈┈┈┈2┈┈┈┈╮╭┈1┈╮ ┆
┆ ╰┈┈┈╯╰┈┈┈┈┈┈┈┈┈╯╰┈┈┈╯ ┆
╰┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╯

屬性 flex-grow 定義項目的放大比例,默認為0,即如果存在剩余空間,也不放大

CSS Flexbox 技巧

垂直中心

.container {
  display: flex;
}
.container > div {
  width: 100px;
  height: 100px;
  margin: auto;
}

垂直中心 (2)

.container {
  display: flex;
  /* 垂直的 */
  align-items: center; 
  /* 水平的 */
  justify-content: center;
}

重新排序

.container > .top {
 order: 1;
}
.container > .bottom {
 order: 2;
}

移動布局

.container {
  display: flex;
  flex-direction: column;
}
.container > .top {
  flex: 0 0 100px;
}
.container > .content {
  flex: 1 0 auto;
}

一個固定高度的頂部欄和一個動態高度的內容區域

Table-like 像表格

.container {
  display: flex;
}
/* 這里的“px”值只是建議的百分比 */
.container > .checkbox { flex: 1 0 20px; }
.container > .subject  { flex: 1 0 400px; }
.container > .date     { flex: 1 0 120px; }

這會創建具有不同寬度的列,但會根據情況相應地調整大小

Vertical 垂直的

.container {
  align-items: center;
}

垂直居中所有項目

左和右

.menu > .left  { align-self: flex-start; }
.menu > .right { align-self: flex-end; }

CSS Grid 網格布局

網格模板列

#grid-container {
  display: grid;
  width: 100px;
  grid-template-columns: 20px 20% 60%;
}

fr 相對單位

.grid {
  display: grid;
  width: 100px;
  grid-template-columns: 1fr 60px 1fr;
}

Grid Gap 網格間隙

/* 行間距為 20px */
/* 列之間的距離是 10px */
#grid-container {
  display: grid;
  grid-gap: 20px 10px;
}

CSS 網格行

CSS 語法:

  • grid-row: grid-row-start / grid-row-end;
實例
.item {
  grid-row: 1 / span 2;
}

CSS 塊級網格

#grid-container {
    display: block;
}

CSS 內聯級別網格

#grid-container {
  display: inline-grid;
}

CSS 網格行間隙

grid-row-gap: length;

任何合法的長度值,例如 px%0 是默認值

CSS 網格區域

.item1 {
  grid-area: 2 / 1 / span 2 / span 3;
}

minmax() 函數

.grid {
  display: grid;
  grid-template-columns: 100px minmax(100px, 500px) 100px; 
}

定義了一個長寬范圍的閉區間

grid-row-start & grid-row-end

CSS 語法:

  • grid-row-start: auto|row-line;
  • grid-row-end: auto|row-line|span n;
實例
grid-row-start: 2;
grid-row-end: span 2;

對齊項目

#container {
  display: grid;
  justify-items: center;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  grid-gap: 10px;
}

CSS 網格模板區域

.item {
  grid-area: nav;
}
.grid-container {
  display: grid;
  grid-template-areas:
  'nav nav . .'
  'nav nav . .';
}

Justify Self

#grid-container {
  display: grid;
  justify-items: start;
}
.grid-items {
  justify-self: end;
}

網格項目位于行的右側(末尾)

對齊項目

#container {
  display: grid;
  align-items: start;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  grid-gap: 10px;
}

CSS 動態內容

變量

定義 CSS 變量

:root {
  --first-color: #16f;
  --second-color: #ff7;
}

變量用法

#firstParagraph {
  background-color: var(--first-color);
  color: var(--second-color);
}

另見: CSS Variable

計數器

/* Set "my-counter" to 0 */
counter-set: my-counter;
/* Increment "my-counter" by 1 */
counter-increment: my-counter;
/* Decrement "my-counter" by 1 */
counter-increment: my-counter -1;
/* Reset "my-counter" to 0 */
counter-reset: my-counter;

另見: Counter set

使用計數器

body { counter-reset: section; }
h3::before {
  counter-increment: section; 
  content: "Section." counter(section);
}
ol {
  counter-reset: section;   
  list-style-type: none;
}
li::before {
  counter-increment: section;
  content: counters(section, ".") " "; 
}

CSS 函數

calc()

div {
  width: calc(100% - 30px);
  height: calc(100% - 30px);
}

calc() CSS 函數允許您在指定 CSS 屬性值時執行計算

clamp()

font-size: clamp(1rem, 10vw, 2rem);

設置隨窗口大小改變的字體大小

attr()

p:before {
  content: attr(data-foo) " ";
}

獲取選擇到的元素的某一 HTML 屬性值

counter()

返回一個代表計數器的當前值的字符串

<ol>
  <li></li>
  <li></li>
  <li></li>
</ol>
ol {
  counter-reset: listCounter;
}
li {
  counter-increment: listCounter;
}
li::after {
  content: "[" counter(listCounter) "] == ["
    counter(listCounter, upper-roman) "]";
}

顯示

1. [1]==[I]
2. [2]==[II]
3. [3]==[III]

counters()

ol {
  counter-reset: count;
}
li {
  counter-increment: count;
}
li::marker {
   content: counters(count, '.', upper-alpha) ') ';
}
li::before {
  content: counters(count, ".", decimal-leading-zero) " == " counters(count, ".", lower-alpha);
}

嵌套計數器,返回表示指定計數器當前值的連接字符串

env()

<meta name="viewport" content="... viewport-fit=cover">

body {
  padding:
    env(safe-area-inset-top, 20px)
    env(safe-area-inset-right, 20px)
    env(safe-area-inset-bottom, 20px)
    env(safe-area-inset-left, 20px);
}

用戶代理定義的環境變量值插入你的 CSS 中

fit-content()

fit-content(200px)
fit-content(5cm)
fit-content(30vw)
fit-content(100ch)

將給定大小夾緊為可用大小

max()

從一個逗號分隔的表達式列表中選擇最大(正方向)的值作為屬性的值

width: max(10vw, 4em, 80px);

例子中,寬度最小會是 80px,除非視圖寬度大于 800px 或者是一個 em 比 20px 寬

min()

width: min(1vw, 4em, 80px);

從逗號分隔符表達式中選擇一個最小值作為 CSS 的屬性值

minmax()

minmax(200px, 1fr)
minmax(400px, 50%)
minmax(30%, 300px)
minmax(100px, max-content)
minmax(min-content, 400px)
minmax(max-content, auto)
minmax(auto, 300px)
minmax(min-content, auto)

repeat() 軌道列表的重復片段

repeat(auto-fill, 250px)
repeat(auto-fit, 250px)
repeat(4, 1fr)
repeat(4, [col-start] 250px [col-end])
repeat(4, [col-start] 60% [col-end])

定義了一個長寬范圍的閉區間

url()

background: url("topbanner.png") #00D no-repeat fixed;
list-style: square url(http://www.example.com/redball.png)

var()

:root {
  --main-bg-color: pink;
}

body {
  background-color: var(--main-bg-color);
}

代替元素中任何屬性中的值的任何部分

CSS 技巧

強制不換行

p {
  white-space:nowrap;
}

強制換行

p {
  word-break:break-all; /* 英文 */
  white-space:pre-wrap; /* 中文 */
}

滾動條平滑

html {
  scroll-behavior: smooth;
}

點擊我頁面會平滑滾動到入門

修改瀏覽器自動填充 input 樣式

input[type="text"]:autofill {
  box-shadow: 0 0 0 1000px #000 inset;
  -webkit-text-fill-color: white;
}

另見: :autofill

修改 input type="color" 樣式

input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: none;
}

忽略用作間距的換行符 <br />

br + br {
  display: none;
}

使用 :empty 隱藏空 HTML 元素

:empty {
  display: none;
}

CSS 重置

html {
  box-sizing: border-box;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

有助于在不同的瀏覽器之間強制樣式一致性,并為樣式元素提供干凈的盒子

設置光標樣式

body {
  caret-color: red;
}

設置整個頁面灰色

html {
  -webkit-filter: grayscale(.95);
}

上面示例設置了當前卡片灰色

<textarea>自動增加其高度

textarea {
  form-sizing: normal
}

定義容器的長寬比

div {
  aspect-ratio: 1/1 
}

屬性 aspect-ratio 可以非常容易的定義一個容器的長寬比

使用 unset 而不是重置所有屬性

使用 all 速記來指定元素的所有屬性。將值設置為 unset 會將元素的屬性更改為其初始值:

button {
  all: unset;
}

注意:IE11 不支持 allunset 速記

超出顯示省略號

p {
  overflow: hidden;/*超出部分隱藏*/
  /* 超出部分顯示省略號 */
  text-overflow:ellipsis;
  /* 規定段落中的文本不進行換行 */
  white-space: nowrap;
  width: 250px;/*需要配合寬度來使用*/
}

給正文添加行高

您不需要為每個 <p><h*> 等添加行高。相反,將其添加到正文:

body {
  line-height: 1.5;
}

這樣文本元素可以很容易地從 body 繼承

使用圖像作為光標

div {
  cursor: url('path-to-image.png'), url('path-to-fallback-image.png'), auto;
  /* 表情符號作為光標 */
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'  width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>🚀</text></svg>"), auto;
}

文本溢出顯示省略號

.overflow-ellipsis {
  width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

一行文本截斷顯示省略號 (...)

將文本截斷到特定的行數

.overflow-truncate {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

多行文本截斷到特定的行數,末尾顯示省略號 (...)

粘性定位元素

.sticky {
  position: sticky;
  top: 0;
}

屬性 sticky 能在滾動到頂部的位置固定住元素

使用帶有空鏈接的屬性選擇器

a[href^="http"]:empty::before {
  content: attr(href);
}

如果 <a> 標簽里面沒有內容,將 href 的值作為內容展示

使用 :root 表示靈活類型

響應式布局中的字體大小應該能夠根據每個視口進行調整,您可以使用 :root 根據視口高度和寬度計算字體大小

:root {
  font-size: calc(1vw + 1vh + .5vmin);
}

您可以根據 :root 計算的值使用根 em 單位:

body {
  font: 1rem/1.6 sans-serif;
}

吸附滾動

.container {
  height: 250px;
  overflow-x: scroll;
  display: flex;
  scroll-snap-type: x mandatory;
  column-gap: 10px;
}
.child {
  flex: 0 0 66%;
  width: 250px;
  background-color: #663399;
  scroll-snap-align: center;
}

可用于 輪播圖 效果

類似 contenteditable 的樣式

div {
  -webkit-user-modify: 
    read-write-plaintext-only;
}

通過樣式來控制一個元素 div 是否可以編輯

等寬表格單元格

嘗試使用 table-layout: fixed 以保持單元格寬度相等:

table {
  table-layout: fixed;
}

利用屬性選擇器來選擇空鏈接

<a> 元素沒有文本內容,但有 href 屬性的時候,顯示它的 href 屬性:

a[href^="http"]:empty::before {
  content: attr(href);
}

給 “默認” 鏈接定義樣式

給 “默認” 鏈接定義樣式:

a[href]:not([class]) {
  color: #008000;
  text-decoration: underline;
}

通常沒有 class 屬性,以上樣式可以甄別它們,而且不會影響其它樣式

用 rem 調整全局大小;用 em 調整局部大小

在根元素設置基本字體大小后 (html { font-size: 100%; }), 使用 em 設置文本元素的字體大小:

h2 { 
  font-size: 2em;
}
p {
  font-size: 1em;
}

然后設置模塊的字體大小為 rem:

article {
  font-size: 1.25rem;
}
aside .module {
  font-size: .9rem;
}

現在,每個模塊變得獨立,更容易、靈活的樣式便于維護

隱藏沒有靜音、自動播放的影片

這是一個自定義用戶樣式表的不錯的技巧。避免在加載頁面時自動播放。如果沒有靜音,則不顯示視頻:

video[autoplay]:not([muted]) {
  display: none;
}

再次,我們利用了 :not() 的優點

為更好的移動體驗,為表單元素設置字體大小

當觸發 <select> 的下拉列表時,為了避免表單元素在移動瀏覽器(iOS Safari 和其它)上的縮放,加上font-size:

input[type="text"],
input[type="number"],
select,
textarea {
  font-size: 16px;
}

使用指針事件來控制鼠標事件

指針事件允許您指定鼠標如何與其觸摸的元素進行交互。要禁用按鈕上的默認指針事件,例如:

button:disabled {
  opacity: .5;
  pointer-events: none;
}

就這么簡單

子元素選中父元素

div:has(img) {
  background: black;
}

設置包含子元素 imgdiv 元素樣式,還可以嵌套:

div:has(h2):has(ul) {
  background: black;
}

在用作間距的換行符上設置 display: none

用戶使用額外的換行符

br + br {
  display: none;
}

body 添加行高

body {
  line-height: 1.5;
}

您不需要為每個 <p><h*> 等分別添加行高。相反,將其添加到正文

檢查本地是否安裝了字體

@font-face {
  font-family: "Dank Mono";
  src:
    /* Full name */
    local("Dank Mono"),
    /* Postscript name */
    local("Dank-Mono"),
    /* 否則,請下載它! */
    url("//...a.server/DankMono.woff");
}

code {
  font-family: "Dank Mono",
        system-ui-monospace;
}

您可以在遠程獲取字體之前檢查是否在本地安裝了字體,這也是一個很好的性能提示

獲取 HTML 元素的屬性

<a href="https://example.com">超鏈接</a>

attr HTML 元素的屬性名。

a:after {
  content: " (" attr(href) ")";
}

為表單元素設置 :focus

a:focus, button:focus, input:focus,
select:focus, textarea:focus {
  box-shadow: none;
  outline: #000 dotted 2px;
  outline-offset: .05em;
}

有視力的鍵盤用戶依靠焦點來確定鍵盤事件在頁面中的位置。使表單元素的焦點比瀏覽器的默認實現更加突出和一致

垂直居中任何東西

html, body {
  height: 100%;
  margin: 0;
}

body {
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
  display: -webkit-flex;
  display: flex;
}

...還有 CSS 網格:

body {
  display: grid;
  height: 100vh;
  margin: 0;
  place-items: center center;
}

圖片對齊不變形

img {
  width: 200px;
  height: 200px;
  /** 確保圖片按原始寬高比例進行縮放 */
  object-fit: cover;
  object-position: left top;
  transition: 1s;
}
img:hover {
  /** 指定圖片顯示的位置,結合鼠標移動+過渡動畫 */
  object-position: right bottom;
}

多行截斷,展示省略號

.clamp {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

html 文本超過 3 行將被截斷,顯示省略號...

<p class="clamp">
  展示多行文本,超過 3 行將被截斷,顯示省略號...
</p>

逗號分隔列表

ul > li:not(:last-child)::after {
  content: ",";
}

使列表項看起來像一個真實的逗號分隔列表,使用 :not() 偽類,最后一項不會添加逗號

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/73341.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/73341.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/73341.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Jenkins 集成 SonarQube 代碼靜態檢查使用說明

環境準備 Jenkins 服務器 確保 Jenkins 已安裝并運行&#xff08;推薦 LTS 版本&#xff09;。安裝插件&#xff1a; SonarQube Scanner for Jenkins&#xff08;用于集成 SonarQube 掃描&#xff09;NodeJS Plugin&#xff08;可選&#xff0c;用于 JavaScript 項目&#xff0…

EasyRTC輕量級Webrtc音視頻通話SDK,助力帶屏IPC在嵌入式設備中的應用

一、市場背景 隨著人們生活水平的提高&#xff0c;對于家居安全和遠程監控的需求日益增長&#xff0c;帶屏IPCam不僅滿足了用戶實時查看監控畫面的需求&#xff0c;還提供了諸如雙向語音通話、智能報警等豐富的功能&#xff0c;極大地提升了用戶體驗。 此外&#xff0c;技術的…

AI編輯器-Trae 玩轉AI 編程

參考 掘金社區地址 Trae下載地址 管理插件 Trae 從入門到實踐:AI 編碼的妙筆生花 掘金社區 掘金社區簡介 掘金是面向全球中文開發者的技術內容分享與交流平臺。我們通過技術文章、沸點、課程、直播等產品和服務,打造一個激發開發者創作靈感,激勵開發者沉淀分享,陪伴開發者…

C語言代碼如何操作硬件?

在嵌入式開發中&#xff0c;C代碼通過直接操作硬件寄存器來控制硬件&#xff0c;這些寄存器被映射到特定的內存地址。以下是其工作原理的詳細分步解釋&#xff1a; 1. 內存映射硬件寄存器 微控制器將外設&#xff08;如GPIO、定時器、UART等&#xff09;的寄存器映射到內存地…

Flume-試題

以下是對話中涉及的題目及其簡要解析&#xff1a; 1. 哪個 Flume Source 可用于監控某個端口&#xff0c;將流經端口的每一個文本行數據作為 Event 輸入&#xff1f; - A. Avro Source - B. exec Source - C. Spooling Directory Source - D. Netcat Source 2. 哪…

C++《紅黑樹》

在之前的篇章當中我們已經了解了基于二叉搜索樹的AVL樹&#xff0c;那么接下來在本篇當中將繼續來學習另一種基于二叉搜索樹的樹狀結構——紅黑樹&#xff0c;在此和之前學習AVL樹類似還是通過先了解紅黑樹是什么以及紅黑樹的結構特點&#xff0c;接下來在試著實現紅黑樹的結構…

【第23節】windows網絡編程模型(WSAEventSelect模型)

目錄 引言 一、WSAEventSelect模型概述 二、 WSAEventSelect模型的實現流程 2.1 創建一個事件對象&#xff0c;注冊網絡事件 2.2 等待網絡事件發生 2.3 獲取網絡事件 2.4 手動設置信號量和釋放資源 三、 WSAEventSelect模型偽代碼示例 四、完整實踐示例代碼 引言 在網…

概率預測之NGBoost(Natural Gradient Boosting)回歸和分位數(Quantile Regression)回歸

概率預測之NGBoost(Natural Gradient Boosting)回歸和線性分位數回歸 NGBoostNGBoost超參數解釋NGBoost.fitscore(X, Y)staged_predict(X)feature_importances_pred_dist 方法來獲取概率分布對象分位數回歸(Quantile Regression)smf.quantreg 對多變量數據進行分位數回歸分…

手撕算法——鏈表

算法基礎——鏈表-CSDN博客 一、排隊順序 題?來源&#xff1a;洛? 題?鏈接&#xff1a;B3630 排隊順序 - 洛谷 難度系數&#xff1a;★ 1. 題目描述 2. 算法原理 本題相當于告訴了我們每?個點的后繼&#xff0c;使?靜態鏈表的存儲?式能夠很好的還原這個隊列。 數組中 [1,…

RAG優化:python從零實現[吃一塹長一智]循環反饋Feedback

本文將介紹一種有反饋循環機制的RAG系統,讓當AI學會"吃一塹長一智",給傳統RAG裝了個"后悔"系統,讓AI能記住哪些回答被用戶點贊/拍磚,從此告別金魚記憶: 每次回答都像在玩roguelike:失敗結局會強化下次冒險悄悄把優質問答變成新知識卡牌,實現"以…

kotlin init執行順序

一 代碼 kotlin: package test.fclass Test1 { }class TestInit(s: String, i: Int) {var name: String? nullvar age 0private var a :Int 1init {this.name sthis.age iprintln("init代碼塊: $name, $age")}}轉成java // Test1.java package test.f;import…

使用cursor開發java案例——springboot整合elasticsearch

安裝elasticsearch 打開cursor&#xff0c;輸入如下提示詞 使用springboot整合elasticsearch。其中elasticsearch服務器ip&#xff1a;192.168.236.134 管理員用戶名elastic 管理員密碼 PdQy_xfR2yLhpok*MK_ 監聽端口9200點Accept all 使用idea打開生成的項目 &#xff0…

Java Collection API增強功能系列之一 Arrays.asList()

在Java編程中&#xff0c;Arrays.asList() 是一個高頻使用卻又容易引發陷阱的工具方法。它能夠快速將數組轉換為列表&#xff0c;但其特殊行為常常讓開發者踩坑。本文將深入剖析該方法的本質特性&#xff0c;并揭示其使用時的注意事項。一、方法定義與基礎用法 1. 方法簽名 p…

vue3 項目的最新eslint9 + prettier 配置

注意&#xff1a;eslint目前升級到9版本了 在 ESLint v9 中&#xff0c;配置文件已經從 .eslintrc 遷移到了 eslint.config.js 配置的方式和之前的方式不太一樣了&#xff01;&#xff01;&#xff01;&#xff01; 詳見自己的語雀文檔&#xff1a;5、新版eslint9prettier 配…

基于FPGA的16QAM+幀同步系統verilog開發,包含testbench,高斯信道,誤碼統計,可設置SNR

目錄 1.算法仿真效果 2.算法涉及理論知識概要 2.1 16QAM調制解調原理 2.2 幀同步 3.Verilog核心程序 4.完整算法代碼文件獲得 1.算法仿真效果 vivado2019.2仿真結果如下&#xff08;完整代碼運行后無水印&#xff09;&#xff1a; 設置SNR12db 將FPGA數據導入到MATLAB顯…

[學成在線]06-視頻分片上傳

上傳視頻 需求分析 教學機構人員進入媒資管理列表查詢自己上傳的媒資文件。 點擊“媒資管理” 進入媒資管理列表頁面查詢本機構上傳的媒資文件。 教育機構用戶在"媒資管理"頁面中點擊 "上傳視頻" 按鈕。 點擊“上傳視頻”打開上傳頁面 選擇要上傳的文件…

Maven安裝與環境配置

首先我們先介紹一些關于Maven的知識&#xff0c;如果著急直接看下面的安裝教程。 目錄 Maven介紹 Maven模型 Maven倉庫 Maven安裝 下載 安裝步驟 Maven介紹 Apache Maven是一個項目管理和構建工具&#xff0c;它基于項目對象模型(Project Object Model , 簡稱: POM)的概念…

【新能源汽車溫度采集與控制系統設計深度解析】

面向汽車行業研發與測試測量設備從業者的技術指南 一、硬件架構設計 新能源汽車的溫度采集與控制系統是保障電池、電機、電控等核心部件安全運行的核心技術之一。其硬件架構需兼顧高精度、抗干擾、可靠性與集成化&#xff0c;以下從信號調理電路、ADC模塊、隔離設計三個維度展…

AI Tokenization

AI Tokenization 人工智能分詞初步了解 類似現在這個&#xff0c;一格子 一格子&#xff0c;拼接出來的&#xff0c;一行或者一句&#xff0c;像不像&#xff0c;我們人類思考的時候組裝出來的話&#xff0c;并用嘴說出來了呢。

React(四)setState原理-性能優化-ref

setState詳解 實現原理 開發中我們并不能直接修改State來重新渲染界面&#xff1a; 因為修改State之后&#xff0c;希望React根據最新的State來重新渲染界面&#xff0c;但這種方式的修改React并不知道數據發生了變化&#xff1b; React并沒有類似于Vue2中的Object.defineP…