使clndr.js日历响应

时间:2018-08-09 00:15:20

标签: javascript underscore.js clndr.js

我有一个日历,它是由CLNDR插件制作的,非常好,使用underscore.js,moment.js。日历工作正常,但问题是如何使它响应较大的屏幕和较小的屏幕。我已经尝试过,但是只有天标头可以响应,而各个天都没有响应,并且它会带来不准确的信息。

See the fiddle here.

我要使其具有响应性的方法(会带来上述错误):

#mini-clndr .clndr .days-container .days .headers .day-header {
   width: 14%;
   display: inline-block;
   text-align: center;
   color: white;
}

感谢帮助

1 个答案:

答案 0 :(得分:0)

我的建议是使用Bootstrap。 签出此链接:https://getbootstrap.com/docs/3.3/css/ 它将使您可以灵活地创建日历。

这是来自 https://www.w3schools.com/howto/howto_css_calendar.asp

(将其整页显示,以查看调整屏幕大小时的行为)

/**
 * Author: w3schools.com
 * URL: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_calendar
 */ 
/**
 * Author: w3schools.com
 * URL: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_calendar
 */ 
 
 * {box-sizing: border-box;}
ul {list-style-type: none;}
body {font-family: Verdana, sans-serif;}

.month {
    padding: 70px 25px;
    width: 100%;
    background: #1abc9c;
    text-align: center;
}

.month ul {
    margin: 0;
    padding: 0;
}

.month ul li {
    color: white;
    font-size: 20px;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.month .prev {
    float: left;
    padding-top: 10px;
}

.month .next {
    float: right;
    padding-top: 10px;
}

.weekdays {
    margin: 0;
    padding: 10px 0;
    background-color: #ddd;
}

.weekdays li {
    display: inline-block;
    width: 13.6%;
    color: #666;
    text-align: center;
}

.days {
    padding: 10px 0;
    background: #eee;
    margin: 0;
}

.days li {
    list-style-type: none;
    display: inline-block;
    width: 13.6%;
    text-align: center;
    margin-bottom: 5px;
    font-size:12px;
    color: #777;
}

.days li .active {
    padding: 5px;
    background: #1abc9c;
    color: white !important
}

/* Add media queries for smaller screens */
@media screen and (max-width:720px) {
    .weekdays li, .days li {width: 13.1%;}
}

@media screen and (max-width: 420px) {
    .weekdays li, .days li {width: 12.5%;}
    .days li .active {padding: 2px;}
}

@media screen and (max-width: 290px) {
    .weekdays li, .days li {width: 12.2%;}
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<!--
/**
 * Author: w3schools.com
 * URL: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_calendar
 */
-->

<h1>CSS Calendar</h1>

<div class="month">      
  <ul>
    <li class="prev">&#10094;</li>
    <li class="next">&#10095;</li>
    <li>
      August<br>
      <span style="font-size:18px">2017</span>
    </li>
  </ul>
</div>

<ul class="weekdays">
  <li>Mo</li>
  <li>Tu</li>
  <li>We</li>
  <li>Th</li>
  <li>Fr</li>
  <li>Sa</li>
  <li>Su</li>
</ul>

<ul class="days">  
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li><span class="active">10</span></li>
  <li>11</li>
  <li>12</li>
  <li>13</li>
  <li>14</li>
  <li>15</li>
  <li>16</li>
  <li>17</li>
  <li>18</li>
  <li>19</li>
  <li>20</li>
  <li>21</li>
  <li>22</li>
  <li>23</li>
  <li>24</li>
  <li>25</li>
  <li>26</li>
  <li>27</li>
  <li>28</li>
  <li>29</li>
  <li>30</li>
  <li>31</li>
</ul>

</body>
</html>

因此,我们的想法是首先使用bootstrap + CSS或纯CSS构建日历。

请记住,您还可以使用媒体查询获取屏幕尺寸:

@media (max-width: 768px) { ... }
@media (min-width: 768px)) and (max-width: 992px) { ... }

例如:

/* Small devices (tablets, 768px and up) */
@media (min-width: 768px) { ... }

/* Medium devices (desktops, 992px and up) */
@media (min-width: 992px) { ... }

/* Large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) { ... }