带有网格显示的日历 - 垂直对齐 notes/tasks 在网格单元格的底部一个在另一个上面
Calendar with grid display - vertical align notes/tasks at the bottom of the grid cell one above another
我目前正在实施日历。我使用网格布局来显示日历日单元格。我想在某些网格单元格中显示一些 tasks/notes 不同类型的条带。任务应该在单元格的底部边框垂直对齐,而不影响日历日单元格的显示。任务条的宽度应适合(触摸单元格的左右边框)单元格宽度 (100%)。如果一天单元格中有多个任务(例如,5 月 26 日),则应将它们一个一个地对齐,并在它们之间留出 2px 的间距。
示例代码如下。你能帮助实现预期的设计吗?
<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>
特定单元格中的以下更改:
<div class="day">
<div>26</div>
<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>
和
.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;
/* The flex layout will do the trick */
display: flex;
flex-direction: column;
}
.day > div {
/* Set size of the container according to the content */
flex: 0 0 auto;
}
.day > div:first-child {
text-align: left;
padding: 16px 20px;
padding-bottom: 0;
/* To shift the tasks to the bottom of the cell */
margin-bottom: auto;
}
以上 CSS 修改对我来说很有效,实现了所需的布局。
我目前正在实施日历。我使用网格布局来显示日历日单元格。我想在某些网格单元格中显示一些 tasks/notes 不同类型的条带。任务应该在单元格的底部边框垂直对齐,而不影响日历日单元格的显示。任务条的宽度应适合(触摸单元格的左右边框)单元格宽度 (100%)。如果一天单元格中有多个任务(例如,5 月 26 日),则应将它们一个一个地对齐,并在它们之间留出 2px 的间距。
示例代码如下。你能帮助实现预期的设计吗?
<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>
特定单元格中的以下更改:
<div class="day">
<div>26</div>
<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>
和
.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;
/* The flex layout will do the trick */
display: flex;
flex-direction: column;
}
.day > div {
/* Set size of the container according to the content */
flex: 0 0 auto;
}
.day > div:first-child {
text-align: left;
padding: 16px 20px;
padding-bottom: 0;
/* To shift the tasks to the bottom of the cell */
margin-bottom: auto;
}
以上 CSS 修改对我来说很有效,实现了所需的布局。