ReactJS Bootstrap 5.2: 在导航栏中排列列元素的间距?

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

ReactJS Bootstrap 5.2: Space Column Elements in NavBar?

问题

将这些项目均匀分布在整个页脚而不是聚集在中心,最好的方法是使用CSS来设置列的间距。您可以为每个列添加marginpadding属性,以使它们在整个页脚中均匀分布。以下是一个示例代码片段,用于设置列之间的间距:

/* 在您的CSS文件中添加以下样式 */
.column {
    margin: 0 10px; /* 设置列之间的水平间距,根据需要进行调整 */
}

然后,将这个column类应用到每个<div className="col">元素上,以实现列的均匀分布。这样,您的项目将在页脚中更均匀地分布。

英文:

I have link items on a footer navbar in a row of columns.

import React from &quot;react&quot;;
import {Link} from &quot;react-router-dom&quot;;

export const NavBarBrandBottom = () =&gt; {

    return (
        &lt;div className=&quot;container-fluid&quot; style={{
            &quot;justify-content&quot;: &#39;center&#39;
        }}&gt;
            &lt;div classname=&quot;row&quot;&gt;
                &lt;ul className=&quot;navbar-nav mb-lg-0&quot; style={{
                    &quot;font-size&quot;: &#39;12px&#39;
                }}&gt;
                    &lt;div className=&quot;col&quot;&gt;
                        &lt;li className=&quot;nav-item me-2&quot;&gt;
                            &lt;Link to={&quot;/add&quot;} className=&quot;nav-link&quot;&gt;
                                &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; fill=&quot;white&quot;
                                    className=&quot;bi bi-plus-square-fill ms-1&quot; viewBox=&quot;0 0 16 16&quot;&gt;
                                    &lt;path
                                        d=&quot;M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z&quot;/&gt;
                                &lt;/svg&gt;
                                &lt;br/&gt;
                                &lt;span&gt;Add&lt;/span&gt;
                            &lt;/Link&gt;
                        &lt;/li&gt;
                    &lt;/div&gt;
                    &lt;div className=&quot;col&quot;&gt;
                        &lt;li className=&quot;nav-item text-center me-2&quot;&gt;
                            &lt;Link to={&quot;/tasks&quot;} className=&quot;nav-link&quot;&gt;
                                &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; fill=&quot;white&quot;
                                    className=&quot;bi bi-card-list ms-1&quot; viewBox=&quot;0 0 16 16&quot;&gt;
                                    &lt;path
                                        d=&quot;M14.5 3a.5.5 0 0 1 .5.5v9a.5.5 0 0 1-.5.5h-13a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h13zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z&quot;/&gt;
                                    &lt;path
                                        d=&quot;M5 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 5 8zm0-2.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0 5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-1-5a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0zM4 8a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0zm0 2.5a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0z&quot;/&gt;
                                &lt;/svg&gt;
                                &lt;br/&gt;
                                &lt;span&gt;Items&lt;/span&gt;
                            &lt;/Link&gt;
                        &lt;/li&gt;
                    &lt;/div&gt;
                    &lt;div className=&quot;col&quot;&gt;
                        &lt;li className=&quot;nav-item text-center&quot;&gt;
                            &lt;Link to={&quot;/family&quot;} className=&quot;nav-link&quot;&gt;
                                &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; fill=&quot;white&quot;
                                    className=&quot;bi bi-people-fill ms-1&quot; viewBox=&quot;0 0 16 16&quot;&gt;
                                    &lt;path
                                        d=&quot;M7 14s-1 0-1-1 1-4 5-4 5 3 5 4-1 1-1 1H7Zm4-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm-5.784 6A2.238 2.238 0 0 1 5 13c0-1.355.68-2.75 1.936-3.72A6.325 6.325 0 0 0 5 9c-4 0-5 3-5 4s1 1 1 1h4.216ZM4.5 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Z&quot;/&gt;
                                &lt;/svg&gt;
                                &lt;br/&gt;
                                &lt;span&gt;Groups&lt;/span&gt;
                            &lt;/Link&gt;
                        &lt;/li&gt;
                    &lt;/div&gt;
                &lt;/ul&gt;
            &lt;/div&gt;      
        &lt;/div&gt;
    );
};

When being displayed, these items are all very close to each other - but I want them spaced out evenly over the entire footer, not clustered in the center. What is the best way of doing this?

答案1

得分: 1

你可以使用Bootstrap的flex实用类:

import React from "react";
import { Link } from "react-router-dom";

export const NavBarBrandBottom = () => {
  return (
    <div className="container-fluid">
      <div className="row">
        <ul
          className="navbar-nav mb-lg-0 d-flex justify-content-around w-100"
          style={{
            "font-size": "12px",
          }}
        >
          <div className="col-auto">
            {/* 添加内容 */}
          </div>
          <div className="col-auto">
            {/* 项目内容 */}
          </div>
          <div className="col-auto">
            {/* 组内容 */}
          </div>
        </ul>
      </div>
    </div>
  );
};

不包括代码部分的翻译。

英文:

You can use Bootstrap's flex utility classes:

import React from &quot;react&quot;;
import { Link } from &quot;react-router-dom&quot;;

export const NavBarBrandBottom = () =&gt; {
  return (
    &lt;div className=&quot;container-fluid&quot;&gt;
      &lt;div className=&quot;row&quot;&gt;
        &lt;ul
          className=&quot;navbar-nav mb-lg-0 d-flex justify-content-around w-100&quot;
          style={{
            &quot;font-size&quot;: &quot;12px&quot;,
          }}
        &gt;
          &lt;div className=&quot;col-auto&quot;&gt;
            {/* Add content */}
          &lt;/div&gt;
          &lt;div className=&quot;col-auto&quot;&gt;
            {/* Items content */}
          &lt;/div&gt;
          &lt;div className=&quot;col-auto&quot;&gt;
            {/* Groups content */}
          &lt;/div&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  );
};

huangapple
  • 本文由 发表于 2023年4月11日 10:50:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982070.html
匿名

发表评论

匿名网友

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

确定