简体   繁体   English

Bootstrap面板填充可用宽度

[英]Bootstrap panels fill available width

I am using bootstrap 3 and PHP to display a page where either 1, 2 or 3 panels are displayed side by side depending on the permissions the user has to see those panels (they always have permission to see at least one). 我使用bootstrap 3和PHP来显示一个页面,其中1,2或3个面板并排显示,具体取决于用户查看这些面板的权限(他们总是有权查看至少一个)。

If the user can see all 3 I want them to appear side by side, using 4 grid columns each. 如果用户可以看到所有3个,我希望它们并排显示,每个使用4个网格列。 If they can see two, I want them to fill the available width, ie 6 columns each. 如果他们可以看到两个,我希望他们填充可用的宽度,即每个6列。 Finally one 12 column panel if the user can only see the one panel. 最后一个12列面板如果用户只能看到一个面板。

I thought putting the panels inside container fluid and inside the same div with class 'row', and not specifying how many columns wide they were, might do the trick, but that makes them all appear one on top of the other and taking up the full width of the page. 我认为将面板放在容器流体中并且在同一个div中使用类'row',并且没有指定它们的宽度是多少,可能会做到这一点,但这会使它们全部出现在另一个之上并占用页面的全宽。

How can I achieve the above with bootstrap rather than having to use PHP code to change the number of columns depending on how many panels are being displayed (which I think would be more cumbersome). 如何使用bootstrap实现上述功能,而不是必须使用PHP代码来更改列数,具体取决于显示的面板数量(我认为这将更加繁琐)。

I think that is not possible. 我认为这是不可能的。 Panels are designed in order to fill their container (like blocks elements). 面板的设计是为了填充容器(如块元素)。 Maybe you could apply a display inline-block css property to the panels, but you would need to calculate css widths to apply them to fill entire row... 也许您可以将一个显示内联块css属性应用于面板,但是您需要计算css宽度以应用它们来填充整行...

try this function. 试试这个功能。 it makes block flexible http://www.w3schools.com/cssref/css3_pr_flex.asp 它使块灵活性http://www.w3schools.com/cssref/css3_pr_flex.asp

While I would have liked a simpler CSS approach that required less logic, I found myself agreeing with @Axel and doing it in PHP. 虽然我想要一个更简单的CSS方法,需要更少的逻辑,但我发现自己同意@Axel并在PHP中完成它。

Since there are 3 possible permissions and 3 variables with values 0 or 1 to determine those permissions, I did something like this; 由于有3个可能的权限和3个值为0或1的变量来确定这些权限,我做了类似的事情;

$number_of_panels = $permission1 + $permission2 + $permission3;

switch ($number_of_panels) {
    case 1:
        $panel_width = 12;
        break;
    case 2:
        $panel_width = 6;
        break;
    case 3:
        $panel_width = 4;
        break;
}

And further down; 进一步向下;

<div class="row">
    <?php if ($permission1 == 1) { ?>
    <div class="col-md-<?php echo $panel_width; ?>">

etc... 等等...

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

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