简体   繁体   English

引导程序中模态的动态大小

[英]Dynamic size of a modal in bootstrap

I am a newbie in the field, so I will explain you what I am trying to achieve. 我是该领域的新手,因此我将向您解释我要达到的目标。 In my webpage I want that when a button is pressed, a popup card shows up where I have to fill some information. 在我的网页中,我希望按下按钮时,弹出卡显示在我必须填写一些信息的地方。 I am using bootstrap in my current project. 我在当前项目中使用引导程序。 So what I found so far is the use of a modal. 因此,到目前为止,我发现是使用模态。 So when the card pops up there are some fields to fill (easy strings) and a date to choose. 因此,当卡片弹出时,会有一些字段要填写(简单的字符串)和日期可供选择。 By going to the code so far I have: 通过到目前为止的代码,我得到了:

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-lg btn-warning addButton" data-toggle="modal" data-target="#myModal">New Employee</button>
 <!-- Modal -->
 <div id="myModal" class="modal fade" role="dialog">
        <div class="modal-dialog modal-sm">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">New FRISS employee</h4>
                </div>
                <div class="modal-body">

                    <input type="text" class="form-control insertInfo" placeholder="Name" />
                    <input type="text" class="form-control insertInfo" placeholder="Surname" />
                    <input type="text" class="form-control insertInfo" placeholder="Date of birth" />
                    <input type="text" class="form-control insertInfo" placeholder="Role" />
                    <input type="text" class="form-control insertInfo" placeholder="Email address" />



                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Done</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>

        </div>
    </div>

The first problem at this point is that I would like to modify the width of the modal (which is too big). 此时的第一个问题是,我想修改模态的宽度(太大)。 Afterwards I don't want a string as a date but a date picker and again I found through bootstrap this snippet of code: 之后,我不希望将字符串作为日期,而是将日期选择器用作日期,然后再次通过引导程序找到了以下代码片段:

<div class="container">
    <div class="row">
        <div class='col-sm-6'>
            <div class="form-group">
                <div class='input-group date' id='datetimepicker1'>
                    <input type='text' class="form-control" />
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $(function () {
                $('#datetimepicker1').datetimepicker();
            });
        </script>
    </div>
</div>

Unfortunately if I use it, everything in the modal gets mixed without anymore an order and I don't manage to keep everything clean and ordered. 不幸的是,如果我使用它,则模态中的所有内容都会混合在一起,而不再需要任何命令,并且我无法保持所有内容的整洁有序。 Can you please help me? 你能帮我么? Thanks in advance 提前致谢

Either you have not added in the datepicker css cdn links in or I think you are copying and pasting the whole datepicker code in place of the date of birth input. 您可能没有在datepicker css cdn链接中添加任何内容,或者我认为您是在复制和粘贴整个datepicker代码以代替出生日期输入。

You dont need to copy the whole code with the container div just the code from the 您不需要使用容器div复制整个代码,只需复制容器中的代码即可。

<div class='input-group date' id='datetimepicker1'>

Also make sure you have added in the datetimepicker css and js file links in your head tag. 还要确保已在head标签中添加了datetimepicker css和js文件链接。

Here is as example using your code. 这是使用您的代码的示例。 Do check the link and script tags at the top and put them in your code in the exact same order. 请检查顶部的链接和脚本标记,并以完全相同的顺序将它们放入代码中。

http://codepen.io/Nasir_T/pen/ALNkaK http://codepen.io/Nasir_T/pen/ALNkaK

Also to customize the width of the modal div. 还可以自定义模态div的宽度。 Just add the default bootstrap .modal-content { class in your custom css file or this page and add the width property to customize it. 只需在自定义css文件或此页面中添加默认的bootstrap .modal-content {类,然后添加width属性即可对其进行自定义。

Hope this helps. 希望这可以帮助。

[Edit] [编辑]

On your spacing request in comments: What you needed to do is pick the whole container of each control and apply margin to it's top and bottom only. 在您的间距请求中添加注释:您需要做的是拾取每个控件的整个容器,并在其顶部和底部仅应用边距。 In this case you already had the insertInfo class added in the inputs so just add the following class in your css file. 在这种情况下,您已经在输入中添加了insertInfo类,因此只需在css文件中添加以下类。

.insertInfo {
  margin: 10px 0;
}

Also add this class in the datepicker div in the modal code as that is separate from the input and we need to apply to the whole datetimepicker row instead of just the input in it so 还要在模态代码中的datepicker div中添加此类,因为它与输入是分开的,我们需要应用到整个datetimepicker行,而不只是应用于其中的输入,因此

<div class='input-group date insertInfo' id='datetimepicker1'>

I have also updated the codepen link so you can check it working there. 我还更新了Codepen链接,以便您可以检查它在那儿的运行情况。 Happy coding :) 快乐的编码:)

just add id="datetimepicker1" to your input field 只需将id =“ datetimepicker1”添加到您的输入字段

and add this java script code at the end of the page 并在页面末尾添加此Java脚本代码

<script>
$(document).ready(function () { 
    $('#datetimepicker1').datetimepicker(
    { 
            autoclose: true,
            //startDate : today,
            //endDate:today,
            format: "mm-dd-yyyy",
            minView:2
     })
        .on('click', function (e) {  
             setTimeout(function () {
                 $('#datetimepicker1').focus();
             }, 10);
        });           
})
</script>

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

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