如何设置 jQuery datePicker 日历的样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25474378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:06:53  来源:igfitidea点击:

How to style jQuery datePicker Calendar?

jquerycssjquery-ui-datepicker

提问by Mar

I am trying to use datePicker in a div. I would like expand the height of the div as the datePicker calendar opens..

我正在尝试在 div 中使用 datePicker。我想在 datePicker 日历打开时扩展 div 的高度。

I have a div like that:

我有一个这样的 div:

.dateBox{
    width:160px;
    height:auto;
    border:1px solid blue;
}

The problem is as you click on datePicker input and open calendar, .datebox height doesn't change.. I have been playing around but I couldn't figure it out...

问题是当你点击 datePicker 输入并打开日历时,.datebox 高度没有改变..我一直在玩,但我无法弄清楚......

How can I fix that?

我该如何解决?

Live: http://jsfiddle.net/fcrsznb1/2/

直播:http: //jsfiddle.net/fcrsznb1/2/

Thanx in advance!

提前谢谢!

回答by shobitha dinsan

.ui-datepicker {
    width: 300px;
    height: 300px;
    margin: 5px auto 0;
    font: 12pt Arial, sans-serif;
    /*-webkit-box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, .5);
    -moz-box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, .5);*/
}

    .ui-datepicker table {
        width: 100%;
    }

.ui-datepicker-header {
    background: #3399ff;
    color: #ffffff;
    font-family:'Times New Roman';
    border-width: 1px 0 0 0;
    border-style: solid;
    border-color: #111;
}

.ui-datepicker-title {
    text-align: center;
    font-size: 15px;

}

.ui-datepicker-prev {
    float: left;
    cursor: pointer;
    background-position: center -30px;
}

.ui-datepicker-next {
    float: right;
    cursor: pointer;
    background-position: center 0px;
}

.ui-datepicker thead {
    background-color: #f7f7f7;

    /*border-bottom: 1px solid #bbb;*/
}

.ui-datepicker th {
    background-color:#808080;
    text-transform: uppercase;
    font-size: 8pt;
    color: #666666;
    /*text-shadow: 1px 0px 0px #fff;*/
    /*filter: dropshadow(color=#fff, offx=1, offy=0);*/
}

.ui-datepicker tbody td {
    padding: 0;
    /*border-right: 1px solid #808080;*/
}

    .ui-datepicker tbody td:last-child {
        border-right: 0px;
    }

.ui-datepicker tbody tr {
    border-bottom: 1px solid #bbb;
}

    .ui-datepicker tbody tr:last-child {
        border-bottom: 0px;
    }

.ui-datepicker a {
    text-decoration: none;
}

.ui-datepicker td span, .ui-datepicker td a {
    display: inline-block;
    /*font-weight: bold;*/
    text-align: center;
    width: 30px;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    /*text-shadow: 1px 1px 0px #fff;*/
    /*filter: dropshadow(color=#fff, offx=1, offy=1);*/
}

.ui-datepicker-calendar .ui-state-default {
      background: linear-gradient(#999999, #737373);
      color:#ffffff;
      height:40px;
      width:40px;

}

.ui-datepicker-calendar .ui-state-hover {
    background: #33adff;
    color: #FFFFFF;
}

.ui-datepicker-calendar .ui-state-active {
    background: #33adff;
    -webkit-box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .1);
    -moz-box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .1);
    box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .1);
    color: #e0e0e0;
    text-shadow: 0px 1px 0px #4d7a85;
    border: 1px solid #55838f;
    position: relative;
    margin: -1px;
}

.ui-datepicker-unselectable .ui-state-default {
    background: #D6E4BE;
    color: #000;
}

回答by Digikid13

If you are looking to animate the datebox you can try using:

如果您想为日期框设置动画,您可以尝试使用:

$( "#datepicker1" ).datepicker({ showAnim: "fold" })

You can use any of the effects listed here: http://api.jqueryui.com/category/effects/

您可以使用此处列出的任何效果:http: //api.jqueryui.com/category/effects/

Here's a jsfiddle showing you it working: http://jsfiddle.net/fcrsznb1/3/

这是一个 jsfiddle 向您展示它的工作原理:http: //jsfiddle.net/fcrsznb1/3/

If you are looking to do other things you might want to check out the docs.

如果您想做其他事情,您可能需要查看文档。

http://api.jqueryui.com/datepicker/See if any options will do what you are looking for.

http://api.jqueryui.com/datepicker/看看是否有任何选项可以满足您的需求。

回答by Bob Tate

You will need to reference the datepicker classes themselves and change their styles.

您将需要引用 datepicker 类本身并更改它们的样式。

Instead of using this

而不是使用这个

 .dateBox{
     width:160px;
     height:auto;
    border:1px solid blue;
 }

Change the name to this and see if that is what you were looking for

将名称更改为此,看看这是否是您要找的

 .ui-widget-content{
     width:160px;
     height:auto;
     border:1px solid blue;
 }

回答by Dwipa Arantha

right click on datepicker box. select 'inspect' (Ctrl+Shift+I) in Chrome or 'inspect element (Q)' in firefox. find the css style that you want to change.

右键单击日期选择器框。在 Chrome 中选择“检查”(Ctrl+Shift+I) 或在 Firefox 中选择“检查元素 (Q)”。找到要更改的 css 样式。

example :

例子 :

.ui-datepicker {
font-size: 5%;
}

.ui-widget-header {
background: #77CC6D;
}

.ui-widget-content .ui-state-default:hover{
background: #77CC6D;
border-radius: 2px;
}

to change the date format, change the script

要更改日期格式,请更改脚本

$(document).ready(function() {
$("#datepicker").datepicker({ dateFormat: 'D, d-M-yy' });
});

D > Day
d > date
M > short Month (Jan)
MM > long Month (January)
m > month number (1)
mm > month double number (01)
y > year (17)
yy > year (2017)

D>日
d>日期
M>短月(Jan)
MM>长月(January)
m>月数(1)
mm>月双数(01)
y>年(17)
yy>年(2017)

回答by hardika

Custom CSS for the date picker:

日期选择器的自定义 CSS:

Copy this into your CSS file. check this result black and green datepicker

将其复制到您的 CSS 文件中。检查此结果黑色和绿色日期选择器

/* datepicker css */

.ui-datepicker {
background: #000000; /* Old browsers */
background: #000000 -moz-linear-gradient(top, #fcfcfc 0%, #fff 100%); /* FF3.6+ */
background: #000000 -webkit-gradient(linear, left top, left bottom, color- 
stop(0%,#000000)), color-stop(100%,#34495e); /* Chrome,Safari4+ */
background: #000000 -webkit-linear-gradient(top,#000000 0%, #34495e 100%); /* 
Chrome10+,Safari5.1+ */
background: #000000 -o-linear-gradient(top,#000000 0%, #34495e 100%); /* Opera11.10+ 
*/
background: #000000 -ms-linear-gradient(top,#000000 0%, #34495e 100%); /* IE10+ */
background: #000000 linear-gradient(top,#000000 0%, #34495e 100%); /* W3C */
font-size:11px;
padding:10px;
border:1px solid #5BFEC8;
width: 300px;
}

.ui-datepicker table td {
text-align:center;
}

.ui-datepicker a {
cursor:pointer;
text-decoration:none;
}

.ui-datepicker-prev {
}

.ui-datepicker-next {
float:right;
}

.ui-datepicker-title {
text-align: center;
font-weight:bold;
}

.ui-widget.ui-widget-content{
    border: 2px solid #5BFEC8;
}

.ui-datepicker th {
    padding: .7em .3em;
    text-align: center;
    font-weight: bold;
    border: 0;
    color: #5BFEC8;
}

.ui-state-default,
.ui-widget-content .ui-state-default,
.ui-widget-header .ui-state-default{
    border: 1px solid #5bfec8;
    background: #000000;
    font-weight: normal;
    color: #5bfec8;
}

a.ui-state-default:hover{
    border: 1px solid white;
    background: #5bfec8;
    font-weight: bold;
    color: black;
}

.ui-state-active, .ui-widget-content .ui-state-active,
.ui-widget-header .ui-state-active {
    border: 1px solid white;
    background: #5bfec8;
    font-weight: bold;
    color: black;
}

.ui-state-highlight,
.ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {
    border: 1px solid #dad55e;
    background: #fffa90;
    color: black;
}

.ui-widget-header {
    border: 1px solid #5bfec8;
    background: #080808;
    color: #5bfec8;
    font-weight: bold;
}