demo2-CSS日历模仿

这是模仿视频做的一个CSS日历,先上效果图
demo2-CSS日历模仿_第1张图片
整体思路是:一个大盒子分为左右两个子盒子,他们的display属性都设置为inline-block,但是因为设置为inline-block后两个盒子之间会有空隙,这里有个巧法就是把他们的父盒子的font-size设为0。

HTML部分:


"en">


    "UTF-8">
    "viewport" content="width=device-width, initial-scale=1.0">
    Document
    "stylesheet" href="css/style.css">



    
"box">
"left">
"week">Monday
"day">13
"right">
"year">July 2020
"calender">
"weeks">
"item">s
"item">m
"item">t
"item">w
"item">t
"item">f
"item">s
"days">
"day">28
"day">29
"day">30
"day">1
"day">2
"day">3
"day">4
"day">5
"day">6
"day">7
"day">8
"day">9
"day">10
"day">11
"day">12
"day today">13
"day">14
"day">15
"day">16
"day">17
"day">18
"day">19
"day">20
"day">21
"day">22
"day">23
"day">24
"day">25
"day">26
"day">27
"day">28
"day">29
"day">30
"day">31
"day">1

CSS部分:

@import url(href="https://fonts.font.im/css?family=Karla" rel="stylesheet");
* {
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background-color: darkcyan;
    display: flex;
    justify-content: center;
    align-items: center;
}

.box {
    width: 700px;
    height: 400px;
    background-color: white;
    /*为了清除inline-block产生的距离*/
    font-size: 0;
    border-radius: 20px;
}

/*左边部分*/

.left {
    display: inline-block;
    width: 350px;
    height: 400px;
    text-align: center;
    vertical-align: top;
    background-color: rgb(43, 223, 223);
    border-top-left-radius: 20px;
    border-bottom-left-radius: 20px;
}

.week {
    font-family: 'Karla', sans-serif;
    text-transform: uppercase;
    font-size: 35px;
    color: white;
    line-height: 100px;
}

.left .day {
    font-size: 180px;
    color: white;
}

/*右边部分*/

.right {
    display: inline-block;
    width: 350px;
    height: 400px;
    text-align: center;
}

.right .year {
    font-family: 'Karla', sans-serif;
    text-transform: uppercase;
    font-size: 35px;
    line-height: 100px;
    color: rgb(43, 223, 223);
}

.calender {
    padding: 0 35px;
}

.weeks .item {
    display: inline-block;
    text-transform: uppercase;
    font-size: 18px;
    width: 40px;
    height: 40px;
    line-height: 40px;
    color: crimson;
    font-weight: bolder;
}

.days .day {
    display: inline-block;
    width: 40px;
    height: 40px;
    font-size: 15px;
    line-height: 40px;
    transition: .2s;
}

.today {
    background-color: crimson;
    font-weight: bolder;
    color: white;
}

.days .day:hover {
    background-color: rgb(224, 57, 91);
    color: white;
    font-weight: bolder;
}

get new idea:
1.解决两个display属性值为inline-block的盒子中间的缝隙,我们可以给父盒子添加font-size:0;
2.text-transform可以转换不同元素中的文本,这里是转化成大写字母。

视频原地址:https://www.bilibili.com/video/BV1Ma4y1a76e

你可能感兴趣的:(CSS)