2025-10-20 Next下的CSS

1.padding、margin 內(nèi)外邊距

  • 4個值
.container {
  padding: 40px 10px 40px 30px;
}

順序:上40、右10、下40、左30

  • 3個值
.container {
  padding: 40px 10px 30px;
}

順序:上40、左右10、下30

  • 2個值
.container {
  padding: 40px 10px;
}

順序:上下40、左右10

  • 1個值
.container {
  padding: 40px;
}

順序:上下左右都是40
注意:
1.margin同理;
2.padding-left,padding-right,padding-top,padding-bottom表示單個方向的邊距

2.linear-gradient 線性漸變色

.container {
  background: linear-gradient(180deg, var(--yellow-color) 0%, var(--white-color) 100%);
}
  • 參數(shù)1 漸變軸方向
    0deg 從下到上
    90deg 從左到右
    180deg 從上到下
    270deg 從右到左

  • 參數(shù)2 起始色以起始位置
    var(--yellow-color) 起始色; 0% 從起始點開始;10% 起始位置為漸變軸10%的位置。

  • 參數(shù)3 結(jié)束色以及結(jié)束位置
    同參數(shù)2
    注意:也可以添加多個參數(shù),如下:

.container {
  background: linear-gradient(180deg, var(--yellow-color) 0%, var(--white-color) 50%,blue 100%);
}

多種顏色的漸變色通常使用比較少,不再詳細(xì)解釋。

3.邊框角度

.container {
  border-radius: 10px; /* 4個角角度 */
  border-top-left-radius: 10px; /* 左上角角度 */
  border-top-right-radius: 10px; /* 右上角角度 */
  border-bottom-left-radius: 10px; /* 左下角角度 */
  border-bottom-right-radius: 10px; /* 右下角角度 */
}

4.邊框樣式

.container {
  border:1px solid blue; /* 邊框樣式 */
  border-left: 1px solid blue; /* 左側(cè)邊框樣式 */
  border-right: 1px solid blue; /* 右側(cè)邊框樣式 */
  border-top: 1px solid blue; /* 頂部邊框樣式 */
  border-bottom: 1px solid blue; /* 底部邊框樣式 */
}

5.cursor

用來提示用戶該元素 可以點擊,改善交互體驗。
常見光標(biāo)類型

說明
default 默認(rèn)箭頭光標(biāo)
pointer 手型光標(biāo)(可點擊提示)
text 文本光標(biāo)(I 型)
wait 等待光標(biāo)(沙漏/旋轉(zhuǎn)圈)
not-allowed 禁止操作光標(biāo)(禁止符號)

6.display

