首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> .NET 實例教學

CSS 2.1/3 核心屬性速查手冊:字體、顏色、文本、盒模型、邊框、列表、定位、濾鏡全覆蓋

     編輯:.NET 實例教學

一、字體屬性

屬性值範例說明
font-family"Microsoft YaHei", SimSun, sans-serif字體族,按序降級
font-stylenormal / italic / oblique斜體/傾斜
font-variantnormal / small-caps小型大寫字母
font-weightnormal / bold / 100-900粗細,400=normal, 700=bold
font-size12px / 1.2em / 120% / large絕對/相對/關鍵字
fontitalic bold 14px/1.5 "YaHei"簡寫:style variant weight size/line-height family

二、顏色與背景

屬性值範例說明
color#ff0000 / rgb(255,0,0) / red前景色
background-color#f0f0f0背景色
background-imageurl(bg.png)背景圖
background-repeatrepeat / repeat-x / repeat-y / no-repeat / space / round平鋪模式
background-attachmentscroll / fixed / local滾動行為
background-positionleft top / center / 10px 20px / 50% 50%初始位置
background#fff url(x.png) no-repeat center / cover簡寫 (CSS3 支援 size: cover/contain)

三、文本屬性

屬性值範例說明
word-spacing2px / 0.2em單詞間距
letter-spacing1px / -0.5px字符間距 (可負)
text-decorationnone / underline / overline / line-through / blink裝飾線
vertical-alignbaseline / sub / super / top / middle / bottom / text-top / text-bottom / 10px行內元素垂直對齊
text-transformcapitalize / uppercase / lowercase / none大小寫轉換
text-alignleft / right / center / justify / start / end文本水平對齊
text-indent2em / 24px首行縮進
line-height1.5 / 24px / normal行高 (無單位為倍數,推薦)
white-spacenormal / pre / nowrap / pre-wrap / pre-line空白處理

四、超鏈接偽類 (LVHA 順序)


a:link    { color: green; text-decoration: none; }
a:visited { color: purple; text-decoration: underline; }
a:hover   { color: blue; text-decoration: underline; }
a:active  { color: red; }  /* 鼠標按下瞬間 */

五、盒模型 (Box Model)

屬性方向簡寫
margintop/right/bottom/leftmargin: 10px 20px 10px 5px; (順時針)
paddingtop/right/bottom/leftpadding: 10px 20px; (垂直 水平)

六、邊框


border-width: 1px 2px 3px 4px;      /* 簡寫 */
border-style: solid dashed dotted double; /* 同序 */
border-color: red green blue black;
border: 1px solid #ccc;              /* 終極簡寫 */
border-radius: 4px / 50%;            /* CSS3 圓角 */
box-shadow: 2px 2px 5px rgba(0,0,0,.3); /* CSS3 陰影 */

七、尺寸與浮動


width: 300px; height: 200px;
max-width: 100%; min-height: 100px;
float: left / right / none;
clear: left / right / both / none;

八、列表


list-style-type: disc / circle / square / decimal / lower-roman / upper-alpha / none;
list-style-image: url(bullet.png);
list-style-position: inside / outside;
list-style: square inside url(bullet.png); /* 簡寫 */

九、定位

屬性值/說明
positionstatic / relative / absolute / fixed / sticky (CSS3)
z-index整數 (含負),堆疊層級
overflowvisible / hidden / scroll / auto / clip (CSS3)
top/right/bottom/left定位偏移 (需 position ≠ static)
cliprect(top, right, bottom, left) 裁剪區域 (absolute/fixed 生效)

十、CSS3 擴展 (IE 專有濾鏡已棄用,現代項目請用標準 CSS3)

功能標準 CSS3 寫法舊 IE 濾鏡 (參考)
透明度opacity: 0.5;filter: Alpha(Opacity=50);
漸變background: linear-gradient(45deg, red, blue);filter: progid:DXImageTransform.Microsoft.Gradient(...)
陰影box-shadow: 2px 2px 5px #0003;filter: DropShadow(Color=#000, OffX=2, OffY=2);
模糊filter: blur(5px); (CSS Filter)filter: Blur(Strength=5);
旋轉/縮放transform: rotate(45deg) scale(1.2);filter: Matrix(...);
圖片剪裁clip-path: circle(50%);—

十一、打印控制


@media print {
    .no-print { display: none; }
    .page-break-before { page-break-before: always; }
    .page-break-after  { page-break-after: always; }
}

十二、游標


cursor: default / pointer / text / wait / help / move / crosshair /
        not-allowed / progress / n-resize / ne-resize / e-resize / se-resize /
        s-resize / sw-resize / w-resize / nw-resize / grab / grabbing;

使用建議

  • **移動優先**:先寫基礎樣式,再用 @media (min-width: 768px) 疊加桌面端
  • **CSS 變量**::root { --primary: #007bff; } → color: var(--primary); 統一主題
  • **避免 IE 濾鏡**:已棄用,標準 CSS3 在現代瀏覽器 (含 Edge) 完整支援
  • **Normalize/Reset**:項目引入 normalize.css 或 reset.css 消除瀏覽器默認差異
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved