网页制作通用css

基础样式重置
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
line-height: 1.5;
-webkit-text-size-adjust: 100%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
line-height: 1.5;
}
排版优化
h1, h2, h3, h4, h5, h6 {
font-weight: 600;
line-height: 1.25;
}
p {
margin-bottom: 1rem;
}
a {
color: inherit;
text-decoration: none;
transition: color 0.2s ease;
}
a:hover {
color: #2563eb;
}
响应式布局
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
}
@media (min-width: 640px) {
.container {
padding: 0 2rem;
}
}
常用工具类
.flex {
display: flex;
}
.flex-col {
flex-direction: column;
}
.items-center {
align-items: center;
}
.justify-center {
justify-content: center;
}
.mx-auto {
margin-left: auto;
margin-right: auto;
}
.text-center {
text-align: center;
}
.hidden {
display: none;
}
.relative {
position: relative;
}
.absolute {
position: absolute;
}
表单元素样式
input, textarea, select {
border: 1px solid #e5e7eb;
border-radius: 0.375rem;
padding: 0.5rem 0.75rem;
width: 100%;
transition: border-color 0.2s ease;
}
input:focus, textarea:focus, select:focus {
outline: none;
border-color: #2563eb;
}
button {
cursor: pointer;
border: none;
border-radius: 0.375rem;
padding: 0.5rem 1rem;
background-color: #2563eb;
color: white;
transition: background-color 0.2s ease;
}
button:hover {
background-color: #1d4ed8;
}
颜色变量
:root {
--primary: #2563eb;
--primary-dark: #1d4ed8;
--gray-100: #f3f4f6;
--gray-200: #e5e7eb;
--gray-500: #6b7280;
--gray-700: #374151;
--white: #ffffff;
--black: #000000;
}
动画效果
.fade-in {
animation: fadeIn 0.3s ease forwards;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.slide-up {
animation: slideUp 0.3s ease forwards;
}
@keyframes slideUp {
from {
transform: translateY(20px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}