简体   繁体   English

Bootstrap中的列宽

[英]Column width in Bootstrap

Please bear with me if this is a simple question (I'm an iOS developer trying to learn CSS-Bootstrap. 如果这是一个简单的问题,请多多包涵(我是一名iOS开发人员,正在尝试学习CSS-Bootstrap。

I first played with rows : 我首先玩行:

     <div class="row">
         <div class="col col-1">
          <p>Plan</p>
        </div>  
        <div class="col col-2">
          <p>Date</p>
        </div>
        <div class="col col-2">
          <p>Person</p>
        </div>
         <div class="col col-3">
          <p>Description</p>
        </div>  
        <div class="col col-1">
          <p>Time</p>
        </div>
        <div class="col col-3">
          <p>Line</p>
        </div>
      </div>

And this was perfect : 这是完美的: 在此处输入图片说明

I then tried to do the same with tables, first without setting the columns for the grid : 然后,我尝试对表执行相同操作,首先不设置网格的列:

    <div class="container-fluid">
        <table class="table">
            <thead>
                <tr>
                    <th">Plan</th>
                    <th">Date</th>
                    <th>Person</th>
                    <th>Description</th>
                    <th>Time</th>
                    <th>Line</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td> <input type="checkbox" name="Plan"> </td>
                    <td> <input type="date" name="date"> </td>
                    <td> <input type="text"></td>
                    <td> <input type="text"></td>
                    <td> <input type="time"></td>
                    <td> <input type="text"></td>
                </tr>
                     <tr>
                    <td> <input type="checkbox" name="Plan"> </td>
                    <td> <input type="date" name="date"> </td>
                    <td> <input type="text"></td>
                    <td> <input type="text"></td>
                    <td> <input type="time"></td>
                    <td> <input type="text"></td>

            </tbody>
        </table>
    </div>

在此处输入图片说明

Not bad but I want some columns to be smaller (Plan, Time, Date) and others to be bigger. 不错,但我希望某些列较小(计划,时间,日期),而另一些则较大。 So I added the classes for those columns (just like I did when experimenting with rows : 因此,我为这些列添加了类(就像我在尝试行时所做的那样:

<div class="container-fluid">
            <table class="table">
                <thead>
                    <tr>
                        <th class="col col-1">Plan</th>
                        <th class="col col-2">Date</th>
                        <th class="col col-2">Person</th>
                        <th class="col col-3">Description</th>
                        <th class="col col-1">Time</th>
                        <th class="col col-3">Line</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="col col-1"> <input type="checkbox" name="Plan"> </td>
                        <td class="col col-2"> <input type="date" name="date"> </td>
                        <td class="col col-2"> <input type="text"></td>
                        <td class="col col-3"> <input type="text"></td>
                        <td class="col col-1"> <input type="time"></td>
                        <td class="col col-3"> <input type="text"></td>
                    </tr>
                         <tr>
                        <td  class="col col-1"> <input type="checkbox" name="Plan"> </td>
                        <td class="col col-2"> <input type="date" name="date"> </td>
                        <td class="col col-2"> <input type="text"></td>
                        <td class="col col-3"> <input type="text"></td>
                        <td class="col col-1"> <input type="time"></td>
                        <td class="col col-3"> <input type="text"></td>

                </tbody>
            </table>
        </div>

But to my surprise. 但令我惊讶的是。 The first column (Plan) was lot bigger (and not smaller) and the other all remained the same: 第一列(计划)更大(而不是更小),其他都保持不变: 在此处输入图片说明

I tried with setting the in both header and body (like code above) and only in header. 我尝试在标头和主体(如上面的代码)中都设置了并且仅在标头中设置了。 The result was the same. 结果是一样的。

First things first, the first table item (Plan) is much larger when you are using columns because of "container-fluid". 首先,由于使用“容器流体”,因此在使用列时,第一个表项目(计划)要大得多。 Try just "container". 尝试仅“容器”。 Per the documentation, "container-fluid" is full width which means it is expanding to fill the screen. 根据文档,“容器流体”为全宽,这意味着它正在扩展以填充屏幕。

Next, columns are not what you would need to make the table items widths smaller. 接下来,列不是使表格项目的宽度变小所需要的。

在此处输入图片说明

The top layout is with column classes with the table. 顶部布局是表的列类。 The bottom layout is a standard table layout with no column classes. 底部布局是没有列类的标准表布局。 As you can see, the smallest possible column width (col-1) is larger than the default sizing for the table items. 如您所见,最小的列宽(col-1)大于表项目的默认大小。 If you want something to be smaller than that (the default sizing for the table), then you will have to mess around with the sizing of the table itself. 如果您想要的东西小于该值(表的默认大小),那么您将不得不弄乱表本身的大小。 (setting the padding-right or padding-left to 0rem for specific td elements helps trim the excess spacing for example) (例如,将特定td元素的padding-right或padding-left设置为0rem有助于修剪多余的间距)

my code for the "columned" table: 我的“列”表代码:

<div class="container">
    <table class="table">
        <thead>
            <tr>
                <th class="col-xl-1">Plan</th>
                <th class="col-xl-2">Date</th>
                <th class="col-xl-2">Person</th>
                <th class="col-xl-3">Description</th>
                <th class="col-xl-1">Time</th>
                <th class="col-xl-3">Line</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="col-xl-1"> <input type="checkbox" name="Plan"></td>      
                <td class="col-xl-2"> <input type="date" name="date"> </td>
                <td class="col-xl-2"> <input type="text"></td>
                <td class="col-xl-3"> <input type="text"></td>
                <td class="col-xl-1"> <input type="time"></td>
                <td class="col-xl-3"> <input type="text"></td>
            </tr>
            <tr>
                 <td  class="col-xl-1"> <input type="checkbox" name="Plan"> </td>
                 <td class="col-xl-2"> <input type="date" name="date"> </td>
                 <td class="col-xl-2"> <input type="text"></td>
                 <td class="col-xl-3"> <input type="text"></td>
                 <td class="col-xl-1"> <input type="time"></td>
                 <td class="col-xl-3"> <input type="text"></td>
        </tbody>
    </table>
</div>

By the way I am using bootstrap version 4 alpha 6. If you are on a lower version of bootstrap, replace all instances of "col-xl-#" with "col-lg-#". 顺便说一句,我正在使用引导程序版本4 alpha6。如果您使用的引导程序版本较低,则将所有“ col-xl-#”实例替换为“ col-lg-#”。 The newest bootstrap has xl as its largest size. 最新的引导程序的最大大小为xl。

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

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