Bootstrap Large column overlay medium

坚强是说给别人听的谎言 提交于 2021-01-28 09:48:04

问题


http://shoelace.io/#7f34fe76be20d73e7e28d03db5e311d4

<div class="container">
  <div class="row">
    <div class="col-md-6">A</div>
    <div class="col-md-6">B</div>
    <div class="col-lg-6">C</div>
    <div class="col-lg-6">D</div>
  </div>
</div>

Given the above structure, why does C overlay both B and A on the medium resolution?

What I was expecting: What I see:


回答1:


Bootstrap col-x-* classes that fall beneath a media query have all css inherited from the col-x-* class removed.

The reason why they default to full width, is not because of a design intention by bootstrap, but is the default behaviour for those divs.

This is counter-intuitive to their documentation which suggests it as a valid method of falling back to mobile.

It is not optional to include the col-xs-12 class if you are using a greater class and wish it to break to full width!

changing the code to

<div class="container">
  <div class="row">
    <div class="col-xs-12 col-md-6">A</div>
    <div class="col-xs-12 col-md-6">B</div>
    <div class="col-xs-12 col-lg-6">C</div>
    <div class="col-xs-12 col-lg-6">D</div>
  </div>
</div>

Will resolve the issue, you do not need to specify col-sm-12 as col-xs-12 will apply.

This is due to bootstrap not applying floats to auto-expanded divs (for whatever reason I'm not sure)

https://github.com/twbs/bootstrap/issues/17998

https://github.com/twbs/bootstrap/issues/17603




回答2:


Use

col-md-# for medium screen size

col-lg-# for large screen size

and if you want same size element in all screen sizes use same class instead

<div class="container">
  <div class="row">
    <div class="col-md-6">A</div>
    <div class="col-md-6">B</div>
    <div class="col-md-6">C</div>
    <div class="col-md-6">D</div>
  </div>
</div>



回答3:


Ignore the Colors, they are just for demo purpose.

.bg {
  height: 100px;
  border: 2px solid #000;
}

.bg-blue {
  background: #00A2E8;
}

.bg-yellow {
  background: #FFF200;
}

.bg-red {
  background: #ED1C24;
}

.bg-green {
  background: #22B14C;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-xs-12 col-md-6 bg bg-blue"></div>
    <div class="col-xs-12 col-md-6 bg bg-yellow"></div>
    <div class="col-xs-12 col-lg-6 bg bg-red"></div>
    <div class="col-xs-12 col-lg-6 bg bg-green"></div>
  </div>

</div>



回答4:


Hi if i understand correctly. you want to show 2 alligned in top. 1 full under those two and under that one another full width one.

If this is the problem I would suggest this:

<div class="container">
  <div class="row">
    <div class="col-xs-12 col-md-6 col-lg-6">A</div>
    <div class="col-xs-12 col-md-6 col-lg-6">B</div>
    <div class="col-xs-12 col-md-12 col-lg-6">C</div>
    <div class="col-xs-12 col-md-12 col-lg-6">D</div>
  </div>
</div>


来源:https://stackoverflow.com/questions/42969468/bootstrap-large-column-overlay-medium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!