带网格显示的日历-在网格单元底部垂直对齐注释/任务,另一种在上面]]

问题描述 投票:0回答:1

我目前正在执行日历。我已使用网格布局显示日历日单元格。我想将一些不同类型的任务/笔记显示为某些网格单元中的条。任务应在单元格的底部边框中垂直对齐,而不影响日历日单元格的显示。任务条的宽度应适合(触摸单元格的左右边框)单元格宽度(100%)。如果一天的单元格中有多个任务(例如,5月26日),则应使其一个对齐,另一个任务之间应有2像素的间隔。

enter image description here

示例代码如下。您可以帮助实现预期的设计吗?

jsFiddle

<div id="calendar_container" class="calendar-container">
    <div class="calendar-header-row">                    
        <span id="calendar_header" class="calendar-header">May 2020</span>

        <span id="prev_month" class="prevMonth" onclick="javascript: previousMonth()"><img src="/images/arrow_left.png"></span>

        <span id="next_month" class="nextMonth" onclick="javascript: nextMonth()"><img src="/images/arrow_right.png"></span>
    </div>

    <div id="calendar_body" class="calendar"><div class="day-name">Sunday</div><div class="day-name">Monday</div><div class="day-name">Tuesday</div><div class="day-name">Wednesday</div><div class="day-name">Thursday</div><div class="day-name">Friday</div><div class="day-name">Saturday</div><div class="day"></div><div class="day"></div><div class="day"></div><div class="day"></div><div class="day"></div><div class="day">01</div><div class="day">02</div><div class="day">03</div><div class="day">04</div><div class="day">05</div><div class="day">06</div><div class="day">07</div><div class="day">08</div><div class="day">09</div><div class="day">10</div><div class="day">11</div><div class="day">12</div><div class="day">13</div><div class="day">14</div><div class="day">15</div><div class="day">16</div><div class="day">17</div><div class="day">18</div><div class="day">19</div><div class="day">20</div><div class="day">21</div><div class="day">22</div><div class="day">23</div><div class="day">24</div><div class="day">25</div><div class="day">26<div class="task error">Error 1 here</div><div class="task info2">Info 2 here<span class="circle" style="padding-left: 7px;">3</span></div><div class="task error2">Error 2 here</div></div><div class="day">27</div><div class="day">28</div><div class="day">29</div><div class="day">30</div><div class="day">31</div><div class="task warning">Warning here</div><div class="task info">Info here</div></div>
</div>



<style>

.calendar-container {
    border: 1px solid orange;
    overflow: hidden;
    max-width: 1200px;
}

.calendar-header-row {
    height: 50px;
    line-height: 50px;
    margin-bottom: 3px;
    background-color: #cccccc;
}

.calendar-header {
    font-size: 16px;
    font-weight: bold;

    padding: 0px 20px;
}

.prevMonth, .nextMonth {
    font-size: 16px;
    font-weight: bold;

    cursor: pointer;
    margin-right: 12px;
}

.calendar {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(7, minmax(120px, 1fr));
    grid-template-rows: 50px;
    grid-auto-rows: 120px;
}

.day-name {
    font-size: 15px;
    font-weight: bold;
    color: #000000;
    background-color: #cccccc;

    border-right: 1px solid #b9b9b9;

    text-transform: uppercase;
    padding: 0 20px;

    height: 50px;
    line-height: 50px;

    pointer-events: none;
    user-select: none;
}

.day {
    position: relative;
    z-index: 1;

    border-bottom: 1px solid #b9b9b9;
    border-right: 1px solid #b9b9b9;

    text-align: left;
    padding: 16px 20px;

    letter-spacing: 1px;
    font-size: 16px;
    font-weight: bold;
    color: #000000;

    pointer-events: none;
    user-select: none;
}


.day:nth-of-type(7n + 7) {
    border-right: 2px;
}

.day:nth-of-type(n + 1):nth-of-type(-n + 7) {
    grid-row: 1;
}

.day:nth-of-type(n + 8):nth-of-type(-n + 14) {
    grid-row: 2;
}

.day:nth-of-type(n + 15):nth-of-type(-n + 21) {
    grid-row: 3;
}

.day:nth-of-type(n + 22):nth-of-type(-n + 28) {
    grid-row: 4;
}

.day:nth-of-type(n + 29):nth-of-type(-n + 35) {
    grid-row: 5;
}

.day:nth-of-type(n + 36):nth-of-type(-n + 42) {
    grid-row: 6;
}

.day:nth-of-type(7n + 1) {
    grid-column: 1/1;
}

.day:nth-of-type(7n + 2) {
    grid-column: 2/2;
}

.day:nth-of-type(7n + 3) {
    grid-column: 3/3;
}

.day:nth-of-type(7n + 4) {
    grid-column: 4/4;
}

.day:nth-of-type(7n + 5) {
    grid-column: 5/5;
}

.day:nth-of-type(7n + 6) {
    grid-column: 6/6;
}
.day:nth-of-type(7n + 7) {
    grid-column: 7/7;
}

.task {
    border-left-width: 5px;
    border-left-style: solid;

    padding: 4px 4px;
    background-color: #8f8f8f;
    color: #ffffff;

    font-size: 12px;
    font-weight: normal;
    position: relative;

    height: min-content;
}

.info {
    border-left-color: #348401;
}

.warning {
    border-left-color: #e5941f;

}

.error {
    border-left-color: #c70623;
}

.info2 {
    border-left-color: #348401;
}

.error2 {
    border-left-color: #c70623;
}

.circle {
    border-radius: 50%;

    height: 20px;
    width: 20px;
    background-color: #348401;

    display: inline-block;
    float: right;
}

</style>

    

我目前正在执行日历。我已使用网格布局显示日历日单元格。我想将一些不同类型的任务/笔记显示为某些网格单元中的条。任务...

html css css-grid vertical-alignment
1个回答
0
投票

在特定单元格中进行以下更改:

© www.soinside.com 2019 - 2024. All rights reserved.