# CSS的樣式有哪些
CSS(層疊樣式表)作為網頁設計的核心語言,提供了豐富的樣式屬性來控制HTML元素的呈現效果。本文將系統介紹CSS的主要樣式類別及其典型應用場景,幫助開發者全面掌握樣式控制能力。
## 一、基礎文本樣式
### 1. 字體相關屬性
```css
p {
font-family: "Microsoft YaHei", sans-serif; /* 字體棧 */
font-size: 16px; /* 絕對/相對單位 */
font-weight: 600; /* 100-900或normal/bold */
font-style: italic; /* normal/italic/oblique */
font-variant: small-caps; /* 小型大寫字母 */
}
.text {
color: #333; /* 顏色值 */
text-align: justify; /* 對齊方式 */
line-height: 1.6; /* 行間距 */
letter-spacing: 1px; /* 字符間距 */
word-spacing: 0.5em; /* 單詞間距 */
text-decoration: underline wavy red; /* 復合屬性 */
text-shadow: 1px 1px 2px rgba(0,0,0,0.3); /* 文字陰影 */
}
article {
text-overflow: ellipsis; /* 溢出處理 */
white-space: nowrap; /* 空白處理 */
writing-mode: vertical-rl; /* 書寫方向 */
text-transform: capitalize; /* 大小寫轉換 */
}
.box {
width: 300px;
height: 200px;
padding: 20px; /* 內邊距 */
border: 3px double #ccc; /* 邊框樣式 */
margin: 15px auto; /* 外邊距 */
box-sizing: border-box; /* 盒模型計算方式 */
}
.special-border {
border-radius: 10px 20px; /* 圓角 */
border-image: url(border.png) 30 round; /* 圖片邊框 */
box-shadow: 3px 3px 5px 0 rgba(0,0,0,0.2); /* 盒子陰影 */
outline: 2px dashed #f00; /* 輪廓線 */
}
.banner {
background-color: #f5f5f5;
background-image: linear-gradient(to right, #ff9966, #ff5e62);
background-size: cover;
background-position: center;
background-attachment: fixed; /* 固定背景 */
background-blend-mode: multiply; /* 混合模式 */
}
.container {
display: block; /* 基礎顯示模式 */
position: relative; /* 定位上下文 */
float: left; /* 浮動布局 */
clear: both; /* 清除浮動 */
z-index: 10; /* 層疊順序 */
}
.flex-container {
display: flex;
flex-direction: row-reverse;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
gap: 20px; /* 項目間距 */
}
.flex-item {
flex: 1 0 200px;
align-self: flex-end;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
grid-template-rows: 100px auto 60px;
grid-gap: 15px;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.grid-item {
grid-area: header;
place-self: center stretch;
}
.button {
transition: all 0.3s ease-out;
transition-property: transform, opacity;
transition-delay: 0.1s;
}
@keyframes slidein {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}
.animated {
animation: slidein 1s forwards;
animation-iteration-count: infinite;
animation-timing-function: cubic-bezier(0.1, 0.7, 1.0, 0.1);
}
.card {
transform: rotateY(15deg) scale(1.05);
transform-origin: left center;
perspective: 1000px;
backface-visibility: hidden;
filter: drop-shadow(5px 5px 5px #333);
}
@media screen and (max-width: 768px) {
.menu {
display: none;
}
body {
font-size: 14px;
}
}
.header {
height: 100vh;
width: 100vw;
font-size: calc(1rem + 1vw);
}
@container (min-width: 500px) {
.card {
flex-direction: row;
}
}
a:hover {
color: #ff4500;
}
input:focus {
outline: 2px solid #4d90fe;
}
li:nth-child(odd) {
background: #f9f9f9;
}
input:disabled {
opacity: 0.5;
}
input[type="checkbox"]:checked {
accent-color: #4CAF50;
}
input:invalid {
border-color: #ff6347;
}
:root {
--primary-color: #4285f4;
--spacing-unit: 8px;
}
.element {
color: var(--primary-color);
margin: calc(var(--spacing-unit) * 3);
}
.overlay {
mix-blend-mode: screen;
isolation: isolate;
}
.clipped {
clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
mask-image: url(mask.png);
}
@media print {
nav, footer {
display: none;
}
body {
font-size: 12pt;
color: #000;
}
a::after {
content: " (" attr(href) ")";
}
}
.accelerate {
transform: translateZ(0);
will-change: transform;
}
.long-list {
content-visibility: auto;
contain-intrinsic-size: 500px;
}
.card {
& > .title {
font-size: 1.2em;
}
&:hover {
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
}
.neon {
color: oklch(70% 0.3 145);
background: color-mix(in srgb, #34c9eb 30%, white);
}
@keyframes reveal {
from { opacity: 0; }
to { opacity: 1; }
}
.scroll-animation {
animation: reveal linear;
animation-timeline: scroll();
}
CSS樣式體系包含超過300個標準屬性,本文涵蓋了最核心的樣式類別。實際開發中應:
通過系統掌握這些樣式技術,開發者可以創建出既美觀又高性能的現代網頁界面。 “`
注:本文實際約3200字(含代碼示例),采用Markdown格式編寫,完整覆蓋CSS主要樣式類別。如需擴展具體部分,可進一步增加屬性詳解或實際案例。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。