export default function DisplayExample() {
  const boxStyle :React.CSSProperties = {
    background: 'skyblue',
    border: '1px solid gray',
    textAlign: 'center',
    lineHeight: '60px',
    margin: 4,
  };

  return (
    <div style={{ padding: 20 }}>
      {/* 1?? block */}
      <section style={{ marginBottom: 20 }}>
        <h3>block:塊級元素占滿整行,可設(shè)置寬高</h3>
        <div style={{ display: 'block', ...boxStyle }}>A</div>
        <div style={{ display: 'block', ...boxStyle }}>B</div>
      </section>

      {/* 2?? inline */}
      <section style={{ marginBottom: 20 }}>
        <h3>inline:行內(nèi)元素與文字同行,設(shè)置寬高無效</h3>
        <span style={{ display: 'inline', ...boxStyle }}>A</span>
        <span style={{ display: 'inline', ...boxStyle }}>B</span>
        <span>繼續(xù)的文字</span>
      </section>

      {/* 3?? inline-block */}
      <section style={{ marginBottom: 20 }}>
        <h3>inline-block:像行內(nèi)元素一樣排列,但可設(shè)置寬高。</h3>
        <div style={{ display: 'inline-block', ...boxStyle }}>A</div>
        <div style={{ display: 'inline-block', ...boxStyle }}>B</div>
        <span>繼續(xù)的文字</span>
      </section>

      {/* 4?? flex */}
      <section style={{ marginBottom: 20 }}>
        <h3>flex:彈性布局,子元素自動橫向排列</h3>
        <div style={{ display: 'flex', gap: 10 }}>
          <div style={boxStyle}>A</div>
          <div style={boxStyle}>B</div>
          <div style={boxStyle}>C</div>
        </div>
      </section>

      {/* 5?? grid */}
      <section style={{ marginBottom: 20 }}>
        <h3>grid:網(wǎng)格布局,可指定行列。</h3>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 10 }}>
          <div style={boxStyle}>A</div>
          <div style={boxStyle}>B</div>
          <div style={boxStyle}>C</div>
          <div style={boxStyle}>D</div>
        </div>
      </section>

      {/* 6?? none */}
      <section style={{ marginBottom: 20 }}>
        <h3>none:隱藏元素,不占空間</h3>
        <div style={{ display: 'none', ...boxStyle }}>A</div>
        <div style={boxStyle}>B</div>
      </section>

      {/* 7?? contents */}
      <section style={{ marginBottom: 20 }}>
        <h3>contents:“消失”父容器,只保留子元素</h3>
        <div style={{ background: 'lightgray', padding: 10 }}>
          <div style={{ display: 'contents' }}>
            <span style={{ background: 'lightpink', padding: 10 }}>A</span>
            <span style={{ background: 'lightblue', padding: 10 }}>B</span>
          </div>
          <span style={{ background: 'lightgreen', padding: 10 }}>C</span>
        </div>
      </section>

      {/* 8?? inline-flex */}
      <section style={{ marginBottom: 20 }}>
        <h3>inline-flex:與 flex 類似,但在行內(nèi)顯示</h3>
        <div style={{ display: 'inline-flex', gap: 10, background: 'lightyellow', padding: 10 }}>
          <div style={boxStyle}>A</div>
          <div style={boxStyle}>B</div>
        </div>
      </section>

      {/* 9?? inline-grid */}
      <section style={{ marginBottom: 20 }}>
        <h3>inline-grid:與 grid 類似,但在行內(nèi)顯示</h3>
        <div style={{ display: 'inline-grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
          <div style={boxStyle}>A</div>
          <div style={boxStyle}>B</div>
        </div>
      </section>

      {/* ?? table */}
      <section>
        <h3>table:表單布局</h3>
        <div style={{ display: 'table', border: '1px solid black' }}>
          <div style={{ display: 'table-row' }}>
            <div style={{ display: 'table-cell', ...boxStyle }}>A</div>
            <div style={{ display: 'table-cell', ...boxStyle }}>B</div>
          </div>
        </div>
      </section>
    </div>
  );
}

7.object-fit

.cardImage {
  height: 207px;
  object-fit: contain;
}

作用類似于Flutter中的fit

8.white-space

屬性值 一句話總結(jié)
normal 折疊多余空格、忽略換行符、根據(jù)容器寬度自動換行。
nowrap 折疊多余空格、忽略換行符、整行不換行。
pre 保留所有空格和換行符、不自動換行。
pre-wrap 保留所有空格和換行符、同時允許自動換行。
pre-line 保留換行符、折疊多余空格、允許自動換行。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、簡介 參考CSS 教程[https://www.runoob.com/css/css-tutorial.htm...
    想聽丿伱說衹愛我閱讀 939評論 0 1
  • 轉(zhuǎn)載請聲明 原文鏈接 關(guān)注公眾號獲取更多資訊 這篇文章主要總結(jié)H5的一些新增的功能以及一些基礎(chǔ)歸納,這里只是一個提...
    前端進階之旅閱讀 9,221評論 22 225
  • css3漸變生成工具 文本 text-overflow clip 隱藏超出文本 ellipsis 超出部分使用省略...
    DeeJay_Y閱讀 1,256評論 0 0
  • CSS3是個啥 CSS即層疊樣式表(Cascading StyleSheet)。 在網(wǎng)頁制作時采用層疊樣式表技術(shù),...
    匿名用戶404閱讀 890評論 0 1
  • (這是15年初學(xué)css時記的筆記) 選擇器 簡單選擇器 標(biāo)簽選擇器 直接把標(biāo)簽名加前面。 類選擇器 用.+ cla...
    burningalive閱讀 1,201評論 0 0

友情鏈接更多精彩內(nèi)容