我有三個並排的div,我希望它們在屏幕變小時彼此堆疊。相反,divs調整內容看起來很糟糕。如何在屏幕變小時將div彼此疊放在一起?引導
我跟着W3Schools的教程(bootstrap_grid_stacked_to_horizontal),使他們通過把他們container
DIV和row
DIV裏面除了堆放在添加類col-lg-4
但他們仍然調整。
這是相關的HTML和CSS:
.how-it-works-container{
\t padding: 50px;
\t background-color: #C5B358;
\t font-family: 'Montserrat', sans-serif;
\t opacity: .8;
\t text-align: center;
\t width: 100%
}
.how-it-works-box{
\t padding: 30px;
\t background-color: #D6C362;
\t margin: 20px 5px;
\t
\t width: calc(30%);
\t overflow-wrap: break-word;
\t color: white;
\t display: inline-block;
\t 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>
將'col-xs-12'添加到當前具有'col-lg-4'的3個div,這會將尺寸設置爲xs屏幕大小以及您當前定位的lg屏幕大小。 – Toby
看一看[docs](https://getbootstrap.com/examples/grid/)。 你可以用'''class =「col-xs-4」'''設置同樣的寬度,這也適用於移動和桌面。 或者就像@Toby用''class =「col-xs-12 col-lg-4」說的那樣''' – Dwhitz
使用相同的代碼,只需刪除'class =「row」',那麼它就會工作。 – user6542823