Day06 vw;vh;B站案例

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

B站案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>b站</title>
    <link rel="stylesheet" href="./fonts/iconfont.css">
    <link rel="stylesheet" href="./css/index.css">
</head>
<body>

    <!-- 头部固定 -->

    <header>
        <div class="top">
            <div class="left">
                <a href="#">
                    <i class="iconfont Navbar_logo"></i>
                </a>
            </div>
            <div class="right">
                <a href="#">
                    <i class="iconfont ic_search_tab"></i>
                </a>
                <a href="#" class="login"><img src="./images/login.png" alt=""></a>
                <a href="#" class="download"><img src="./images/download.png" alt=""></a>
            </div>
        </div>
        <div class="bottom">
            <div class="tab">
                <ul>
                    <li><a href="#" class="current">首页</a></li>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">首页</a></li>
                </ul>
            </div>
            <div class="more">
                <a href="#">
                    <i class="iconfont general_pulldown_s"></i>
                </a>
            </div>
        </div>
    </header>
    <!-- 头部固定结束 -->
    <!-- tab: 菜单的个数要和内容的个数相等 -->
    <!-- 视频 -->
    <section class="video-cotent">
        <!-- 一份视频,  共计有五个菜单,未来应该有五份视频的div -->
        <div class="video-list">
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>
            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
            <a href="#">
                <div class="pic">
                    <img src="./images/1.jpg" alt="">
                    <div class="count">
                        <p>
                            <i class="iconfont icon_shipin_bofangshu"></i>
                            <span>132</span>    
                        </p>
                        <p>
                            <i class="iconfont icon_shipin_danmushu"></i>
                            <span>2.4</span>    
                        </p>
                    </div>
                </div>
                <div class="txt ellipsis-2">你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19</div>

            </a>
        </div>
    </section>
    <!-- 视频结束 -->
    <!-- 底部固定 -->

    <footer>
        <a href="#">
            <i class="iconfont Navbar_logo"></i>
            <span>打开App,看你感兴趣的视频</span>
        </a>
    </footer>
    <!-- 底部固定结束 -->
</body>
</html>

CSS样式表

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
body {
  font-family: Helvetica Neue, Tahoma, Arial, PingFangSC-Regular, Hiragino Sans GB, Microsoft Yahei, sans-serif;
}
a {
  color: #333;
  text-decoration: none;
}
img {
  vertical-align: middle;
  width: 100%;
  height: 100%;
}
ul {
  list-style: none;
}
.ellipsis-2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
header {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 1;
  width: 100%;
  height: 22.4vw;
  background-color: #fff;
}
header .top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 11.73333333vw;
  padding-left: 4.8vw;
  padding-right: 3.2vw;
}
header .top .left .iconfont {
  font-size: 7.46666667vw;
  color: #fb7299;
}
header .top .right {
  display: flex;
}
header .top .right .iconfont {
  font-size: 5.86666667vw;
  color: #ccc;
}
header .top .right .login {
  width: 6.4vw;
  height: 6.4vw;
  margin-left: 6.4vw;
}
header .top .right .download {
  width: 19.2vw;
  height: 6.4vw;
  margin-left: 6.4vw;
}
header .bottom {
  display: flex;
  justify-content: space-between;
  height: 10.13333333vw;
  border-bottom: 1px solid #eee;
}
header .bottom .more a {
  display: block;
  width: 10.66666667vw;
  height: 10.66666667vw;
  text-align: center;
  line-height: 10.66666667vw;
  color: #ccc;
}
header .bottom .more a .iconfont {
  font-size: 5.86666667vw;
}
header .bottom .tab ul {
  display: flex;
}
header .bottom .tab ul li {
  padding: 0 4.26666667vw;
}
header .bottom .tab ul li a {
  display: block;
  height: 10.13333333vw;
  line-height: 10.13333333vw;
  font-size: 3.73333333vw;
}
header .bottom .tab ul li a.current {
  color: #fb7299;
  border-bottom: 2px solid #fb7299;
}
.video-cotent {
  padding: 22.4vw 1.33333333vw 0;
}
.video-cotent .video-list {
  display: flex;
  flex-wrap: wrap;
}
.video-cotent .video-list a {
  width: 50%;
  padding: 2.13333333vw 1.33333333vw;
  font-size: 3.2vw;
}
.video-cotent .video-list a .txt {
  margin-top: 1.33333333vw;
}
.video-cotent .video-list a .pic {
  position: relative;
}
.video-cotent .video-list a .pic .count {
  position: absolute;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 2.13333333vw;
  background-image: linear-gradient(to top, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
  color: #fff;
}
.video-cotent .video-list a .pic .count i {
  vertical-align: middle;
}
footer {
  position: fixed;
  left: 0;
  bottom: 5.33333333vw;
  width: 93.6vw;
  height: 9.6vw;
  padding: 3.2vw;
}
footer a {
  display: block;
  width: 93.6vw;
  height: 9.6vw;
  background-color: #fb7299;
  border-radius: 4.8vw;
  line-height: 9.6vw;
  color: #fff;
  font-size: 3.73333333vw;
  text-align: center;
}

less代码

@import url(./base.less);
@vw: 3.75vw;
@color: #fb7299;



// 头部固定
header {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 1;
    width: 100%;
    height: (84 / @vw);
    background-color: #fff;
    .top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: (44 / @vw);
        padding-left: (18 / @vw);
        padding-right: (12 / @vw);
        // background-color: green;
        .left {
            .iconfont {
                font-size: (28 / @vw);
                color: @color;
            }
        }
        .right {
            display: flex;
            .iconfont {
                font-size: (22 / @vw);
                color: #ccc;
            }
            .login {
                width: (24 / @vw);
                height: (24 / @vw);
                margin-left: (24 / @vw);
            }
            .download {
                width: (72 / @vw);
                height: (24 / @vw);
                margin-left: (24 / @vw);

            }
        }
    }
    .bottom {
        display: flex;
        justify-content: space-between;
        height: (38 / @vw);
        border-bottom: 1px solid #eee;
        .more {
            a {
                display: block;
                width: (40 / @vw);
                height: (40 / @vw);
                // background-color: pink;
                text-align: center;
                line-height: (40 / @vw); 
                // font-size: (22 / @vw);
                color: #ccc;
                .iconfont {
                    font-size: (22 / @vw);
                }   
            }
        }
        .tab {
            ul {
                display: flex;
                li {
                    padding: 0 (16 / @vw);
                    a {
                        display: block;
                        height: (38 / @vw);
                        line-height: (38 / @vw);
                        font-size: (14 / @vw);
                        &.current {
                            color: @color;
                            border-bottom: 2px solid @color;
                        }
                    }
                }
            }
        }
    }
}
      
