左
右
.father {
width: 300px;
height: 300px;
background-color: pink;
/* 设计稿没有border就不能用 */
/* border: 1px solid #000; */
/* 最完美方法 */
/* overflow: hidden; */
}
-注意:
1.如果想要通过margin或者padding改变行内标签的垂直位置,无法生效
2.行内标签的margin-top和bottom不生效
3.行内标签的padding-top和bottom不生效
span {
/* margin: 100px; */
/* padding: 100px; */
line-height: 100px;
}
/* 选中第一个 */
/* li:first-child {
background-color: green;
} */
/* 选中最后一个 */
li:last-child {
background-color: pink;
}
/* 任意一个 */
li:nth-child(4) {
background-color: blue;
}
/* 倒数第xx个 */
li:nth-last-child(1) {
background-color: red;
}
/* 去除列表前的小点点 */
ul {
list-style: none;
}
| 功能 | 公式 |
|---|---|
| 偶数 | 2n,even |
| 奇数 | 2n+1,2n-1,odd |
| 找到前5个 | -n+5 |
| 找到从第5个往后 | n+5 |
li:nth-child(2n+1) {
background-color: pink;
color: rgb(110, 13, 155);
}
li:nth-child(-n+3) {
background-color: rgb(52, 23, 179);
color: rgb(155, 13, 13);
}
li:nth-child(4n) {
background-color: rgb(201, 204, 16);
color: rgb(8, 1, 1);
}
| 伪元素 | 作用 |
|---|---|
| ::before | 在父元素前添加伪元素 |
| ::after | 在父元素后添加伪元素 |
作用:网页布局。
1.浮动元素脱离标准流,在标准流中国不占位置
2.浮动元素比标准流高半个级别,可以覆盖标准流中的元素
3.浮动找浮动,下一个浮动元素会在上一个浮动元素后面左右浮动
4.浮动元素由特殊的显示效果
1.放浮动或者display
2.盒子模型相关的属性:margin,border,padding
3.文字样式
头部
左
右
1.在父级元素内容最后添加一个块级元素
2.给添加的元素设置clear:both
1.用伪元素替代了额外标签
.clearfix::before {
content: '';
/* 伪元素添加的是行内的,我们需要的是块级的 */
display: block;
clear: both;
}
.clearfix::before {
content: '';
/* 伪元素添加的是行内的,我们需要的是块级的 */
display: block;
clear: both;
height: 0;
visibility: hidden;
}
/* 清除浮动 */
/* .clearfix::before 用来解决外边距塌陷 */
.clearfix::before,
.clearfix::after {
content: '';
display: table;
}
/* 真正清除浮动的标签 */
.clearfix::after {
clear: both;
}
.top {
margin: 0 auto;
width: 1000px;
height: 300px;
background-color: pink;
overflow: hidden;
}
1.可以让元素自由的钉在网站的任何位置上。
| 定位方式 | 属性值 |
|---|---|
| 静态位置 | static |
| 相对位置 | relative |
| 绝对定位 | absolute |
| 固定定位 | fixed |
| 方向 | 属性名 | 属性值 | 含义 |
|---|---|---|---|
| 水平 | left | 数字+px | 距离左边的距离 |
| 水平 | right | 数字+px | 距离右边的距离 |
| 垂直 | top | 数字+px | 距离上边的距离 |
| 垂直 | bottom | 数字+px | 距离下边的距离 |
场景:解决行内(行内块)元素垂直对齐问题
问题:当图片和文字在一行中显示时,其实底部是不对齐的
属性名:vertical-align
属性值:
| 属性值 |效果|
|:-----??:------??
| baseline|默认基线对齐|
| top|顶部对齐 |
|middle|中部对齐 |
| bottom|底部对齐 |
注意:浏览器遇到行内和行内块标签当作文字处理,默认文字是按照基线对齐的。
.son img {
width: 300px;
/* 浏览器吧行内和行内块标签当作文字处理,默认基线对齐 */
/* vertical-align: middle; */
display: block
/*(两种解决办法都可以)*/
}
| 属性值 | 效果 |
|---|---|
| default | 默认值,通常时箭头 |
| poInter | 小手效果,提示用户可以点击 |
| text | 工字型,提示用户可以选择文字 |
| move | 十字光标,提示用户可以移动 |
1.盒子必须是正方形
2.设置边框圆角是盒子的一半(最大值50%)
1.盒子必须是长方形
2.设置:border-radius:盒子高度的一半
.two {
width: 600px;
height: 300px;
background-color: skyblue;
border-radius: 150px;
}
| 属性值 | 效果 |
|---|---|
| visible | 默认溢出部分可见 |
| hidden | 溢出部分隐藏 |
| scroll | 无论是否溢出,都显示滚动条 |
| auto | 根据是否溢出,自动显示或隐藏滚动条 |
.code {
position: absolute;
left: 50%;
top: 41px;
transform: translate(-50%);
display: none;
}
/* 鼠标悬停显示二维码图片 */
.nav li a:hover img {
display: block;
}
| 取值 | 场景 |
|---|---|
| 数字+px | 简单方便实用 |
| 百分比 | 相对于当前盒子自身的宽高比 |
| contain | 包含,将背景图片等比例缩放,知道不会超出盒子的最大 |
| cover | 覆盖,将背景图片等比例缩放,直到刚好填满整个盒子没有空白 |
.box::after {
background-position: right 0;
}
| 参数 | 作用 |
|---|---|
| h-shadow | 必须,水平位移量,允许负值 |
| v-shadow | 必须,垂直位移量,允许负值 |
| blur | 可选,模糊度 |
| spread | 可选,阴影扩大 |
| color | 可选,阴影颜色 |
| inset | 可选,将阴影改为内部阴影 |
| 参数 | 取值 |
|---|---|
| 过渡属性 | all:所有能过渡的属性都过渡。具体属性名:width:只有width过渡 |
| 过渡时长 | 数字+s |
京东全球版-专业的综合网上购物商城
1.引入样式表
2.引入内容
1.与设计沟通,得到svg格式矢量图
2.在iconfont网站上传图标,下载使用
.son {
position: absolute;
left: 50%;
top: 50%;
margin-left: -100px;
margin-top: -50px;
width: 200px;
height: 100px;
background-color: pink;
}
.son {
position: absolute;
left: 50%;
top: 50%;
/* margin-left: -100px;
margin-top: -50px; */
transform: translate(-50%, -50%);
width: 200px;
height: 100px;
background-color: pink;
}
.box:hover img {
/* 边走边转 */
transform: translate(600px) rotate(720deg);
/* 旋转可以改变坐标轴向 */
/* transform: rotate(720deg) translate(600px); */
/* taransform具有层叠性 */
/* transform: translate(600px);
transform: rotate(720px); */
}
.box .pic::after {
/* 播放按钮居中显示 */
position: absolute;
top: 50%;
left: 50%;
/* transform: translate(-50%, -50%); */
margin-left: -29px;
margin-top: -29px;
content: '';
width: 58px;
height: 58px;
background-image: url(./images/play.png);
/* 缩放原来的五倍 */
transform: scale(5);
transition: all 0.5s;
opacity: 0;
}
.box .pic::after {
/* 播放按钮居中显示 */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(5);注意这里
/* margin-left: -29px;
margin-top: -29px; */
content: '';
width: 58px;
height: 58px;
background-image: url(./images/play.png);
/* 缩放原来的五倍 */
/* transform: scale(5); */
transition: all 0.5s;
opacity: 0;
}
.box li:hover .pic::after {
transform: translate(-50%, -50%) scale(1);注意这里
opacity: 1;
}
.box li:hover .pic::after {
transform: scale(1);
opacity: 1;
}
background-image: linear-gradient( transparent, rgba(0, 0, 0, .6));
(transparent用来指定透明色)
.box:hover {
/* transform: translate3d(50px, 100px, 200px); */
transform: translateX(100px);
transform: translateY(100px);
transform: translateZ(100px);
}
透视效果
.box {
/* 透视效果:近大远小,近实远虚 */
perspective: 1000px;
}
.box img:hover {
transform: rotateZ(360deg);
}
.box img:hover {
transform: rotateX(60deg);
transform: rotateX(-120deg);
}
.box img:hover {
transform: rotateY(60deg);
}
.cube {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
/* background-color: pink; */
transition: all 2s;
transform-style: preserve-3d;(呈现3D效果)(要注意这个属性是添加给效果盒子的父级的!)
}
.cube:hover {
transform: rotateY(180deg);
}
transform: scale3d(0.5, 1.1, 2);
1.定义动画:
(第一种)
@keyframes 动画名称{
form{}
to{}
}
(第二种)
@keyframes 动画名称{
0%{}
10%{}
15%{}
100%{}
}
@keyframes change {
form {
width: 200px;
}
to {
width: 600px;
}
}
@keyframes change {
0% {
width: 200px;
}
50% {
width: 500px;
height: 300px;
}
100% {
width: 800px;
height: 500px;
}
}
/* 百分比指的是动画总时长的占比 */
2.使用动画
anomation: 动画名称 动画花费时长;
.box {
width: 200px;
height: 100px;
background-color: pink;
/* 使用动画 */
animation: change 1s;
}
/* animation: change 1s linear; */
animation: change 1s steps(3) 1s(延迟时间) 3(重复次数);
/* 无限循环 */
animation: change 1s infinite;
/* 反复执行状态 */
/* animation: change 1s infinite alternate(反复执行属性); */
/* 默认值, 动画停留在最初的状态 */
/* animation: change 1s backwards(默认值); */
/* 动画停留在结束状态 */
/* animation: change 1s forwards; */
| 属性 | 作用 | 取值 |
|---|---|---|
| animation-name | 动画名称 | |
| animation-duration | 动画时长 | |
| animation-delay | 延迟时间 | |
| animation-fill-mode | 动画执行完毕时状态 | forwords:最后一帧状态 backwards:第一阵状态 |
| animation-timing-function | 速度曲线 | steps(数字):逐帧动画 |
| animation-iteration-count | 重复次数 | infinite为无限循环 |
| animation-direction | 动画执行方向 | alternate为反向 |
| animation-play-state | 暂停动画 | paused为暂停,通常配合:hover使用 |
animation: move 1s steps(12) infinite, run 1s forwards;(多个动画效果可以用逗号隔开)
精灵动画
1
2
3
|:-----??:------??
| row|行,水平(默认)|
| column|列,垂直(重点) |
| row-reverse|行,从右向左 |
| column-reverse|列,从上向下 |
.box li {
display: flex;
/* 1. 先确定主轴方向; 2. 再选择对应的属性实现主轴或侧轴的对齐方式 */
/* 修改主轴方向: 列 */
flex-direction: column;
/* 视觉效果: 实现盒子水平居中 */
align-items: center;
/* 视觉效果: 垂直居中 */
justify-content: center;
width: 80px;
height: 80px;
border: 1px solid #ccc;
}
.box {
display: flex;
/* 默认值,不换行 */
/* flex-wrap: nowrap; */
/* 弹性盒子换行 */
flex-wrap: wrap;(案例中是加在父级上的)
height: 500px;
border: 1px solid #000;
}
.orders li .goods {
display: flex;
flex: 1;
padding: 17px 0 14px 12px;
align-items: center;
margin-right: 120px;
}
.orders .goods .txt {
flex: 1;
/* 溢出的时候显示省略号 */
/* 弹性盒子的尺寸可以被内容撑开,不换行的文字撑开 */
width: 0;
}
.orders .goods .txt h5 {
text-overflow: ellipsis;
white-space: nowrap;(不换行)
overflow: hidden;(溢出隐藏)
}
.box {
/* width: 10px; */
width: 5rem;
height: 5rem;
background-color: pink;
}
/* 1rem = 1html标签字号大小 */
html {
font-size: 12px;
}
.box {
width: 5rem;
height: 3rem;
background-color: pink;
font-size: 12rem;
}
目标:能够使用媒体查询设置差异化的css样式
/* 1. 不同的视口, HTML标签字号不同, 字号是视口宽度的1/10 */
@media (width:320px) {
html {
font-size: 32px;
}
}
@media (width:375px) {
html {
font-size: 37.5px;
}
}
@media (width:414px) {
html {
font-size: 41.4px;
}
.father {
color: red;
width: 1.81333333rem;
}
.father .son {
background-color: pink;
}
// 单行注释
/*
块注释
第二行
第三行
*/
.box {
width: 100 + 10px;
width: 100 - 20px;
width: 100 * 2px;
// 除法
// 68 > rem
width: (68 / 37.5rem);
// height: 29 ./ 37.5rem;
height: 29 / 37.5rem;
}
.father {
width: 100px;
.son {
color: pink;
// & 表示当前选择器
&:hover {
color: green;
}
}
&:hover {
color: orange;
}
}
// .father:hover {}(方便代码迁移)
.father {
width: 100px;
}
.father .son {
color: pink;
}
.father .son:hover {
color: green;
}
// 1. 定义. 2.使用
@colors:blue;
.box{
color: @color;
}
.father{
background-color: @colors;
}
.aa{
color: @colors;
}
.box {
color: blue;
}
.father {
background-color: blue;
}
.aa {
color: blue;
}
@import './01-体验less.less';(import后面加空格,后面加分号)
@import './02-注释';(如果引入的是less文件,则可以不用写.less后缀)
// out: ./qqq/daqiu.css
// out: ./abc/
.box {
color: red;
}
// out: ./
//68 * 29 --vw
.box {
width: (68/3.75vw);
height: (29/3.75vw);
background-color: pink;
}
.box2{
//vh
width: (68/6.67vh);
height: (27/6.67vh);
background-color: green;
}
// 不允许宽高混用,避免全面屏的影响
.box {
// 68 vw * 29 vh
width: (68 / 3.75vw);
height: (29 / 6.67vh);
background-color: pink;
}
@media 关键词 媒体类型 and (媒体属性) { css代码 }
| 类型名称 | 值 | 描述 |
|---|---|---|
| 屏幕 | screen | 带屏幕的设备 |
| 打印预览 | 打印预览模式 | |
| 阅读器 | speech | 屏幕阅读模式 |
| 不区分类型 | all | 默认值,包括以上3种类型 |
| 特性名称 | 属性 | 值 |
|---|---|---|
| 视口的宽高 | width,height | 数值 |
| 视口最大宽或者高 | max-width,max-height | 数值 |
| 视口最小宽或者高 | min-width,min-height | 数值 |
| 屏幕方向 | orientation | portrait:竖屏;landscape横屏 |
| 超小屏幕 | 小屏幕 | 中等屏幕 | 大屏幕 | |
|---|---|---|---|---|
| 响应断点 | <768px | >=768px | >=992px | >=1200px |
| 别名 | xs | sm | md | lg |
| 容器宽度 | 100% | 750% | 970% | 1170% |
| 类前缀 | col-xs- | col-sm- | col-md- | col-lg- |
| 列数 | 12 | 12 | 12 | 12 |
| 列间隙 | 30px | 30px | 30px | 30px |
1
2
3