简体   繁体   English

jQuery UI-Datepicker:月和年下拉CSS

[英]jQuery ui - datepicker: month and year dropdown css

Problem Question: I have a jQuery datepicker with month and year dropdown, when there are month like may,june css between month and year looks bad. 问题问题:我有一个带有月份和年份下拉列表的jQuery datepicker,当可能有月份时may,june月份和年份之间的may,june CSS看起来很糟糕。 Something like December 2016 and May 2016 December 2016 May 2016 December 2016May 2016 December 2016 May 2016

I have created the fiddle for this https://jsfiddle.net/GeekOnGadgets/wra3pcsv/ 我为此https://jsfiddle.net/GeekOnGadgets/wra3pcsv/创建了小提琴

What I am trying to achieve: I want month and year to have fixed margin between them. 我想要达到的目标:我希望月份和年份之间保持固定的利润。 Something like December 2016 and May 2016 December 2016 May 2016 December 2016May 2016 December 2016 May 2016

Month and Year in the Datepicker are actually select menus, and by default the width of that menu (if unspecified) is the width of the largest option it holds, so you'll need to implement some javascript if you want to adjust the width of the select menu according to the selected option. Datepicker中的Month和Year实际上是选择菜单,并且默认情况下,该菜单的宽度(如果未指定)是它拥有的最大选项的宽度,因此,如果要调整的宽度,则需要实现一些JavaScript根据所选选项选择菜单。 There's a very good example of how to do that in the accepted answer of this post: 在这篇文章的公认答案中,有一个很好的例子说明了如何做到这一点:

Auto resizing the SELECT element according to selected OPTION's width 根据所选OPTION的宽度自动调整SELECT元素的大小

Unfortunately you can't directly get the width of the selected option. 不幸的是,您无法直接获得所选选项的宽度。 So in the solution referenced, a hidden select element with only that option is created and it's width is measured, then the actual select element is set to that width. 因此,在引用的解决方案中,将创建仅包含该选项的隐藏选择元素,并测量其宽度,然后将实际选择元素设置为该宽度。 A clever solution. 一个聪明的解决方案。

Add the following snippet into the CSS: 将以下代码段添加到CSS中:

.ui-datepicker-month {
  text-align-last: right;
  padding-right: .25em;
}

Related: Is it possible to center text in select box? 相关: 是否可以在选择框中将文本居中?

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

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