Collection css
一、文字
font-family
font-size
font-style 字体样式
italic 通常用它设置斜体,italic 倾斜的意思
normal 取消倾斜
font-weight
bold 加粗,相当于数字700
normal 取消加粗
text-decoration 文本修饰的意思,说白了就是给文本加线
line-through 文字中间加线
overline 文本上面加线
underline 文本下面加一条线,比较常见
none 把a元素下面默认的线去掉
line-height: 1.5
通常情况不用的不是绝对的单位,而是用相对单位(em也可以),但是建议直接使用纯数字,比如 1.5 表示跟当前文字大小的1.5倍数
text-indent: 2em
首行文本缩进,indent表示缩进的意思,通常 2em 中文正好缩进两个字符,但是中文正好是2个字符英文就不一样了,因为英文字母宽度比较小
letter-spacing
表示文字间隙,像素值也可以是 em
word-spacing: normal|length
增加或减少单词间的空白,定义元素中字之间插入多少空白符,
如果指定为长度值,会调整字之间的通常间隔,
所以,normal 就等同于设置为 0。允许指定负长度值,这会让字之间挤得更紧。
调整文字间距的两种属性的不同
word-spacing 用于设置单词(或汉字)之间的间距,通过空格分隔的单词或汉字生效。
letter-spacing 用于设置字母(或汉字笔画)之间的间距,每个字符生效。
word-spacing 仅对英文单词或中文分开的汉字生效,若汉字无空格分隔则无效。
letter-spacing 适用于所有字符(包括汉字笔画),但中文默认字间距通常无需调整。
white-space 空白折叠
pre 元素里面默认所有空白字符都会保留
nowrap 默认值,普通情况下会空白折叠
http://ruyic.com/blog/html/view.php?id=324
word-break
定义非 CJK 文本(中文/日文/韩文)的断行规则
normal 默认的方式非常合理。按语言规则断行(如英文按空格断行,CJK文本按字符断行)。允许在单词内换行。
break-all 表示截断所有。强制任意字符间断行(破坏单词结构,适用于表格或窄栏布局)
keep-all 表示保持所有,意思所有文字都在单词之间截断(不管是英文还是中文)。只能在半角空格或连字符处换行。保持 CJK 文本词语完整性(日文排版常用)
word-wrap
允许长单词或 URL 地址,换行到下一行,两种取值
break-word 强制断行
normal 按语言规则断行
word-wrap 现规范名称为 overflow-wrap,
用于控制长单词或URL的换行策略,默认仅在容器边界断行(如URL溢出时触发换行)
适用场景
word-break 用于严格宽度控制的布局(如表格或窄栏设计),可能破坏 CJK 文本语义
overflow-wrap 适合需要保持文本可读性同时避免溢出的场景(如长URL、代码块)
兼容性说明
overflow-wrap 完全兼容现代浏览器,建议优先使用
word-wrap 为遗留属性,仅部分浏览器支持
CJK 文本处理需注意 word-break: break-all 会强制断行,可能造成语义断裂
text-wrap: normal|none|unrestricted|suppress
规定文本的换行(折行)规则。目前主流浏览器都不支持
使用现代属性 word-wrap 或 overflow-wrap 替代 text-wrap
.content {
word-wrap: break-word;
overflow-wrap: break-word;
}user-select
auto 默认。如果浏览器允许,则可以选择文本。
none 防止文本选取。
https://www.w3ccoo.com/cssref/css3_pr_user-select.asp
文字超出部分打点
http://ruyic.com/blog/html/view.php?id=318
white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
淘宝的一些设置
body,button,input,select,textarea {
font: 12px/1.5 system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji,BlinkMacSystemFont,Helvetica Neue,Arial,PingFang SC,PingFang TC,PingFang HK,Microsoft Yahei,Microsoft JhengHei
}
h1,h2,h3,h4,h5,h6 {
font-size: 100%
}
address,cite,dfn,em,var {
font-style: normal
}
code,kbd,pre,samp {
font-family: courier new,courier,monospace
}
small {
font-size: 12px
}
ol,ul {
list-style: none
}
a {
color: inherit;
cursor: pointer;
text-decoration: none
}
a:hover {
text-decoration: none!important
}
a:focus {
outline: none
}二、背景
background-repeat
background-repeat: no-repeat 相当于写了下面两个
background-repeat-x: no-repeat 横坐标方向不重复
background-repeat-y: no-repeat 纵坐标方向不重复
background-repeat
repeat-x 只在 x 轴横向重复
repeat-y 只在纵向重复
repeat 默认值,两个方向都重复
http://ruyic.com/blog/html/view.php?id=332
background-size 预设值
1. contain
2. cover
background-repeat: no-repeat; /* 去掉重复 */ background-size: contain; /* 保证图片能完整的显示到div盒子里面 */ background-repeat: no-repeat; /* 去掉重复 */ background-size:cover /* 意思背景图一定要把这个区域撑满 */
background-size 数值
background-repeat: no-repeat; background-size: 300px 200px; /* 可以自己设置一些数值,宽300像素,高200像素 */ background-repeat: no-repeat; background-size: 100%; /* 意思是横向上一定要撑满,纵向上按照比例缩放 */ background-repeat: no-repeat; background-size: 100% 100%; /* 写两个100%,第一个表示横向撑满,第二个表示纵向撑满,于是背景图比例上就发生了变化 */
background-position 背景图的位置,预设值分别设置横向和纵向的位置
left
bottom
right
top
center
background-repeat: no-repeat; background-position: center; /* 表示横向居中,同时纵向也居中 */ background-repeat: no-repeat; background-position: center top; /* 横向居中,纵向靠上 */
也可以写数值,或百分比(百分比用的不多)
background-repeat: no-repeat; background-position: 0px 20px; /* 第二个数字表示纵向的Y坐标,离上边的距离 */
background-attachment 通常用于设置背景图是否固定
background-repeat: no-repeat; /* 设置不重复 */ background-size: 100%; /* 横向100%,纵向自适应 */ background-attachment: fixed; /* 设置背景图是相对于视口的,有点类似于固定定位 */
速写属性(简写)
background: url('./pic.jpg') 不重复 位置/尺寸 固定 颜色
位置和尺寸都可以写数值 50% 50%/100% 写一个斜杠
1. 斜杠前写位置
2. 斜杠后面写尺寸
background: url('pic.jpg') no-repeat 50% 50%/100% fixed #ffd200;位置这里也不可以不写 50% 50% 可以简单的写预设值center,总之顺序要先写位置,再写尺寸才行
background: url('pic.jpg') no-repeat center/100% fixed #ffd200;https://www.w3school.com.cn/cssref/pr_background-color.asp
background-color: color|transparent|initial|inherit;
background: url('../img/logo.png') center/contain no-repeat;
center 表示居中
contain 保证图片能完整的显示到 div 盒子里面
三、盒模型
background-clip 背景覆盖范围
border-box 背景覆盖边框盒(默认值)
content-box 背景覆盖内容盒
padding-box 背景覆盖填充盒
overflow 溢出处理
visible 默认情况下溢出是可见的
hidden 溢出的部分隐藏
scroll 生成滚动条
auto 还有一个值 auto,表示自动的意思,不需要滚动条的时候,滚动条就不出现,需要滚动条的时候才出现
flex-direction
设置主轴方向(常用)
row 默认值,主轴水平方向,从左向右排列
cloumn 主轴垂直方向,自上向下排列
row-reverse 主轴还是水平方向,自右向左排列
column-reverse 主轴垂直方向,自下向上排列
flex-wrap 换行(常用)
nowrap 默认值,不换行
wrap 换行
wrap-reverse 倒着换行,有点怪的排列,这种应用很少出现基本上不用
justify-content 基于主轴做的对齐方式
flex-start 默认值,在主轴开头对齐
flex-end 在主轴结尾对齐
center 居中(主要用到)
space-between 在主轴上平均分配 多加几个子元素方便看到效果
space-around 设置子元素两侧的空间,space是空隙的意思,round之前见过
align-items
设置交叉轴的对齐方式,单行文本
align-content
设置交叉轴的对齐方式,多行文本
四、鼠标
cursor
| 值 | 描述 |
| auto | 默认,让浏览器来控制,比如遇到文字变成选择光标,在文本框变成输入状态 |
| poiner | 点击时的小手 |
| e-resize | 表示重新调整尺寸 |
| help | 帮助,鼠标箭头多了一个问号 |
| not-allowed | 禁止(分页) |
| text | 鼠标在文本上是一个竖线 |
五、边框
边框做三角型
border: 10px solid; border-color: transparent transparent #579e68 transparent; border: 10px solid transparent; border-top-color: #b0b0b0;
CSS 参考手册 https://www.runoob.com/cssref/pr-class-cursor.html
示例
<style>
.option{
height:90px;width:900px;margin:0 auto;border-bottom:1px solid #eaeaea;
display: flex;
align-items: center;
justify-content: center;
}
.optionTab{
font-size: 32px;
flex-grow: 1;
text-align: center;
height: 55px;
line-height: 55px;
position: relative;
}
.optionTab:nth-child(1){
border-right: 1px solid #eaeaea;
}
.optionTab:nth-child(2){
border-right: 1px solid #eaeaea;
}
.option > .optionTab::after{
content: "";
display: block;
position: absolute;
width: 0;
height: 0;
border: 10px solid transparent;
border-top-color: #b0b0b0;
left: 194px;
top: 24px;
/* transition: 500ms; */
}
.option .optionTab:nth-child(1):hover::after{
border-top-color: red;
transform-origin: center 5px;
transform: rotate(0.5turn);
}
</style>
<div class="option">
<div class="optionTab city" data-id="0" id="city">全城</div>
<div class="optionTab brand" data-id="1" id="brand">品牌</div>
<div class="optionTab special" data-id="2" id="special">特色</div>
</div>六、表单
1. 重置
文本框的边框是外面的 .search 元素,文本框里面清除默认样式
文本框下拉列表的字体默认大小是 13.33333px,我们同样改成 13px
2. 统一设置鼠标上面都是小手
3. 设置自己的样式
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>表单样式</title>
<link rel="stylesheet" href="http://at.alicdn.com/t/c/font_3463133_5bvselrd2ss.css">
<style>
/* 重置样式 */
*{padding: 0;margin: 0;}
input,button{
border: none;
outline: none;
outline-offset: 0; /* 外边框的偏移量 */
}
button{
background: initial;/* 重置按钮按钮背景颜色为继承,或transparent透明也可以 */
padding: 0;
}
/* 统一样式 */
button{
cursor:pointer;
}
/* 公共样式 */
.container{
width: 950px;
margin: 0 auto;
}
/* 表单样式 */
html,body{height:100%;}
.search{
width: 270px;
height: 30px;
border: 1px solid #c3c3c3;
position: relative;
top:50%;left:50%;margin-left:-135px;margin-top:-15px;
}
.search .txt{
width: 240px;
height: 20px;
padding: 5px;
font-size: 13px;
}
.search .txt::placeholder{
color: #ccc;
}
.search button{
color: #c3c3c3;
position: absolute;
height: 30px;
width: 30px;
top: 0;
right: 0;
}
</style>
</head>
<body>
<div class="search">
<form>
<input type="text" maxlength="60" size="12" class="txt" placeholder="书籍、电影、音乐、小组、小站、成员" autocomplete="off" name="q">
<button>
<i class="iconfont icon-sousuo4"></i>
</button>
</form>
</div>
</body>
</html>七、盒子
border-radius
圆角边框是一个速写属性
上左的圆弧半径 border-top-left-radius
上右的圆弧半径 border-top-right-radius
下右的圆弧半径 border-bottom-right-radius
下左的圆弧半径 border-bottom-left-radius
单独设置两个圆角
border-bottom-right-radius:0
border-top-right-radius:0
也可以这样,按照次序依次书写
border-radius: 左上 右上 右下 左下
box-shadow: 0px 0px 2px 2px rgba(0, 0, 0, .2)
五个参数分别是
1. 0px 阴影横坐标偏移量
2. 0px 阴影横坐标偏移量
3. 2px 阴影模糊程度,像素越大越模糊
4. 2px 阴影的扩散半径,扩散范围
5. rgba(0, 0, 0, .2) 阴影颜色,一般是透明色
box-shadow: 1px 1px 2px #999
只写四个参数,没有扩散半径
九、其他
图标
<link rel="shortcut icon" type="image/x-icon" href="./img/favicon.ico">
网页图标 favicon.ico 介绍及使用 https://blog.csdn.net/weixin_41287260/article/details/97621561
浮动
.left{
float: left;
}
.right{
float: right;
}
.clearfix::after{
content: "";
display: block;
clear: both;
}重置样式
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
text-decoration: none;
color: inherit;
}
/* 重置文本框和按钮聚焦样式、边框...*/
input,button{
border: none;
outline: none;
outline-offset: 0; /* 外边框的偏移量 */
}
/* 重置按钮按钮背景颜色为继承或transparent透明也可以 */
button{
background: initial;
padding: 0;
}object-fit 属性一般用在图片里面使用,表示图片的适用方式
contain 图片宽高比例不变,但是图片所有内容又要显示在img元素里面
fill 默认值 fill,就是填充会把整个图片全部显示出来,但是不能保持比例
cover
