如何在Bootstrap中调整内容以适应列宽?

huangapple go评论66阅读模式
英文:

How to wrap content to fit column width in Bootstrap?

问题

我有以下内容:

<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->

<!-- 语言: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">

    <div class="row">
      <div class="col-xs-2 col-md-4">
        Name
      </div>
      <div class="col-xs-10 col-md-8">
        <b class="d-block">Here some name</b>
      </div>
    </div>

<!-- 结束代码片段 -->

在较小的设备上查看时,我希望列的宽度具有优先级,并且其中的内容应该换行。目前,列是按顺序显示的。

我该如何解决这个问题?

英文:

I have the following:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css&quot; integrity=&quot;sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N&quot; crossorigin=&quot;anonymous&quot;&gt;

&lt;div class=&quot;row&quot;&gt;
  &lt;div class=&quot;col-xs-2 col-md-4&quot;&gt;
    Name
  &lt;/div&gt;
  &lt;div class=&quot;col-xs-10 col-md-8&quot;&gt;
    &lt;b class=&quot;d-block&quot;&gt;Here some name&lt;/b&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

When viewing on smaller devices I would like that the column widths have priority and the content within them should wrap. Currently, the columns are displayed under each other.

How can I fix this?

答案1

得分: 1

你只需编写这个类:.col-,并且如果需要,你还可以将.container类添加到容器中,以便从两侧获得一些边距。

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

<div class="row container">
    <div class="col-2 col-md-4">
        Name
    </div>
    <div class="col-10 col-md-8">
        <b class="d-block">Here some name</b>
    </div>
</div>
英文:

You are gonna have to only write this class: .col- and you can also add the .container class to the container to get some margin from the both sides if you want.

<!-- 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">

 &lt;div class=&quot;row container&quot;&gt;
    &lt;div class=&quot;col-2 col-md-4&quot;&gt;
        Name
    &lt;/div&gt;
    &lt;div class=&quot;col-10 col-md-8&quot;&gt;
        &lt;b class=&quot;d-block&quot;&gt;Here some name&lt;/b&gt;
    &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月3日 19:05:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76604145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定