简体   繁体   English

根据同级div的可用性调整div的宽度

[英]resize the width of the div based on sibling div availability

I have 2 divs on a same row. 我在同一行上有2个div。 When the div2 which is on right is removed I want the div1 on left to take full width. 当右边的div2被删除时,我希望左边的div1占据全角。

<div class="row">
    <div class="col-sm-6" style="background-color:lavender;">Div1/div>
    <div class="col-sm-6" style="background-color:lavenderblush;">Div2</div>
  </div>

I am using bootstrap for grid and resposivity. 我正在使用引导程序来实现网格和响应性。 Is there any way I could achieve it with bootstrap? 我有什么办法可以通过Bootstrap实现它吗?

You could write a css selector that sets the width of col-sm-6 to be 100% it is both the first-child and last-child 您可以编写一个CSS选择器,将col-sm-6的宽度设置为100%,它既是第一个孩子又是最后一个孩子

.row .col-sm-6:first-child:last-child {
    width:100%
}

If you are using bootstrap4, then you can skip the column size declaration and instead just do. 如果您正在使用bootstrap4,则可以跳过列大小声明,而只是这样做。

<div class="row">
    <div class="col-sm" style="background-color:lavender;">Div1/div>
    <div class="col-sm" style="background-color:lavenderblush;">Div2</div>
</div>

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

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