Web-前端:CSS之经典总结

一、定位

1.相对定位 : relative---生成相对定位的元素,相对于其正常位置进行定位。因此,"left:20" 会向元素的 LEFT 位置添加 20 像素。

2.绝对定位:absolute---相对于 static 定位以外的第一个父元素进行定位。元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。

注意:

 1、如果Sub1 的父元素或者祖父元素,设置了Position属性,并且属性值为 absolute 或 relative的时候,那么子元素相对于父元素来进行定位。比如我们例子中最外层Div Parent设置了相对定位属性,因此Sub1 和 Sub2 两个Div 就根据 Div Parent 来进行定位。但是根据Parent那个定位点进行定位呢?答案是:如果parent设定了margin,border,padding等属性,那么这个定位点将忽略padding,将会从padding开始的地方(即只从padding的左上角开始)进行定位。

2、如果sub1不存在一个有着position属性的父对象,那么那就会以body为定位对象,按照浏览器的窗口进行定位。

3.固定定位 : fixed---生成绝对定位的元素,相对于浏览器窗口进行定位。

  注意:fixed 在IE 低版本中式不支持的,包括IE6

4.层级:z-index:俩个同级的div,其中一个的层级大, 那么它的子级都比它父集的同级要大,要优先。

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>定位的综合使用技巧</title>
    <style>
    .son1{
        width: 100px;
        height: 50px;
        background:rebeccapurple;
        position:absolute;
        left: 30px;
        top: 30px;
        position: relative;
        z-index: 20;
    }
    .son2{
        width: 100px;
        height: 50px;
        background:rosybrown;
        position: relative;
        left: 50px;
        top: 20px;
    }
    .father{
        width: 500px;
        height: 300px;
        margin: 50px auto;
        border: red 1px solid;
    }
    </style>
</head>
<body>
    <div class="father1">
        <div class="son1">
            SON1
        </div>
        <div class="son2">
            SON2
        </div>
    </div>
    <div class="father2">
            father2
    </div>
</body>
</html>

二、选择器

1.选择器的优先级:行内式 > id选择器 > 类选择器 > 标签选择器

那么, 如何改变优先级?

(1)!important  将所选的样式,设置为最高优先级

  (2) 利用父集增加优先级

demo

.father .son2{
        width: 100px;
        height: 50px;
        background:rosybrown;
        position: relative;
        left: 50px;
        top: 20px;
    }

2.常用的伪类选择器(仅仅局限于嵌套结构, 例如:ul-li)

(1) : first-child

(2) : last-child

(3) : nth-child

(4) : not

(5) : before(content)  

(6) : after(content)

三、动画

1.transform: 沿着什么轴旋转

---Rotate 、rotateX 、rotateY

---Scale

2.transition: 变化

---transition-delay

---transition-timing-function:ease   linear   ease-in(低速开始)   ease-out(低速结束) ease-in-out

3.animation: 动画

---animation: name time ease alternate

---animation-delay;

---animation-timing-function: linear  ease

---animation-direction: normal  reverse  alternate  alternate-reverse(偶正奇反)

---animation-iteration-count: infinite

4.@keyframes

四、常用CSS分享

1.box-shadow:x, y, 模糊距离,阴影大小, 颜色, inset

2.text-shadow:x, y, 模糊距离, 颜色

3.box-sizing:border-box;

4.white-space:nowrap;

5.word-break:break-word;break-all;

6.pointer-events:none;

7.user-select:none;

8.background:linear-gradient(角度, 颜色大小, 颜色 大小)

9.background:radial-gradient(颜色, 大小, )

五、flex布局

1.justify-content(水平分布)

flex-start, center, flex-end, space-between, space-around, space-evenly

2.align-items(竖直布局)

flex-start, center, flex-end, baseline(第一行文字对齐)

3.flex-wrap(换行)

wrap, wrap-reverse, nowrap

4.align-content(垂直分布)

同一

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值