简体   繁体   English

jQuery UI-无法设置多个DatePicker元素的样式

[英]jQuery UI - Unable to style several DatePicker elements

I'm using jQuery UI DatePicker widget and customizing by my own style. 我正在使用jQuery UI DatePicker小部件并通过自己的样式进行自定义。 Since this is not really an open source I'm having troubles styling the title of the date picker: 由于这并不是真正的开源,所以我在设置日期选择器标题时遇到了麻烦:

1. Currently the title shows the full month name with a capital letter, how do I make it all capital? 1.当前标题显示的是全月名称,并带有大写字母,如何将其全部大写?
2. It uses two png arrows to draw the next and previous signs. 2.它使用两个png箭头绘制nextprevious符号。 I just want to replace it with < and > as a plain text, not another png element. 我只想用<>替换为纯文本,而不是另一个png元素。
3. It seems next and previous are stand-alone elements, unrelated to the month name and year, this means whenever I resize the window these elements remain static while the calendar always stays in the middle of the page. 3. nextprevious似乎是独立元素,与月份名称和年份无关,这意味着每当我调整窗口大小时,这些元素将保持静态,而日历始终位于页面中间。 How do I align them on the right and left sides of the month and year text? 如何在月和年文本的右侧和左侧对齐它们?

EDIT 编辑
4. How can I transform the year to show only the last two digits? 4.如何转换年份以仅显示最后两位数字? from 2015 --> 15. 从2015年开始-> 15。

Fiddle 小提琴

CSS: CSS:

/* picker width and position*/
.ui-datepicker{
    position: relative;
    margin: 50px auto 0;
    font-size: 20px;
}

/*eliminate the underline of a tags*/
.ui-datepicker a{
    text-decoration: none;
}


.ui-datepicker table {
    position: relative;
    margin: 0 auto;
    width: 900px;
    height: 500px;
    text-align: center;
    border-collapse: collapse; /*remove double border*/
}

/*header*/

.ui-datepicker-title {
    position: relative;
    margin: 0 auto;
    width: 100px;
    left: -335px;
    margin-bottom: 30px;
}

/*the arrows definition*/
.ui-datepicker-prev, .ui-datepicker-next {
    display: inline-block;
    width: 30px;
    height: 30px;
    text-align: center;
    cursor: pointer;
    background-image: url('../img/arrow.png');
    background-repeat: no-repeat;
    font-size: 10px;
    position: absolute;
    overflow: hidden;
}

/*the arrows position*/
.ui-datepicker-prev {
    position:relative;
    left: 50px;

}
.ui-datepicker-next {
    position: relative;
     left: 350px;
}

/*days names treatment*/

.ui-datepicker th {
    padding: 5px 0;
    color: #666666;
    font-size: 15px;
}

.ui-datepicker td span, .ui-datepicker td a {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    color: #666666;
    position: relative;
    bottom: 15px;
    left: 30px;
    font-size: 15px;
}


/*unselectable*/
.ui-datepicker-unselectable .ui-state-default {
    font-weight: 500;
    color: lightgrey;    

}

/*hover*/
.ui-datepicker-calendar .ui-state-hover {
    background: #f7f7f7;
    border-radius: 100px;
}

jQuery: jQuery的:

$(function(){
        $('#datepicker').datepicker({
//            beforeShowDay: $.datepicker.noWeekends,
            inline: true,
            showOtherMonths: true,
            dayNamesMin: ['Sunday', 'Monday', 'Tuesday', 'Wednsday', 'Thursday', 'Friday', 'Saturday'],
        });
    });

HTML: HTML:

<div id="datepicker"></div>

EDIT2 编辑2
This is what the title should look like (only with different arrows): 标题应如下所示(仅带有不同的箭头): 在此处输入图片说明

To make the Title Uppercase, add 要使标题大写,请添加

text-transform: uppercase;

to .ui-datepicker-title in your CSS . CSS .ui-datepicker-title

To change the png images, 要更改png图像,

remove 去掉

background-image: url('../img/arrow.png');
background-repeat: no-repeat;

from .ui-datepicker-prev, .ui-datepicker-next in your CSS 来自CSS .ui-datepicker-prev, .ui-datepicker-next

To set the < and > as previous and next text, use nextText and prevText as config options. 要将<>设置为上一个和下一个文本,请使用nextTextprevText作为配置选项。

And for the last question, i think you have some problem with the CSS. 对于最后一个问题,我认为您在CSS上存在一些问题。 Check it once more, as such a problem never happens with the default one. 再次检查,因为默认问题永远不会发生。

To show the last two digits only, in your config please add 要仅显示最后两位数字,请在您的配置中添加

dateFormat: "dd-mm-y"

eg: 例如:

$('#startDate').datepicker({
        dateFormat: "dd-mm-y"
    }) 

jsfiddle jsfiddle

The changes in code: 代码更改:

.ui-icon, .ui-icon-circle-triangle-w, .ui-datepicker-prev, .ui-datepicker-next {
    background-image: none !important;
}
.ui-datepicker-prev:after {
    content: '\003c';
}
.ui-datepicker-next:after {
    content: '\003e';
}

As for your last request, i'm not sure what you mean as the calendar renders on the entire page. 至于您的最后一个请求,我不确定您的意思,因为日历会在整个页面上呈现。

  1. .ui-datepicker-title { text-transform: uppercase; }
  2. Set nextText and prevText . 设置nextTextprevText See: http://api.jqueryui.com/datepicker/#option-nextText 请参阅: http//api.jqueryui.com/datepicker/#option-nextText
  3. I'm not sure what you mean here. 我不确定你在这里是什么意思。 They should already be on the left and right sides and should respond to resizing the calendar. 它们应该已经在左侧和右侧,并且应该响应调整日历的大小。 Post a specific example that illustrates your problem. 发布一个具体的示例来说明您的问题。

Here's an updated Fiddle: https://jsfiddle.net/rmk3f010/3/ 这是更新的小提琴: https : //jsfiddle.net/rmk3f010/3/

As already mentioned: 如前所述:

For uppercase title: 对于大写标题:

.ui-datepicker-title {
    text-transform: uppercase;
}

For textual arrows: 对于文本箭头:

nextText: '>',
prevText: '<',

And finally for the alignment: 最后是对齐:

.ui-datepicker-prev {
    float: left;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM