为移动设备调整大小时响应 CSS 浮动 table

Responsive CSS float table when resizing for mobile

我有一个页面,其中包含一个简单的 2 列 CSS table,在一个通用容器 div 中,如下所示:

#container:after {
    content: "";
    display: table;
    clear: both;
}
#col_1 {
    float: left;
    width: 50%;
    padding-right: 20px;
}
#col_2 {
    width: 50%;
}

它在计算机上可以正常工作,但在移动设备上,两列 overlap/overlay 并且我希望 col2 位于 col1 下方。换句话说,只有在两者都有空间时才浮动,否则就变成两行。 我该怎么做?

谢谢

由于没有你的HTML代码,我只能自己做一个模型。为移动设备添加断点媒体查询。

html,
body,
#container {
  width: 100%;
  margin: 0;
}

#container:after {
  content: "";
  display: table;
  clear: both;
}

#col_1 {
  float: left;
  width: 50%;
  height: 100px;
  padding-right: 20px;
  background: orange;
}

#col_2 {
  float: left;
  width: calc(50% - 20px); /* The 20px is the padding-right of the col_1 */
  height: 100px;
  background: lime;
}

@media screen and (max-width: 576px) {
  #col_1 {
    width: 100%;
  }
  #col_2 {
    width: 100%;
  }
}
<div id="container">
  <div id="col_1"></div>
  <div id="col_2"></div>
</div>