草庐IT

javascript - 如何更改 Bootstrap 内联日期选择器以适应全宽

coder 2025-02-22 原文

我在这里使用 Bootstrap 日期选择器:https://github.com/eternicode/bootstrap-datepicker

现在我想用父容器调整它的宽度,但目前它只填充一个固定大小,我不知道在哪里可以通过 CSS 更改它。也许您之前遇到过类似的问题并愿意帮助我?

我附上了问题的图片: http://i.stack.imgur.com/ShZTU.png

下面是通过 JavaScript 添加日期选择器功能之前的代码:

<div class="col-sm-4">';
<div class="panel panel-success panel-dark widget-profile ">
    <div class="panel-heading">
        <div class="widget-profile-bg-icon">
            <i class="fa fa-flask"></i>
        </div>
        <img src="assets/demo/avatars/2.jpg" alt="" class="widget-profile-avatar">
            <div class="widget-profile-header">
                <span>Robert Jang</span>
                <br>
                        email@example.com
                </div>
            </div>
            <!-- / .panel-heading -->
            <div id="bs-datepicker-inline"></div>
        </div>
    </div>

然后我使用这段 JavaScript 代码添加日期选择器功能:

 jQuery('#bs-datepicker-inline').datepicker();

在这之后我的最终源代码如下所示:

<div class="col-sm-4">
<div class="panel panel-success panel-dark widget-profile ">
    <div class="panel-heading">
        <div class="widget-profile-bg-icon">
            <i class="fa fa-flask"></i>
        </div>
        <img src="assets/demo/avatars/2.jpg" alt="" class="widget-profile-avatar">
            <div class="widget-profile-header">
                <span>Robert Jang</span>
                <br>
                        email@example.com

                </div>
            </div>
            <!-- / .panel-heading -->
            <div id="bs-datepicker-inline">
                <div class="datepicker datepicker-inline">
                    <div class="datepicker-days" style="display: block;">
                        <table class=" table-condensed">
                            <thead>
                                <tr>
                                    <th class="prev" style="visibility: visible;">«</th>
                                    <th colspan="5" class="datepicker-switch">February 2015</th>
                                    <th class="next" style="visibility: visible;">»</th>
                                </tr>
                                <tr>
                                    <th class="dow">Su</th>
                                    <th class="dow">Mo</th>
                                    <th class="dow">Tu</th>
                                    <th class="dow">We</th>
                                    <th class="dow">Th</th>
                                    <th class="dow">Fr</th>
                                    <th class="dow">Sa</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="day old">25</td>
                                    <td class="day old">26</td>
                                    <td class="day old">27</td>
                                    <td class="day old">28</td>
                                    <td class="day old">29</td>
                                    <td class="day old">30</td>
                                    <td class="day old">31</td>
                                </tr>
                                <tr>
                                    <td class="day">1</td>
                                    <td class="day">2</td>
                                    <td class="day">3</td>
                                    <td class="day">4</td>
                                    <td class="day">5</td>
                                    <td class="day">6</td>
                                    <td class="day">7</td>
                                </tr>
                                <tr>
                                    <td class="day">8</td>
                                    <td class="day">9</td>
                                    <td class="day">10</td>
                                    <td class="day">11</td>
                                    <td class="day">12</td>
                                    <td class="day">13</td>
                                    <td class="day">14</td>
                                </tr>
                                <tr>
                                    <td class="day">15</td>
                                    <td class="day">16</td>
                                    <td class="day">17</td>
                                    <td class="day">18</td>
                                    <td class="day">19</td>
                                    <td class="day">20</td>
                                    <td class="day">21</td>
                                </tr>
                                <tr>
                                    <td class="day">22</td>
                                    <td class="day">23</td>
                                    <td class="day">24</td>
                                    <td class="day">25</td>
                                    <td class="day">26</td>
                                    <td class="day">27</td>
                                    <td class="day">28</td>
                                </tr>
                                <tr>
                                    <td class="day new">1</td>
                                    <td class="day new">2</td>
                                    <td class="day new">3</td>
                                    <td class="day new">4</td>
                                    <td class="day new">5</td>
                                    <td class="day new">6</td>
                                    <td class="day new">7</td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th colspan="7" class="today" style="display: none;">Today</th>
                                </tr>
                                <tr>
                                    <th colspan="7" class="clear" style="display: none;">Clear</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="datepicker-months" style="display: none;">
                        <table class="table-condensed">
                            <thead>
                                <tr>
                                    <th class="prev" style="visibility: visible;">«</th>
                                    <th colspan="5" class="datepicker-switch">2015</th>
                                    <th class="next" style="visibility: visible;">»</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="7">
                                        <span class="month">Jan</span>
                                        <span class="month">Feb</span>
                                        <span class="month">Mar</span>
                                        <span class="month">Apr</span>
                                        <span class="month">May</span>
                                        <span class="month">Jun</span>
                                        <span class="month">Jul</span>
                                        <span class="month">Aug</span>
                                        <span class="month">Sep</span>
                                        <span class="month">Oct</span>
                                        <span class="month">Nov</span>
                                        <span class="month">Dec</span>
                                    </td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th colspan="7" class="today" style="display: none;">Today</th>
                                </tr>
                                <tr>
                                    <th colspan="7" class="clear" style="display: none;">Clear</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="datepicker-years" style="display: none;">
                        <table class="table-condensed">
                            <thead>
                                <tr>
                                    <th class="prev" style="visibility: visible;">«</th>
                                    <th colspan="5" class="datepicker-switch">2010-2019</th>
                                    <th class="next" style="visibility: visible;">»</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="7">
                                        <span class="year old">2009</span>
                                        <span class="year">2010</span>
                                        <span class="year">2011</span>
                                        <span class="year">2012</span>
                                        <span class="year">2013</span>
                                        <span class="year">2014</span>
                                        <span class="year">2015</span>
                                        <span class="year">2016</span>
                                        <span class="year">2017</span>
                                        <span class="year">2018</span>
                                        <span class="year">2019</span>
                                        <span class="year new">2020</span>
                                    </td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th colspan="7" class="today" style="display: none;">Today</th>
                                </tr>
                                <tr>
                                    <th colspan="7" class="clear" style="display: none;">Clear</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

