如何将我的现有JSX代码转换/使用/修复以适应Bootstrap的显示属性?

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

How can I convert/use/fix my existing JSX code to work with Bootstraps display properties?

问题

我被卡住了,所以我需要一些帮助。几个月前,我使用HTML、CSS和JavaScript构建了一个单页网页。

现在我正在使用REACT JS构建同样的网页。

上一个版本的代码示例:

<sectio id="topbar" class="d-none d-lg-block">
  <div class="dontainer d-flex">
    <div class="contact-info mr-auto">
      <i class="fas fa-envelope"></i>
      <a href="mailto:example@example.com">example@example.com &nbsp;</a>
      <i class="fas fa-phone"></i>
      <a href="tel:example">example&nbsp;&nbsp;</a>
      <i class="fas fa-map-marker-alt"></i>
      <a href="https:example">lorem lorem</a>
    </div>
  </div>
</sectio>

相同的代码,但使用了JSX和className:

const TopBar = () => {
  return (
    <section id="topbar" className="d-none d-lg-block">
      <div className="dontainer d-flex">
        <div className="contact-info mr-auto">
          <FontAwesomeIcon icon={faEnvelope} style={{ color: "#efa036" }} />
          <i className="fas fa-envelope"></i>
          <a href="mailto:example@example.com">example@example.com &nbsp;</a>
          <i className="fas fa-phone"></i>
          <FontAwesomeIcon icon={faPhone} style={{ color: "#efa036" }} />
          <a href="tel:example">example&nbsp;&nbsp;</a>
          <i className="fas fa-map-marker-alt"></i>
          <FontAwesomeIcon icon={faLocationDot} style={{ color: "#efa036" }} />
          <a href="example">example</a>
        </div>
      </div>
    </section>
  );
};

问题是,我无法在新的React JS版本中使用之前版本(HTML、CSS、JS)中的Bootstrap类(这些类用于显示属性)。Bootstrap的显示属性根本不起作用。

问题是如何将现有的JSX代码转换/使用/修复,以便与Bootstrap的显示属性一样工作,就像之前的版本一样?

附言:

我已经在我的VS CODE终端中安装了Bootstrap("bootstrap": "^5.3.1")。

英文:

I am stuck with my project, so I need some help. A few months ago I built a single-page webpage using HTML, CSS, and JAVASCRIPT.

Now I am working on the same webpage, but I am building it in REACT JS.

Code example from the previous version

&lt;sectio id=&quot;topbar&quot; class=&quot;d-none d-lg-block&quot;&gt;
      &lt;div class=&quot;dontainer d-flex&quot;&gt;
        &lt;div class=&quot;contact-info mr-auto&quot;&gt;
          &lt;i class=&quot;fas fa-envelope&quot;&gt;&lt;/i&gt;
            &lt;a href=&quot;mailto:&quot;example@example.com&quot;&gt;example@example.com &amp;nbsp;&lt;/a&gt;
            &lt;i class=&quot;fas fa-phone&quot;&gt;&lt;/i&gt;
              &lt;a href=&quot;tel: example&quot;&gt;example&amp;nbsp; &amp;nbsp;&lt;/a&gt;
              &lt;i class=&quot;fas fa-map-marker-alt&quot;&gt;&lt;/i&gt;
                &lt;a href=&quot;https:example&quot;&gt;lorem lorem&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/sectio&gt;

The same code but in JSX with className

const TopBar = () =&gt; {
  return (
    &lt;section id=&quot;topbar&quot; className=&quot;d-none d-lg-block&quot;&gt;
      &lt;div className=&quot;dontainer d-flex&quot;&gt;
        &lt;div className=&quot;contact-info mr-auto&quot;&gt;
          &lt;FontAwesomeIcon icon={faEnvelope} style={{ color: &quot;#efa036&quot; }} /&gt;
          &lt;i className=&quot;fas fa-envelope&quot;&gt;&lt;/i&gt;
          &lt;a href=&quot;mailto:example@example.com&quot;&gt;example@example.com &amp;nbsp;&lt;/a&gt;
          &lt;i className=&quot;fas fa-phone&quot;&gt;&lt;/i&gt;
          &lt;FontAwesomeIcon icon={faPhone} style={{ color: &quot;#efa036&quot; }} /&gt;
          &lt;a href=&quot;tel:example example &amp;nbsp;&lt;/a&gt;
          &lt;i className=&quot;fas fa-map-marker-alt&quot;&gt;&lt;/i&gt;
          &lt;FontAwesomeIcon icon={faLocationDot} style={{ color: &quot;#efa036&quot; }} /&gt;
          &lt;a href=&quot;example&quot;&gt;
            example
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/section&gt;
  );
};

The problem is that I can't use the Bootstrap classes (those classes are for display properties) from the previous version (HTML, CSS, JS) in the new React JS version. The display property of Boostrap simply doesn't work.

The question is how can I convert/use/fix my existing JSX code to work with Bootstraps display properties just like the previous version does?

P.S.

I have installed Boostrap ( "bootstrap": "^5.3.1",) in NPM in my VS CODE terminal.

答案1

得分: -1

你在 app.jsx 中是否导入了 import bootstrap/dist/css/bootstrap.min.css?其次,检查类名的拼写,例如 container 和 flex,而不是 <div className="container d-flex">,否则它与 Bootstrap 4 的版本相同。

英文:

Did you import the import bootstrap/dist/css/bootstrap.min.css in app.jsx second, check the spell of classes as well like container flex not <div className="container d-flex"> otherwise its same as version 4 of bootstrap

huangapple
  • 本文由 发表于 2023年8月8日 21:22:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859987.html
匿名

发表评论

匿名网友

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

确定