简体   繁体   English

Bootstrap列不会彼此相邻显示

[英]Bootstrap columns aren't displayed next to each other

I'm using Bootstrap 4 and having some problem with the Footer part, I want to create three columns with the same width, using class col-md-6 as described in the documentation, this is my code: 我正在使用Bootstrap 4 ,并且Footer部分有问题,我想使用文档中介绍的类col-md-6创建具有相同宽度的三列,这是我的代码:

<footer class="footer">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-6">
        <p>2018 © Hello World!</p>
      </div>
      <div class="col-md-6">
        <div class="text-md-right footer-links d-none d-md-block">
          <a href="javascript: void(0);">About</a>
          <a href="javascript: void(0);">Support</a>
          <a href="javascript: void(0);">Contact Us</a>
        </div>
      </div>
      <div class="col-md-6">
        <div>
          <select>
            <option>1</option>
            <option>2</option>
          </select>
        </div>
      </div>
    </div>
  </div>
</footer>

and this is the CSS applied to stylize the footer: 这是用于样式化页脚的CSS:

.footer {
    border-top: 1px solid rgba(152,166,173,.2);
    bottom: 0;
    padding: 19px 30px 20px;
    position: absolute;
    right: 0;
    color: #98a6ad;
    left: 250px;
}

The result was completely incorrect, I should get the content perfectly aligned to the center of the column which contains the item but I get all the items as: 结果是完全不正确的,我应该使内容与包含该项目的列的中心完美对齐,但是我将所有项目都获得为:

在此处输入图片说明

this is a fiddle . 这是一个小提琴

The expected result should be like this: 预期结果应如下所示:

| 2018© Hello World! | About Support Contact Us | 1

These | 这些| symbols are fake separator in which I have used as a delimiter for the column. 符号是伪分隔符,在其中我已用作列的定界符。 These three columns should be enlarge based on the windows resolution. 这三列应基于Windows分辨率进行放大。

Since grid rule follows - 12 Column system, so one should use grid in a way that it sums up to be 12 . 由于网格规则遵循-12列系统,因此应该以总计为12的方式使用网格。

<footer class="footer">
<div class="container-fluid">
<div class="row">
  <div class="col-xs-4">
    <p>2018 © Hello World!</p>
  </div>
  <div class="col-xs-4">
    <div class="footer-links d-none d-md-block">
      <a href="javascript: void(0);">About</a>
      <a href="javascript: void(0);">Support</a>
      <a href="javascript: void(0);">Contact Us</a>
    </div>
  </div>
  <div class="col-xs-4">
    <div>
      <select>
        <option>1</option>
        <option>2</option>
      </select>
    </div>
  </div>
</div>

CSS 的CSS

.footer {
border-top: 1px solid rgba(152,166,173,.2);
bottom: 0;
padding: 19px 30px 20px;
position: absolute;
right: 0;
color: #98a6ad;
/* left: 250px; */
}

校验

小尺寸

You only need to use col ( https://getbootstrap.com/docs/4.1/layout/grid/#auto-layout-columns ) 您只需要使用colhttps://getbootstrap.com/docs/4.1/layout/grid/#auto-layout-columns

 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" > <footer class="footer"> <div class="container-fluid"> <div class="row"> <div class="col"> <p>2018 © Hello World!</p> </div> <div class="col"> <div class="text-md-right"> <a href="javascript: void(0);">About</a> <a href="javascript: void(0);">Support</a> <a href="javascript: void(0);">Contact Us</a> </div> </div> <div class="col"> <div> <select> <option>1</option> <option>2</option> </select> </div> </div> </div> </div> </footer> 

The bootstrap grid system comes with 12 columns out of the box, so unless you change it it will be 12. 引导网格系统开箱即用,共有12列,因此除非您进行更改,否则它将为12列。

From the bootstrap documentation : 从引导文档

Column classes indicate the number of columns you'd like to use out of the possible 12 per row. 列类表示每行可能使用的12列中的列数。 So, if you want three equal-width columns across, you can use .col-4. 因此,如果要跨三个相等宽度的列,则可以使用.col-4。

Since 12 / 3 = 4 由于12 / 3 = 4


But as of Bootstrap 4, you don't need to explicitly declare the column widths. 但是从Bootstrap 4开始,您无需显式声明列宽。 It will calculate the width of your columns based on how many you have 它将根据您拥有的列数来计算列的宽度

So you would end up with something like this (from the Boostrap documentation ): 因此,您最终将得到如下内容(来自Boostrap文档 ):

<div class="row">
  <div class="col">
      One of three columns
  </div>
  <div class="col">
      One of three columns
  </div>
  <div class="col">
      One of three columns
  </div>
</div>

And it should look like this: 它应该看起来像这样:

3列排

Also, I wouldn't define unnecessary CSS rules. 另外,我不会定义不必要的CSS规则。

The problem in your code is that "col-md" class only applies when the container width is greater than 768 that's the "md" breakpoint. 您的代码中的问题是“ col-md”类仅在容器宽度大于“ md”断点的768时适用。 If you're seeing the Fiddle in it's default layout you'll have your screen split into four areas, and the preview one is less than 768 pixels width, so you get the divs stacked... Furthermore, as stated above in other answers, you should use "-4" instead of "-6" on your classes, since the Bootstrap grid system is based on a 12 column layout. 如果您在默认布局中看到小提琴,则将屏幕划分为四个区域,预览一区域的宽度小于768像素,因此您将div叠放了...此外,如上所述,在其他答案中,您应该在类上使用“ -4”而不是“ -6”,因为Bootstrap网格系统基于12列布局。

So, change the "col-md-6" classes for "col-sm-4" and you'll get what you're looking for. 因此,将“ col-md-6”类更改为“ col-sm-4”,您将获得所需的内容。 (Here "col-sm-" stands for the small screen breakpoint) (此处“ col-sm-”代表小屏幕断点)

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

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