如何使用jQuery和CSS3创建日历

来源:互联网 发布:linux可视化调试工具 编辑:程序博客网 时间:2024/05/02 02:53
在本教程中,我们将编写jQuery和CSS3的日历
第1步 - HTML标记
要创建的日历,我们只需要添加一个ID的div标签。
<div id="calendar"></div>
然后前体结束标记 我们需要添加的jQuery和jQuery UI的脚本。
我们还需要调用“选择器”,所以你需要使用相同的ID,你的div。我们还将添加一些选项:内嵌日历可见,所以我们并不需要点击一个按钮或输入“星期一”的日历上,我们需要将其设置为1的第一天,“秀其他月份将添加其他几个月天,以填补所有表。欲了解更多有关所有可用的选项的详细信息,阅读的文档。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/jquery-ui-datepicker.min.js"></script>
<script>
    $('#calendar').datepicker({
        inline: true,
        firstDay: 1,
        showOtherMonths: true,
        dayNamesMin: ['Sun''Mon''Tue''Wed''Thu''Fri''Sat']
    });
</script>

第2步 - CSS
 
让我们开始通过消除所有的边缘,填充,边界等
.ui-datepicker,
.ui-datepicker table,
.ui-datepicker tr,
.ui-datepicker td,
.ui-datepicker th {
    margin: 0;
    padding: 0;
    border: none;
    border-spacing: 0;
}
然后我们将风格的日历容器。让我们添加背景颜色,圆角和阴影。我们也将改变文本字体为“宋体”和文字的大小。
.ui-datepicker {
    displaynone;
    width294px;
    padding35px;
    cursordefault;
 
    text-transformuppercase;
    font-familyTahoma;
    font-size12px;
 
    background#141517;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    -webkit-box-shadow: 0px 1px 1px rgba(255,255,255, .1), inset 0px 1px 1px rgb(0,0,0);
    -moz-box-shadow: 0px 1px 1px rgba(255,255,255, .1), inset 0px 1px 1px rgb(0,0,0);
    box-shadow: 0px 1px 1px rgba(255,255,255, .1), inset 0px 1px 1px rgb(0,0,0);
}

步骤3 - 标题
风格的日历头(年份和月份),我们将改变文本颜色,添加边框底部和一些更基本的样式。
.ui-datepicker-header {
    position: relative;
    padding-bottom: 10px;
    border-bottom: 1px solid #d6d6d6;
}
.ui-datepicker-title { text-align: center; }
.ui-datepicker-month {
    position: relative;
    padding-right: 15px;
    color: #565656;
}
.ui-datepicker-year {
    padding-left: 8px;
    color: #a8a8a8;
}
添加绿色圆圈,我们将使用:before伪选择。这将使我们之前插入内容“一个月”的元素,那么我们将风格和定位。
.ui-datepicker-month:before {
    displayblock;
    positionabsolute;
    top5px;
    right0;
    width5px;
    height5px;
    content'';
    background#a5cd4e;
    background: -moz-linear-gradient(top#a5cd4e 0%#6b8f1a 100%);
    background: -webkit-gradient(linear, left topleft bottom, color-stop(0%,#a5cd4e), color-stop(100%,#6b8f1a));
    background: -webkit-linear-gradient(top#a5cd4e 0%,#6b8f1a 100%);
    background: -o-linear-gradient(top#a5cd4e 0%,#6b8f1a 100%);
    background: -ms-linear-gradient(top#a5cd4e 0%,#6b8f1a 100%);
    background: linear-gradient(top#a5cd4e 0%,#6b8f1a 100%);
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}

步骤4 - 上一页下一页月
我们将使用一个背景图像风格的未来和以前的箭头,然后我们将定位在右边左边以前和未来。
.ui-datepicker-prev,
.ui-datepicker-next {
    positionabsolute;
    top-2px;
    padding5px;
    cursorpointer;
}
.ui-datepicker-prev {
    left0;
    padding-left0;
} 
.ui-datepicker-next {
    right0;
    padding-right0;
}
.ui-datepicker-prev span,
.ui-datepicker-next span{
    displayblock;
    width5px;
    height10px;
    text-indent-9999px;
    background-imageurl(../img/arrows.png);
}
.ui-datepicker-prev span { background-position0px 0px; }
.ui-datepicker-next span { background-position-5px 0px; }
.ui-datepicker-prev-hover span { background-position0px -10px; }
.ui-datepicker-next-hover span { background-position-5px -10px; }

第5步 - 日历样式
风格一周的日子,我们将添加一个顶部和底部填充,改变颜色。
.ui-datepicker-calendar th {
    padding-top15px;
    padding-bottom10px;
    text-aligncenter;
    font-weightnormal;
    color#a8a8a8;
}
然后我们将加入一些填充,改变颜色,我们将添加一个透明边框,每个数字式的“天格”。这是必要的,因为我们将添加一个边境活动的数量,所以要避免它跳,当我们点击一个数字,我们需要添加这个透明边框。
.ui-datepicker-calendar td {
    padding: 0 7px;
    text-align: center;
    line-height: 26px;
}
.ui-datepicker-calendar .ui-state-default {
    display: block;
    width: 26px;
    outline: none;
    text-decoration: none;
    color: #a8a8a8;
    border: 1px solid transparent;
}
为活跃状态,我们将改变文本和边框颜色为绿色。对于其他月份的“天”,我们会改变颜色较暗。
.ui-datepicker-calendar .ui-state-active {
    color#6a9113;
    border1px solid #6a9113;
}
.ui-datepicker-other-month .ui-state-default color#565656; }

完原文地址:http://www.software8.co/wzjs/cssdiv/311.html
原创粉丝点击