简体   繁体   English

6列bootstrap div内容器的左边界对齐

[英]Left margin alignment of a container inside a 6 column bootstrap div

I have two 6 column bootstrap divs side by side in a row div and both of the divs have an image to display where each image has a width of half the view-port. 我在一行div中并排有两个6列引导区div,并且两个div都有一个要显示的图像,其中每个图像的宽度为视口宽度的一半。 I have a header and a link to be placed in the left column above the image (I have the image set as background of the column via CSS). 我有一个标题和一个链接放置在图像上方的左列中(我通过CSS将图像设置为该列的背景)。 I have placed the header and the link in a container. 我已将标题和链接放在容器中。

Problem 问题

container doesn't align with the left margin of the text (inside a container) that follows the two 6 column bootstrap divs. 容器与在两个6列引导程序div之后的文本的左边缘(容器内)不对齐。 I had set margin left for the container but the alignment goes off when the screen size is changed. 我已经为容器设置了剩余边距,但是当屏幕尺寸改变时,对齐方式将消失。 But below 992px of resolution break-point everything is fine as the columns are stacked. 但低于992px的分辨率断点时,由于将列堆叠起来,一切都很好。 Did I miss something or did I do something wrong? 我错过了什么还是做错了什么?

I'm new to this trade so, help much appreciated!! 我是这个行业的新手,请多多关照!! Here's the code 这是代码

 #aboutus { background-image: url("https://picsum.photos/946/381"); background-size: cover; background-repeat: no-repeat; display: flex; align-items: center; } 
 <div class="row"> <div id="aboutus" class="col-lg-6"> <div class="container"> <h2 style="color: white;">About Us</h2> <a class="small" href="#home" style="color: white;">Home</a> <i style="color: white;" class="fa fa-angle-right"></i> </div> </div> <div class="col-lg-6"> <img class="img-fluid w-100" src="https://picsum.photos/946/381" alt=""> </div> </div> <div class="container"> <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dignissimos cupiditate ut nobis unde ipsa eius commodi, praesentium eum. Natus, laborum illo est dolorem rem quos ui ipsum nemo fuga. Odio, aut. Esse veniam quia corporis dolor vitae totam.</p> </div> 

Change col-lg-6 to some other responsive size. 将col-lg-6更改为其他响应大小。

In the example I changed it to col-6. 在示例中,我将其更改为col-6。 See: https://getbootstrap.com/docs/4.0/layout/grid/#grid-options 请参阅: https//getbootstrap.com/docs/4.0/layout/grid/#grid-options

 #aboutus { background-color: #e6603f; background-size: cover; background-repeat: no-repeat; display: flex; align-items: center; background-image:url(https://picsum.photos/946/381); } 
 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div id="aboutus" class=" col-6"> <div class="container"> <h2 style="color: white">About Us</h2> <a class="small" href="#home" style="color:white">Home</a> <i style="color: white" class="fa fa-angle-right"> </i> </div> </div> <div class="col-6"> <img class="img-fluid w-100" src="https://picsum.photos/946/381" alt="" /> </div> </div> <div class="container"> <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dignissimos cupiditate ut nobis unde ipsa eius commodi, praesentium eum. Natus, laborum illo est dolorem rem quos ui ipsum nemo fuga. Odio, aut. Esse veniam quia corporis dolor vitae totam.</p> </div> 

for small screen you need to use col-* class and after large screen you need to use col-lg-* class, for more info check this link 对于小屏幕,您需要使用col- *类,大屏幕后,您需要使用col-lg- *类,有关更多信息,请检查此链接

In your code i use col-12 and col-lg-6 so in large screen your two image show side by side and in small screen it show like up down manner 在您的代码中,我使用col-12col-lg-6因此在大屏幕中两个图像并排显示,在小屏幕中它像上下显示

 #aboutus { background-color: #e6603f; background-size: cover; background-repeat: no-repeat; display: flex; align-items: center; } 
 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/> <div class="row m-0"> <div id="aboutus" class="col-12 col-lg-6"> <div class="container"> <h2 style="color: white;">About Us</h2> <a class="small" href="#home" style="color: white;">Home</a> <i style="color: white;" class="fa fa-angle-right"></i> </div> </div> <div class="col-12 col-lg-6"> <img class="img-fluid w-100" src="https://picsum.photos/946/381" alt=""> </div> </div> <div class="container"> <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dignissimos cupiditate ut nobis unde ipsa eius commodi, praesentium eum. Natus, laborum illo est dolorem rem quos ui ipsum nemo fuga. Odio, aut. Esse veniam quia corporis dolor vitae totam.</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM