web前端4

DAY4

  • 盒子模型

在这里插入图片描述

  • 内边距

    <style>
        div{
            padding-top/left/right:200px;
            padding: 10px 30px 60px
             		/*上   左右  下*/
            padding: 10px 30px 60px 90px;
            /*        上   右   下    左*/
        }
    
    </style>
    
  • 外边距

    <style>
        ul li{
            margin-bottom/right/left/top:30px;
            /*外边距不影响盒子内部大小*/       
        }
    
    </style>
    
    • 外边距塌陷问题
    <style>
    	*{
    		margin: 0;
    		padding: 0;
    	}
    	.father{
    		width:300px;
    		height:300px;
    		background-color:pink;
    	}
    	.son{
    		width:100px;
    		height:100px;
    		background-color:skyblue;
    		margin-top:50px;
    	}
    </style>
    <div class="father">
    	<div class="son"></div>
    </div>
    

    解决方法:

    1. 给父元素加边框border

    2. 给父元素加内边距padding

    3. 给父元素加overflow:hidden

  • css样式的继承性

    * 不是所有样式都继承,只有改变之后对布局无影响的样式才会继承。
    
      a链接最好在自身更改样式
    
  • flex布局

<style>
	display:flex;
    
    /*排列方式*/
    flex-direction:row-reverse;
    flex-direction:column;
    flex-direction:column-reverse;
    flex-direction:row;
    /*让flex布局变为多行*/
    flex-wrap:wrap;
    flex-wrap:nowarp;
    /*主轴上的布局*/
    justify-content:center;
    justify-content:end;
    justify-content:space-between;
    justify-content:space-around;
    justify-content:space-evenly;
    /*侧轴上的布局*/
    单行
    align-items:center;
    align-items:start;(默认)
    多行
    align-content:end;
    align-content:sapce-between;
    align-content:space-around;
    align-content:space-evenly;
    
</style>
  • 浮动

    <style>
    		img {
                width: 100px;
                float: left;
            }
    
    </style>
    
  • float

    <style>
            .father {
                width: 1000px;
                /* height: 1000px;  */
                background-color: pink;
            }
    
            .son {
                float: left;
                width: 200px;
                height: 200px;
                background-color: aqua;
            }
    
            .son2 {
                background-color: blue;
                float: left;
                /* 浮动,会脱离文档流   不再保留原来位置  会造成在其下方的兄弟元素位置发生变化  */
                /* 当子元素发生浮动时,其父元素的高度发生塌陷 */
    
            }
    
            .son3 {
                width: 400px;
    
                background-color: black;
            }
        </style>
    </head>
    
    <body>
        <div class="father">
            <div class="son son1"></div>
            <div class="son son2"></div>
            <div class="son son3"></div>
    
        </div>
    </body>
    
    • float的解决方法:

      1.父元素 overflow: hidden

      2.clear: both;

  • 渐变

    <style>
            div {
                width: 400px;
                height: 800px;
                background-image: linear-gradient(to right, green, pink, yellow, red);
    
            }
        </style>
    
  • 2d转换

    .son {
                width: 300px;
                height: 300px;
                background-color: pink;
                /* 平移 */
                /* transform: translate(-40px, 40px); */
                /* transform: translateX(70px); */
                /* transform: translateY(-60px); */
                /* 旋转 */
                /* transform: rotateZ(40deg); */
                /* 复合写法  旋转永远放在最后一个 */
                /* transform: translate(100px) rotateZ(45deg); */
                /* transform: rotateZ(45deg) translate(100px); */
                /* transform: scale(1.5); */
                /* transform: scaleX(2); */
                /* transform: scaleY(2); */
                /* transform: skew(40deg); */
                /* 向右下移动100px   旋转45度    缩放1.5 */
                transform: translate(100px, 100px) scale(1.5) rotate(45deg);
    
            }
    
  • 3d转换

     <style>
            .father {
                width: 300px;
                height: 300px;
                border: 1px solid black;
                margin: 100px auto;
                transform-style: preserve-3d;
                perspective: 800px;
                /* perspective-origin: 100px 200px; */
    
            }
    
            .son {
    
                width: 300px;
                height: 300px;
                background-color: pink;
                /* transform: translateZ(-200px); */
                transform: rotateX(45deg);
                /* transform: rotateY(45deg); */
                /* transform: rotate3d(1, 1, 0, 45deg); */
                backface-visibility: hidden;
                transform-origin: bottom;
            }
        </style>
    </head>
    
    <body>
        <div class="father">
            <div class="son">2222222</div>
    
        </div>
    </body>
    
  • 过渡

<style>
        .father {
            width: 300px;
            height: 300px;
            border: 1px solid black;
            margin: 100px auto;
            transform-style: preserve-3d;
            perspective: 800px;
            /* perspective-origin: 100px 200px; */

        }

        .son {
            /* transition   谁变化给谁加 */
            transition: all 5s;

            width: 300px;
            height: 300px;
            background-color: pink;
            /* transform: translateZ(-200px); */
            /* transform: rotateY(45deg); */
            /* transform: rotate3d(1, 1, 0, 45deg); */
            /* backface-visibility: hidden; */

        }

        .son:hover {
            width: 800px;
            transform: rotateX(45deg);

        }
    </style>
  • 动画

    <style>
            @keyframes myMovie {
                from {
                    width: 200px;
                    background-color: pink;
                }
    
                to {
                    width: 800px;
                    background-color: aqua;
                }
    
            }
    
            @keyframes myfirst {
                0% {
                    width: 200px;
                    background-color: pink;
                }
    
                20% {
                    width: 400px;
                    background-color: green;
                }
    
                80% {
                    width: 800px;
                    background-color: red;
                }
    
                100% {
                    width: 1200px;
                    background-color: aquamarine;
                }
            }
    
            div {
                width: 200px;
                height: 50px;
                background-color: aqua;
                animation: myMovie 5s infinite alternate steps(4);
                animation: myfirst 5s infinite alternate steps(400);
    
            }
        </style>
    </head>
    
    <body>
        <div>
    
        </div>
    </body>
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阳阳真的很菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值