英文:
Putting 2 divs under each other with Bootstrap flex classes
问题
你可以在上传的图片上看到我的问题。在其中,第一张图片。
当我最小化浏览器窗口宽度时,这两个 div 不会叠在彼此下面,只有当窗口完全最小化,或者在移动设备上查看网站时才会叠在一起。
当窗口太小,以至于这两个 div 可以相互接触时,我希望它们叠在彼此下面。
我尝试了媒体查询,但我认为只用一些 Bootstrap 类就可以做到这一点,这会更好。

以下是 HTML 代码片段:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<section class="header_full_width py-2 px-4">
<div class="container-fluid">
<div class="row align-items-center justify-content-center justify-content-lg-between">
<div>
<a href="tel:+3630" class="text-white_disabled header_full_width_link text-white_redundant" title="Hívás"><i class="fa fa-phone mr-1 mr-md-2"></i>Kérdésed van? +36 30 123 4567</a>
</div>
<div>
<span class="text-white_disabled header_full_width_link text-white_redundant"><i class="fa fa-envelope mr-1 mr-md-2"></i>info@emailcimem.hu</span>
<span class="nav_separator_2 text-white mx-1">|</span>
<a href="kapcsolat" class="text-white_disabled header_full_width_link text-white_redundant" title="Elérhetőségeink"><i class="fa fa-phone-square mr-1 mr-md-2"></i>Kapcsolat</a>
</div>
</div>
</div>
</section>
英文:
You can see my problem on the uploaded image. Within that, the first image.
When I minimize the browser screen width these two divs won't get under each other, just when the window is fully minimized, or when i view the site on mobile.
When the window is too small, so the 2 divs can reach each other, I want them under each other.
I tried media queries, but I think I can do this with only a few Bootstrap classes, and that will be better.

<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<section class="header_full_width py-2 px-4">
<div class="container-fluid">
<div class="row align-items-center justify-content-center justify-content-lg-between">
<div>
<a href="tel:+3630" class="text-white_disabled header_full_width_link text-white_redundant" title="Hívás"><i class="fa fa-phone mr-1 mr-md-2"></i>Kérdésed van? +36 30 123 4567</a>
</div>
<div>
<span class="text-white_disabled header_full_width_link text-white_redundant"><i class="fa fa-envelope mr-1 mr-md-2"></i>info@emailcimem.hu</span>
<span class="nav_separator_2 text-white mx-1">|</span>
<a href="kapcsolat" class="text-white_disabled header_full_width_link text-white_redundant" title="Elérhetőségeink"><i class="fa fa-phone-square mr-1 mr-md-2"></i>Kapcsolat</a>
</div>
</div>
</div>
</section>
<!-- end snippet -->
答案1
得分: 0
你可以使用Bootstrap的row和col类。
正如您在上面的代码示例中已经看到的那样,您已经使用了row,但没有为子元素的div使用col。
Bootstrap认为row有12个单位。因此,对于这两个div,您可以分别给它们赋予col-12 col-lg-6的类。Bootstrap采用移动优先的方式,这意味着直到屏幕尺寸达到lg(992px)之前,这两个div将占满整行的宽度,然后它们将各自占用一半,即6个单位。
“当窗口太小,以至于两个div可以相互接触时,我希望它们排列在下面。”
要回答这个问题,您可以选择在什么时候希望您的div共享同一行。只需将lg替换为适当的断点,参考下面的图像。
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<section class="header_full_width py-2 px-4">
<div class="container-fluid">
<div class="row align-items-center justify-content-center justify-content-lg-between">
<div class='col-12 col-lg-6'>
<a href="tel:+3630" class="text-white_disabled header_full_width_link text-white_redundant" title="Hívás"><i class="fa fa-phone mr-1 mr-md-2"></i>Kérdésed van? +36 30 123 4567</a>
</div>
<div class='col-12 col-lg-6'>
<span class="text-white_disabled header_full_width_link text-white_redundant"><i class="fa fa-envelope mr-1 mr-md-2"></i>info@emailcimem.hu</span>
<span class="nav_separator_2 text-white mx-1">|</span>
<a href="kapcsolat" class="text-white_disabled header_full_width_link text-white_redundant" title="Elérhetőségeink"><i class="fa fa-phone-square mr-1 mr-md-2"></i>Kapcsolat</a>
</div>
</div>
</div>
</section>
英文:
You can use bootstrap's row and col classes.
As we can already see, in your code example above. You have used row but not col for the children div's
A bootstrap row is considered to have 12 units. So for both the div's you can give class of col-12 col-lg-6. Bootstrap takes a mobile first approach so this means, the div's will take full width of the row till the screen size reaches lg (992px), then the div's will occupy half each i.e. 6 units each.
"When the window is too small, so the 2 div's can reach each other, I want them under each other."
To answer this - you can choose when you want your div's to share the row. Just replace lg with the appropriate breakpoint by refrencing the image below.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<section class="header_full_width py-2 px-4">
<div class="container-fluid">
<div class="row align-items-center justify-content-center justify-content-lg-between">
<div class='col-12 col-lg-6'>
<a href="tel:+3630" class="text-white_disabled header_full_width_link text-white_redundant" title="Hívás"><i class="fa fa-phone mr-1 mr-md-2"></i>Kérdésed van? +36 30 123 4567</a>
</div>
<div class='col-12 col-lg-6'>
<span class="text-white_disabled header_full_width_link text-white_redundant"><i class="fa fa-envelope mr-1 mr-md-2"></i>info@emailcimem.hu</span>
<span class="nav_separator_2 text-white mx-1">|</span>
<a href="kapcsolat" class="text-white_disabled header_full_width_link text-white_redundant" title="Elérhetőségeink"><i class="fa fa-phone-square mr-1 mr-md-2"></i>Kapcsolat</a>
</div>
</div>
</div>
</section>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论