html - 当屏幕变小时如何将div堆叠在一起? Bootstrap

标签 html css twitter-bootstrap grid resize

我有三个并排的 div,当屏幕变小时,我希望它们彼此堆叠。相反,div 会调整大小,使内容看起来很糟糕。

我按照 w3schools 教程 (bootstrap_grid_stacked_to_horizo​​ntal) 进行操作,除了添加类 col 之外,还通过将它们放入 container div 和 row div 中来使它们堆叠起来-lg-4 但它们仍然调整大小。

这是相关的 HTML 和 CSS:

.how-it-works-container{
    	padding: 50px;
    	background-color: #C5B358;
    	font-family: 'Montserrat', sans-serif;
    	opacity: .8;
    	text-align: center;
    
    	width: 100%
    }
 
    .how-it-works-box{
    	padding: 30px;
    	background-color: #D6C362;
    	margin: 20px 5px;
    	
    	width: calc(30%);
    	overflow-wrap: break-word;
    	color: white;
    	display: inline-block;
    	box-shadow: 0 4px 8px 0 rgba(255, 255, 255, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    }
<!-- How It Works section -->
<div class="how-it-works-container container">

    <h2>How It Works</h2>

  <div class="row">

      <div class="how-it-works-box col-lg-4"> 
        <img src=" {% static "images/meetlocals3.svg" %} "> 
        <h3>Meet Local People</h3>
        <p>Meet like-minded locals who could show you around their city.</p>
      </div>

      <div class="how-it-works-box col-lg-4">
        <img src=" {% static "images/showpeople.svg" %} ">
        <h3>Show Visitors Around</h3>
        <p>Show visitors around and meet interesting international visitors.</p>
      </div>

      <div class="how-it-works-box col-lg-4">
        <img src=" {% static "images/makefriends.svg" %} ">
        <h3>Make New Friends!</h3>
        <p>Walking around is a fun bonding activity to make new friends!</p>
      </div>

    </div>
</div>

最佳答案

CSS 正在覆盖 Bootstrap 网格。将盒子放入 Bootstrap 网格列内,这些列将自动堆叠在 xs 屏幕上。

http://www.codeply.com/go/gTkC50Paql

.how-it-works-container{
    padding: 50px;
    background-color: #C5B358;
    font-family: 'Montserrat', sans-serif;
    opacity: .8;
    text-align: center;
}

.how-it-works-box{
    width: 100%;
    padding: 30px;
    background-color: #D6C362;
    margin: 20px 5px;
    overflow-wrap: break-word;
    color: white;
    display: inline-block;
    box-shadow: 0 4px 8px 0 rgba(255, 255, 255, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

<div class="how-it-works-container container-fluid">
    <h2>How It Works</h2>
    <div class="row">
        <div class="col-lg-4">
            <div class="how-it-works-box">
                <img src="">
                <h3>Meet Local People</h3>
                <p>Meet like-minded locals who could show you around their city.</p>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="how-it-works-box">
                <img src="">
                <h3>Show Visitors Around</h3>
                <p>Show visitors around and meet interesting international visitors.</p>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="how-it-works-box">
                <img src="">
                <h3>Make New Friends!</h3>
                <p>Walking around is a fun bonding activity to make new friends!</p>
            </div>
        </div>
    </div>
</div>

关于html - 当屏幕变小时如何将div堆叠在一起? Bootstrap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43954450/

相关文章:

html - 背景附件中的全宽图像不起作用

php - 在 SimplePie 提要文章之间添加横幅

c# - 想要从控件的客户端实现可见性,而从服务器端不可见

jquery - 最简单的增加 - 使用 jquery 减少选择区域中的值选项

html - 如何创建具有背景图像的部分?

html - 使用 Bootstrap 将搜索图标放在文本框附近

html - web.config 和 CDATA 错误

javascript - 单击 div 时更改复选框值

c# - 像在 html 上一样测量字符串?

css - 如何使用 HTML-CSS 表格获得垂直文本省略号?