我希望有人能帮助我。如果您需要更多信息,请告诉我。

非常感谢。

编辑 1:

这是日期选择器的 CSS 代码

.datepicker {
  direction: ltr;
  padding: 0;
  width: auto !important;
}
.datepicker.datepicker-inline {
  border: 1px solid #eee;
  display: inline-block;
  position: relative;
}
.datepicker > div {
  display: none;
}
.datepicker.days div.datepicker-days,
.datepicker.months div.datepicker-months,
.datepicker.years div.datepicker-years {
  display: block;
}
.datepicker div.datepicker-months td,
.datepicker div.datepicker-years td {
  width: 210px !important;
}
.datepicker table {
  margin: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.datepicker td {
  line-height: 32px;
  padding: 0 !important;
  text-align: center;
  width: 30px;
}
.table-striped .datepicker table tr td,
.table-striped .datepicker table tr th {
  background-color: transparent;
}
.datepicker table tr td {
  border-bottom: 1px solid #eee;
  border-right: 1px solid #eee;
}
.datepicker table tr td:last-child {
  border-right: none;
}
.datepicker table tr td.day:hover {
  background: #f3f3f3;
  cursor: pointer;
  position: relative;
}
.datepicker table tr td.old,
.datepicker table tr td.new {
  color: #bbb;
}
.datepicker table tr td.disabled,
.datepicker table tr td.disabled:hover {
  background: none;
  color: #eee;
  cursor: default;
}
.datepicker table tr td.today,
.datepicker table tr td.today:hover,
.datepicker table tr td.today.disabled,
.datepicker table tr td.today.disabled:hover {
  background: #f3f3f3;
  font-weight: 700 !important;
}
.datepicker table tr td.today:hover:hover {
  color: #555555;
}
.datepicker table tr td.today.active:hover {
  color: #fff;
}
.datepicker table tr td.range,
.datepicker table tr td.range:hover,
.datepicker table tr td.range.disabled,
.datepicker table tr td.range.disabled:hover {
  background: #f3f3f3;
}
.datepicker table tr td.range.today,
.datepicker table tr td.range.today:hover,
.datepicker table tr td.range.today.disabled,
.datepicker table tr td.range.today.disabled:hover {
  background: #f3f3f3;
  font-weight: 700;
}
.datepicker table tr td.selected,
.datepicker table tr td.selected:hover,
.datepicker table tr td.selected.disabled,
.datepicker table tr td.selected.disabled:hover {
  color: #fff !important;
}
.datepicker table tr td.active,
.datepicker table tr td.active:hover,
.datepicker table tr td.active.disabled,
.datepicker table tr td.active.disabled:hover {
  color: #fff !important;
}
.datepicker table tr td span {
  border-radius: 2px;
  cursor: pointer;
  display: block;
  float: left;
  line-height: 54px;
  margin: 1%;
  width: 23%;
}
.datepicker table tr td span:hover {
  background: #eee;
}
.datepicker table tr td span.disabled,
.datepicker table tr td span.disabled:hover {
  background: none;
  color: #eee;
  cursor: default;
}
.datepicker table tr td span.active,
.datepicker table tr td span.active:hover,
.datepicker table tr td span.active.disabled,
.datepicker table tr td span.active.disabled:hover {
  color: #fff !important;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.datepicker table tr td span.old,
.datepicker table tr td span.new {
  color: #eee;
}
.datepicker thead tr:first-child th,
.datepicker tfoot tr th {
  cursor: pointer;
}
.datepicker th,
.datepicker td,
.datepicker tr {
  border-top: none !important;
  text-align: center !important;
}
.datepicker thead th,
.datepicker tfoot th {
  font-weight: 600;
  padding: 0 !important;
}
.datepicker thead th {
  border-bottom: none !important;
  color: #fff;
  font-weight: 600;
  line-height: 35px !important;
  height: 35px !important;
  padding: 0 !important;
  text-align: center;
}
.datepicker thead tr:first-child {
  border-bottom: 1px solid !important;
}
.datepicker thead tr:first-child th:hover {
  background: rgba(255, 255, 255, 0.2);
}
.datepicker thead tr:last-child {
  border-bottom: none !important;
}
.datepicker thead th.prev,
.datepicker thead th.next {
  color: rgba(0, 0, 0, 0);
  display: block;
  font-size: 0;
  line-height: 0;
  position: absolute;
  width: 36px !important;
}
.datepicker thead th.prev:after,
.datepicker thead th.next:after {
  bottom: 0;
  color: #fff;
  display: block;
  font-family: FontAwesome;
  font-size: 14px;
  font-weight: normal;
  left: 0;
  line-height: 35px;
  position: absolute;
  right: 0;
  text-align: center;
  top: 0;
  width: 36px;
}
.datepicker thead th.prev {
  left: 0;
  border-right: 1px solid;
}
.datepicker thead th.prev:after {
  content: "\f053";
}
.datepicker thead th.next {
  border-left: 1px solid;
  right: 0;
}
.datepicker thead th.next:after {
  content: "\f054";
}
.datepicker tfoot th:hover {
  background: #eee;
}
.datepicker tbody td,
.datepicker tfoot th {
  line-height: 32px !important;
}
.datepicker > .datepicker-days tbody .cw {
  background: #f8f8f8 !important;
  color: #aaa;
  font-size: 8px;
  font-weight: 600;
}
.datepicker > .datepicker-days thead tr:first-child th.cw {
  background-color: transparent;
  cursor: default;
}
.datepicker > .datepicker-days thead tr:first-child th.cw + .prev {
  left: 30px;
  border-left: 1px solid;
}
.datepicker > .datepicker-days thead tr:last-child th.cw + th {
  border-left: 1px solid;
}

最佳答案

这对我有用:

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

关于javascript - 如何更改 Bootstrap 内联日期选择器以适应全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28627794/

有关javascript - 如何更改 Bootstrap 内联日期选择器以适应全宽的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby-on-rails - Ruby on Rails 迁移,将表更改为 MyISAM - 2

    如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设

  4. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  5. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  6. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  7. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

  8. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  9. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  10. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

随机推荐