// 头部固定结束

// 视频
.video-cotent {
    padding: (84 / @vw) (5 / @vw) 0;

    .video-list {
        display: flex;
        // 弹性盒子换行
        flex-wrap: wrap;
        a {
            width: 50%;
            padding: (8 / @vw) (5 / @vw);
            // background-color: pink;
            font-size: (12 / @vw);
            .txt {
                margin-top: (5 / @vw);
            }
            .pic {
                position: relative;
                .count {
                    position: absolute;
                    left: 0;
                    bottom: 0;
                    display: flex;
                    justify-content: space-between;
                    width: 100%;
                    padding: (8 / @vw);
                    background-image: linear-gradient(to top, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
                    color: #fff;
                    i {
                        vertical-align: middle;
                    }
                }
            }
        }
    }
}
// 视频结束

// 底部固定

footer {
    position: fixed;
    left: 0;
    bottom: (20 / @vw);
    width: (351 / @vw);
    height: (36 / @vw);
    padding: (12 / @vw);
    a {
        display: block;
        width: (351 / @vw);
        height: (36 / @vw);
        background-color: @color;
        border-radius: (18 / @vw);
        line-height: (36 / @vw);
        color: #fff;
        font-size: (14 / @vw);
        text-align: center;
    }
}
// 底部固定结束

效果图
在这里插入图片描述

<think> 根据用户需求,用户希望了解在SQL中使用`DATEDIFF(DAY)`函数计算天数差的案例。虽然之前讨论过Oracle中没有直接的`DATEDIFF`函数,但用户明确要求的是使用`DATEDIFF(DAY)`的案例,因此需要提供在其他数据库(如SQL Server、MySQL等)中的示例。 根据引用内容: - 引用[5]提到`DATEDIFF`函数的通用语法:`DATEDIFF(datepart, startdate, enddate)`,其中`datepart`指定单位(如day)。 - 引用[4]给出了Hive中使用`DATEDIFF`计算天数差的简单示例。 因此,应展示不同数据库中`DATEDIFF(DAY)`的使用案例。 ### 回答结构: 1. **常见数据库中的`DATEDIFF(DAY)`函数语法**:简要说明不同数据库的差异。 2. **具体案例**:提供SQL Server、MySQL、Hive中的示例。 3. **注意事项**:提醒用户不同数据库的差异和常见错误。 ### 具体内容: #### 1. SQL Server中的`DATEDIFF(DAY)` 在SQL Server中,`DATEDIFF`函数接受三个参数:日期部分、开始日期、结束日期。计算天数差时,`datepart`参数为`DAY`或`dd`。 ```sql -- 计算两个日期之间的天数差 SELECT DATEDIFF(DAY, '2023-01-01', '2023-01-10') AS day_difference; -- 结果:9 ``` #### 2. MySQL中的`DATEDIFF` MySQL的`DATEDIFF`函数只接受两个日期参数,且默认计算天数差(无需指定单位): ```sql -- 计算两个日期之间的天数差(忽略时间部分) SELECT DATEDIFF('2023-01-10', '2023-01-01') AS day_difference; -- 结果:9 ``` #### 3. Hive中的`DATEDIFF` Hive的`DATEDIFF`函数与MySQL类似,也只需要两个日期参数: ```sql -- 计算两个日期之间的天数差 SELECT DATEDIFF('2023-01-10', '2023-01-01') AS day_difference; -- 结果:9 ``` ### 注意事项: - **参数顺序**:在SQL Server中,结束日期在前还是开始日期在前会影响结果的正负(结束日期-开始日期)。而MySQL和Hive是第一个日期减去第二个日期。 - **时间处理**:这些函数通常只考虑日期部分,忽略时间。例如: ```sql -- 在SQL Server中 SELECT DATEDIFF(DAY, '2023-01-01 23:59:59', '2023-01-02 00:00:01') AS diff; -- 结果:1(尽管实际时间差只有2秒) ``` - **跨数据库兼容性**:若需编写跨数据库SQL,建议使用标准方式(如直接日期相减)或封装函数。 ### 相关问题: 1. 如何在PostgreSQL中计算两个日期的天数差? 2. 使用`DATEDIFF`函数时如何处理NULL值? 3. 如何计算两个日期之间的工作日(排除周末)? </think>以下是在不同数据库中使用 `DATEDIFF(DAY)` 函数计算日期天数差的典型案例,结合具体场景说明使用方法: ### 📊 1. SQL Server 案例 **场景**:计算订单处理时长 ```sql -- 计算订单创建日期和发货日期的天数差 SELECT order_id, order_date, shipped_date, DATEDIFF(DAY, order_date, shipped_date) AS processing_days FROM orders WHERE shipped_date IS NOT NULL; ``` **输出示例**: | order_id | order_date | shipped_date | processing_days | |----------|-------------|--------------|-----------------| | 1001 | 2023-05-01 | 2023-05-03 | 2 | | 1002 | 2023-05-01 | 2023-05-10 | 9 | > ⚠️ 注意:SQL Server 中参数顺序为 `DATEDIFF(单位, 开始日期, 结束日期)`,结果为 **结束日期 - 开始日期** [^1][^5] --- ### 🐬 2. MySQL 案例 **场景**:统计用户注册后的活跃天数 ```sql -- 计算用户最后登录时间与注册时间的天数差 SELECT user_id, reg_date, last_login, DATEDIFF(last_login, reg_date) AS active_days FROM users WHERE last_login > reg_date; ``` **特点**: - MySQL 的 `DATEDIFF()` 只需两个日期参数,自动计算天数差 - **忽略时间部分**,仅比较日期值[^4] --- ### 🐝 3. Hive 案例 **场景**:分析用户留存率 ```sql -- 计算首次购买和第二次购买的时间间隔(天) SELECT user_id, DATEDIFF(second_purchase_date, first_purchase_date) AS repurchase_interval FROM ( SELECT user_id, MIN(order_date) AS first_purchase_date, LEAD(order_date, 1) OVER(PARTITION BY user_id ORDER BY order_date) AS second_purchase_date FROM sales ) tmp WHERE second_purchase_date IS NOT NULL; ``` --- ### ⚠️ 关键注意事项 1. **跨数据库差异** | 数据库 | 语法结构 | 是否包含时间 | |-----------|--------------------------------------|--------------| | SQL Server| `DATEDIFF(DAY, start, end)` | 否(仅日期)| | MySQL | `DATEDIFF(end, start)` | 否 | | Hive | `DATEDIFF(end, start)` | 否 | | Oracle | `end_date - start_date`(直接相减) | 是 | 2. **边界情况处理** ```sql -- SQL Server 中处理日期为 NULL 的情况 SELECT DATEDIFF(DAY, COALESCE(start_date, '1900-01-01'), end_date) FROM schedule; ``` 3. **性能优化** 在大数据场景下避免在 WHERE 子句中直接计算: ```sql -- 低效写法 ❌ SELECT * FROM logs WHERE DATEDIFF(DAY, create_time, GETDATE()) > 30; -- 高效写法 ✅ SELECT * FROM logs WHERE create_time < DATEADD(DAY, -30, GETDATE()); ``` ### 🌰 综合应用案例 **需求**:统计项目延期天数(仅工作日) ```sql -- SQL Server 实现(排除周末) SELECT project_id, SUM(CASE WHEN DATEPART(WEEKDAY, date_series) NOT IN (1,7) THEN 1 ELSE 0 END) AS work_days FROM ( SELECT project_id, DATEADD(DAY, num, plan_start_date) AS date_series FROM projects CROSS APPLY ( SELECT TOP (DATEDIFF(DAY, plan_start_date, actual_end_date)) ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) - 1 AS num FROM sys.objects ) dates ) t GROUP BY project_id; ``` [^1]: `DATEDIFF` 函数返回的是两个日期之间的整数天数差(不含时间部分) [^4]: 在 Hive 和 MySQL 中直接使用两个日期参数即可计算天数差 [^5]: SQL Server 需要明确指定时间单位和参数顺序
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值