【无标题】css3新增的特性+如何让一个盒子水平垂直居中

本文详细介绍了如何使用CSS实现盒子水平垂直居中、圆角、盒阴影、渐变效果,以及过渡、2D/3D转换、动画和关键帧的运用。同时讨论了文本阴影、自定义字体和响应式设计在网页设计中的实践。
摘要由CSDN通过智能技术生成

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 实现盒子水平垂直居中 -->
    <div class="box_box">
        <div class="box"></div>
    </div>
    <!-- 水平垂直居中第二种方法+圆角+盒阴影+渐变 -->
    <div class="big_box">
        <div class="small_box"></div>
    </div>
    <!-- 实现盒阴影的动画(过渡),旋转+倾斜+缩放+平移+动画 -->
    <!-- transform:  旋转: rotate(45deg)   缩放: scale(1.5)   倾斜: skew(30deg, 20deg)   平移: translate(50px, 20px); -->
    <div class="transition">
        <div class="transition_box"></div>
    </div>
    <!-- 文本添加阴影 -->
        <h1>文本添加阴影</h1>
</body>
<script></script>
<style scoped>
    html,body{
        height: 100%;
        margin: 0;
    }
    /* .box_box{
        height: 100%;
        margin: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .box{
        width: 300px;
        height: 300px;
        background-color: red;
    }
    .big_box{
        position: relative;
        height: 100vh;
    }
    .small_box{
        width: 100px;
        height: 100px;
        border: 1px solid saddlebrown;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        border-radius: 10px;
        border-top-left-radius: 20px;
        box-shadow: 5px 5px 10px 0 rgba(0, 0, 0, 5);
        background: linear-gradient(45deg, #ffcccc, #6699ff);
    } */
    .transition{
        height: 100%;
        margin: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .transition_box{
        width: 200px;
        height: 200px;
        background-color: #3498db;
        color: #ffffff;
        transition: background-color 3s ease 0.3s;
        /* transition: property duration timing-function delay;
        transition: property; 过渡的属性名称 有:background-color,color
        transition: duration; 过渡持续的时间
        transition: timing-function; 过渡动画的时间函数 默认值:ease(先慢后快再慢),还有其他值:linear(匀速)、ease-in(先慢后快)、ease-out(先快后慢)
        transition: delay; 开始过渡动画的延迟时间 */
        transform: rotate(45deg) scale(1.5) skew(30deg, 20deg) translate(50px, 20px);
        /* transform: rotate(45deg);  旋转
        transform: skew(30deg, 20deg); 倾斜
        transform: scale(1.5); 缩放
        transform: translateZ(50px); 平移 */
        /* animation: moveRight 2s ease-in-out 1s infinite; */
        /* animation: moveRight 2s ease-in-out 1s infinite alternate; */
        animation-name: transition_box;
        animation-duration: 3s;
        animation-timing-function: ease;
        animation-delay: 0.5s;
        animation-iteration-count: infinite;
        /* animation-name: transition_box;  动画的名称
        animation-duration: 3s;  动画持续的时间
        animation-timing-function: ease;动画的时间函数
        animation-delay: 0.5s; 动画开始的延迟时间
        animation-iteration-count: infinite; 循环播放的次数   infinite:无限循环*/
    }
    @keyframes transition_box {
        0% { opacity: 0; }
        50% { opacity: 1; }
        100% { opacity: 0; }
    }
    .transition_box:hover{
        background-color: #29b954;
    }
    h1{
        text-shadow: 2px 2px 4px red;
    }
</style>
</html>

  1. 边框效果(Border Effects)

    • 圆角边框(border-radius):通过设置 border-radius 属性可以使元素的边框呈现圆角效果。
    • 阴影效果(box-shadow):通过设置 box-shadow 属性可以为元素添加阴影效果。
  2. 过渡效果(Transitions)

    • 过渡动画(transition):通过设置 transition 属性可以定义元素在状态改变时的过渡效果,如颜色、尺寸、透明度等的平滑过渡。
  3. 2D/3D 转换(Transform)

    • 元素变形(transform):通过设置 transform 属性可以实现元素的旋转、缩放、倾斜和平移,创造出立体和动态效果。
  4. 动画(Animations)

    • 关键帧动画(@keyframes):通过定义关键帧动画,可以实现复杂的动画效果,如透明度、位置、尺寸等的动态变化。
  5. 字体效果(Typography)

    • 自定义字体(@font-face):通过 @font-face 规则可以引入自定义字体,丰富网页中文字的样式和呈现效果。
    • 文本阴影(text-shadow):通过设置 text-shadow 属性可以为文本添加阴影效果。
  6. 背景效果(Backgrounds)

    • 线性渐变(linear-gradient):通过设置 background-image 可以创建线性渐变背景。
    • 辐射渐变(radial-gradient):通过设置 background-image 可以创建辐射渐变背景。
  7. 响应式设计(Responsive Design)

    • 媒体查询(@media):媒体查询可以根据设备的特性(如屏幕宽度、高度等)为不同的设备提供样式,实现响应式设计
  • 23
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值