# 常用CSS class集合

主要是从tailwind.css借鉴的, 搞出一些自己常用的,容易记忆的常用CSS, 减少一些开发的时间。

毕竟tailwind.css功能过多过全, 加进项目里面,很多时候也是多了心智负担。不如针对自己要做的项目的,做一些特殊性的改造。

先从modern-normalize (opens new window)学习一下, 可以先引入一下这个文件来重置一些CSS

我们自己常用的, 从tailwind也可以借鉴一些过来

# 1、常用class

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

.flex {
  display: flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.flex-1 {
  flex: 1 1 0%;
}
.flex-auto {
  flex: 1 1 auto;
}
.flex-initial {
  flex: 0 1 auto;
}
.flex-none {
  flex: none;
}
.flex-2 {
  flex: 2;
}
.flex-3 {
  flex: 3;
}
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.align-start {
  align-items: flex-start;
}
.align-center {
  align-items: center;
}
.align-end {
  align-items: end;
}
.justify-start {
  justify-content: flex-start;
}
.justify-end {
  justify-content: flex-end;
}
.justify-between {
  justify-content: space-between;
}
.flex-nowrap {
  flex-wrap: nowrap;
}

.flex-wrap {
  flex-wrap: wrap;
}

.align-content-start {
  align-content: flex-start;
}

.w-100 {
  width: 100%;
}
.h-100 {
  height: 100%;
}
.w-0 {
  width: 0;
}
.h-0 {
  height: 0;
}

.bg-white {
  background-color: #fff;
}
.bg-aaa {
  background-color: #aaa;
}
.bg-bbb {
  background-color: #bbb;
}
.bg-ccc {
  background-color: #ccc;
}
.bg-red {
  background-color: red;
}

.bg-green {
  background-color: green;
}

.m-2 {
  margin: 2px;
}
.mb-2 {
  margin-bottom: 2px;
}
.mt-2 {
  margin-top: 2px;
}
.mr-2 {
  margin-right: 2px;
}
.ml-2 {
  margin-left: 2px;
}
.m-4 {
  margin: 4px;
}
.mt-4 {
  margin-top: 4px;
}
.mr-4 {
  margin-right: 4px;
}
.mb-4 {
  margin-bottom: 4px;
}
.ml-4 {
  margin-left: 4px;
}
.m-6 {
  margin: 6px;
}
.mt-6 {
  margin-top: 6px;
}
.mr-6 {
  margin-right: 6px;
}
.mb-6 {
  margin-bottom: 6px;
}
.ml-6 {
  margin-left: 6px;
}

.m-8 {
  margin: 8px;
}
.mt-8 {
  margin-top: 8px;
}
.mr-8 {
  margin-right: 8px;
}
.mb-8 {
  margin-bottom: 8px;
}
.ml-8 {
  margin-left: 8px;
}
.m-12 {
  margin: 12px;
}
.mt-12 {
  margin-top: 12px;
}
.mr-12 {
  margin-right: 12px;
}
.mb-12 {
  margin-bottom: 12px;
}
.ml-12 {
  margin-left: 12px;
}
.m-16 {
  margin: 16px;
}
.mt-16 {
  margin-top: 16px;
}
.mr-16 {
  margin-right: 16px;
}
.mb-16 {
  margin-bottom: 16px;
}
.ml-16 {
  margin-left: 16px;
}

.p-2 {
  padding: 2px;
}
.pt-2 {
  padding-top: 2px;
}
.pr-2 {
  padding-right: 2px;
}
.pb-2 {
  padding-bottom: 2px;
}
.pl-2 {
  padding-left: 2px;
}

.pt-4 {
  padding-top: 4px;
}
.pr-4 {
  padding-right: 4px;
}
.pb-4 {
  padding-bottom: 4px;
}
.pl-4 {
  padding-left: 4px;
}
.p-4 {
  padding: 4px;
}
.pt-6 {
  padding-top: 6px;
}
.pr-6 {
  padding-right: 6px;
}
.pb-6 {
  padding-bottom: 6px;
}
.pl-6 {
  padding-left: 6px;
}
.p-6 {
  padding: 6px;
}
.pt-8 {
  padding-top: 8px;
}
.pr-8 {
  padding-right: 8px;
}
.pb-8 {
  padding-bottom: 8px;
}
.pl-8 {
  padding-left: 8px;
}
.p-8 {
  padding: 8px;
}
.pt-16 {
  padding-top: 16px;
}
.pr-16 {
  padding-right: 16px;
}
.pb-16 {
  padding-bottom: 16px;
}
.pl-16 {
  padding-left: 16px;
}
.p-16 {
  padding: 16px;
}
.pt-32 {
  padding-top: 32px;
}
.pr-32 {
  padding-right: 32px;
}
.pb-32 {
  padding-bottom: 32px;
}
.pl-32 {
  padding-left: 32px;
}
.p-32 {
  padding: 32px;
}

.fs-12 {
  font-size: 12px !important;
}
.fs-14 {
  font-size: 14px !important;
}
.fs-16 {
  font-size: 16px !important;
}
.fs-18 {
  font-size: 18px !important;
}
.fs-20 {
  font-size: 20px !important;
}
.fs-24 {
  font-size: 24px !important;
}

.ovh {
  overflow: hidden;
}
.ova {
  overflow: auto;
}
.ovy-a {
  overflow-y: auto;
}
.ovx-a {
  overflow-x: auto;
}
.tar {
  text-align: right;
}
.ta-r {
  text-align: right;
}
.tac {
  text-align: center;
}
.ta-c {
  text-align: center;
}
.tal {
  text-align: left;
}
.ta-l {
  text-align: left;
}
.fixed {
  position: fixed;
}
.relative {
  position: relative;
}
.absolute {
  position: absolute;
}
.sticky {
  position: sticky;
}
.absolute-fill {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.inset-0 {
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.left-0 {
  left: 0;
}
.right-0 {
  right: 0;
}
.top-0 {
  top: 0;
}
.bottom-0 {
  bottom: 0;
}

.color-333 {
  color: #333;
}
.color-666 {
  color: #666;
}
.color-999 {
  color: #999;
}
.fw-7 {
  font-weight: 700;
}
.fw-6 {
  font-weight: 600;
}
.fw-5 {
  font-weight: 500;
}
.fw-4 {
  font-weight: 400;
}
.hide-scrollbar::-webkit-scrollbar {
  width: 0 !important;
  display: none !important;
}
.lh-1 {
  line-height: 1;
}

.block {
  display: block;
}
.none {
  display: none;
}
.pointer {
  cursor: pointer;
}

/* 最多显示1行, 超出部分... */
.xd-ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
/* 最多显示2行 */
.xd-multi-ellipsis--l2 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
/* 最多显示3行 */
.xd-multi-ellipsis--l3 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* 实现 Retina屏幕下的0.5px边框 */
[class*='xd-hairline'] {
  position: relative;
}
[class*='xd-hairline']:after {
  position: absolute;
  box-sizing: border-box;
  content: ' ';
  pointer-events: none;
  top: -50%;
  right: -50%;
  bottom: -50%;
  left: -50%;
  border: 0 solid #ebedf0;
  transform: scale(0.5);
}
.xd-hairline--top:after {
  border-top-width: 1px;
}
.xd-hairline--bottom:after {
  border-bottom-width: 1px;
}
.xd-hairline--left:after {
  border-left-width: 1px;
}
.xd-hairline--right:after {
  border-right-width: 1px;
}
.xd-hairline--top-bottom:after {
  border-width: 1px 0 1px 0;
}
.xd-hairline--surround:after {
  border-width: 1px;
}

.border-1-ccc {
  border: 1px solid #ccc;
}

.box-b {
  box-sizing: border-box;
}
.box-c {
  box-sizing: content-box;
}

# 2、modern-normalize.css

/*! modern-normalize v3.0.1 | MIT License | https://github.com/sindresorhus/modern-normalize */

/*
Document
========
*/

/**
Use a better box model (opinionated).
*/

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

/**
1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
2. Correct the line height in all browsers.
3. Prevent adjustments of font size after orientation changes in iOS.
4. Use a more readable tab size (opinionated).
*/

html {
	font-family:
		system-ui,
		'Segoe UI',
		Roboto,
		Helvetica,
		Arial,
		sans-serif,
		'Apple Color Emoji',
		'Segoe UI Emoji'; /* 1 */
	line-height: 1.15; /* 2 */
	-webkit-text-size-adjust: 100%; /* 3 */
	tab-size: 4; /* 4 */
}

/*
Sections
========
*/

/**
Remove the margin in all browsers.
*/

body {
	margin: 0;
}

/*
Text-level semantics
====================
*/

/**
Add the correct font weight in Chrome and Safari.
*/

b,
strong {
	font-weight: bolder;
}

/**
1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
2. Correct the odd 'em' font sizing in all browsers.
*/

code,
kbd,
samp,
pre {
	font-family:
		ui-monospace,
		SFMono-Regular,
		Consolas,
		'Liberation Mono',
		Menlo,
		monospace; /* 1 */
	font-size: 1em; /* 2 */
}

/**
Add the correct font size in all browsers.
*/

small {
	font-size: 80%;
}

/**
Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
*/

sub,
sup {
	font-size: 75%;
	line-height: 0;
	position: relative;
	vertical-align: baseline;
}

sub {
	bottom: -0.25em;
}

sup {
	top: -0.5em;
}

/*
Tabular data
============
*/

/**
Correct table border color inheritance in Chrome and Safari. (https://issues.chromium.org/issues/40615503, https://bugs.webkit.org/show_bug.cgi?id=195016)
*/

table {
	border-color: currentcolor;
}

/*
Forms
=====
*/

/**
1. Change the font styles in all browsers.
2. Remove the margin in Firefox and Safari.
*/

button,
input,
optgroup,
select,
textarea {
	font-family: inherit; /* 1 */
	font-size: 100%; /* 1 */
	line-height: 1.15; /* 1 */
	margin: 0; /* 2 */
}

/**
Correct the inability to style clickable types in iOS and Safari.
*/

button,
[type='button'],
[type='reset'],
[type='submit'] {
	-webkit-appearance: button;
}

/**
Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
*/

legend {
	padding: 0;
}

/**
Add the correct vertical alignment in Chrome and Firefox.
*/

progress {
	vertical-align: baseline;
}

/**
Correct the cursor style of increment and decrement buttons in Safari.
*/

::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
	height: auto;
}

/**
1. Correct the odd appearance in Chrome and Safari.
2. Correct the outline style in Safari.
*/

[type='search'] {
	-webkit-appearance: textfield; /* 1 */
	outline-offset: -2px; /* 2 */
}

/**
Remove the inner padding in Chrome and Safari on macOS.
*/

::-webkit-search-decoration {
	-webkit-appearance: none;
}

/**
1. Correct the inability to style clickable types in iOS and Safari.
2. Change font properties to 'inherit' in Safari.
*/

::-webkit-file-upload-button {
	-webkit-appearance: button; /* 1 */
	font: inherit; /* 2 */
}

/*
Interactive
===========
*/

/*
Add the correct display in Chrome and Safari.
*/

summary {
	display: list-item;
}
上次更新: 1/29/2026, 9:17:42 AM