Collection css
一、文字
font-family
font-size
淘宝的一些设置
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 }
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
文字超出部分打点
white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
More
http://ruyic.com/blog/html/view.php?id=318
二、背景
repeat
background-repeat: no-repeat; /* 相当于写了下面两个 */ background-repeat-x: no-repeat; /* 横坐标方向不重复 */ background-repeat-y: no-repeat; /* 纵坐标方向不重复 */
只在x轴横向重复
background-repeat: repeat-x;
只在纵向重复
background-repeat: repeat-y;
默认值repeat,两个方向都重复
background-repeat: 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坐标,离上边的距离 */
attachment
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盒子里面
三、弹性盒
529 CSS3弹性盒模型
579 CSS3语言提升布局
1、弹性项目
display
触发弹性盒模型
flex
inline-flex
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
设置交叉轴的对齐方式,单行文本
flex-start 在交叉轴的上面
flex-end 交叉轴的下面
center 居中
baseline 基于文字底线对齐
stretch 默认值,伸展/拉长/拽宽/撑大的意思,如果子元素不设置高度,默认值auto,子项高度撑满父元素内容区
align-content
设置交叉轴的对齐方式,多行文本
flex-start 交叉轴起始端
flex-end 交叉轴的尾部
center 交叉轴的中间
space-between 上下顶头,中间平均分配
space-around 行与行之间上下平均分配空间
stretch 把元素的高去掉,这个值才生效(默认值)
2、项目属性
order
默认值是0
值越小排的越靠前,要排到默认值前面最好填负数
align-self 对齐
子项作为一个单独的个体,它基于交叉轴的分配状况
auto 默认值,父元素align-items的值
flex-start 交叉轴上面
flex-end 交叉轴下面
center 交叉轴中间
baseline 文字基线
stretch
flex : 0 1 auto
flex速写属性:拉伸比例 压缩比例 初始化尺寸
flex-grow
默认值是0
grow扩大/增加/长高的意思
flex-shrink
默认值是1
shrink收缩/退缩/减少的意思
flex-basis
默认值是auto
basis代表基础占有多少空间,用来代替width属性优先级高于width
四、鼠标
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>
七、其他
图标
<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; }