为什么我的图标被放置为列而不是行?

发布于 2025-02-06 11:56:08 字数 2348 浏览 2 评论 0原文

我试图使用className =“ col s1”将这些图标与一行对齐,但是当我运行此代码时,它在列中显示在列中。我尝试删除容器标签,添加它,IVE尝试更改列大小,但是由于某种原因,它总是以列显示为列而不是行。

有什么办法可以使它起作用?

这是指代码的链接: project

main.jsx

import React, { useState, useEffect, useRef } from "react";
import Helmet from "react-helmet";
import Socials from "./Socials";
function Main(props) {
  const socialMedia = [
    {
      link: "https://www.linkedin.com/in/",
      icon: "linkedin"
    },
    {
      link: "https://github.com/",
      icon: "github"
    },
    {
      link: "https://www.youtube.com/",
      icon: "youtube"
    },
    {
      link:
        "mailto:[email protected]?subject=Felipe%20GD%20--%20Request%20To%20Contact",
      icon: "email"
    }
  ];

  return (
    <React.Fragment>
      <Helmet>
        <title>Felipe GD</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      </Helmet>
      <div className="container">
        <div clasName="row">
          {socialMedia.map((socials) => (
            <Socials
              getOpacity={null}
              getVisibility={null}
              link={socials.link}
              icon={socials.icon}
            />
          ))}
        </div>
      </div>
    </React.Fragment>
  );
}

export default Main;


socials.jsx

import React, { useEffect, useRef } from "react";
import { SocialIcon } from "react-social-icons";

function Socials(props) {
  let size = useRef("20");

  useEffect(() => {
    if (window.innerWidth > 500) {
      size.current = 50;
    } else {
      size.current = 25;
    }
  }, [size]);

  return (
    <React.Fragment>
      <div className="col s1">
        <SocialIcon
          id={props.icon}
          bgColor="#2C2C2C"
          fgColor="#ECCECE"
          network={props.icon}
          url={props.link}
        />
      </div>
    </React.Fragment>
  );
}

export default Socials;

我知道我可以通过不将其制成一个组件来使它起作用,但是对我来说,这看起来很干净,ID喜欢在可能的情况下使用地图功能。

I am trying to align these icons as a row using className="col s1" but when I run this code its displayed in a column for some reason. I've tried removing the container tag, adding it, ive tried changing the column sizes, but for some reason it is always displayed as a column instead of as a row.

Is there any way i can get this to work?

Here is a link to the code: Project

Main.jsx

import React, { useState, useEffect, useRef } from "react";
import Helmet from "react-helmet";
import Socials from "./Socials";
function Main(props) {
  const socialMedia = [
    {
      link: "https://www.linkedin.com/in/",
      icon: "linkedin"
    },
    {
      link: "https://github.com/",
      icon: "github"
    },
    {
      link: "https://www.youtube.com/",
      icon: "youtube"
    },
    {
      link:
        "mailto:[email protected]?subject=Felipe%20GD%20--%20Request%20To%20Contact",
      icon: "email"
    }
  ];

  return (
    <React.Fragment>
      <Helmet>
        <title>Felipe GD</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      </Helmet>
      <div className="container">
        <div clasName="row">
          {socialMedia.map((socials) => (
            <Socials
              getOpacity={null}
              getVisibility={null}
              link={socials.link}
              icon={socials.icon}
            />
          ))}
        </div>
      </div>
    </React.Fragment>
  );
}

export default Main;


Socials.jsx

import React, { useEffect, useRef } from "react";
import { SocialIcon } from "react-social-icons";

function Socials(props) {
  let size = useRef("20");

  useEffect(() => {
    if (window.innerWidth > 500) {
      size.current = 50;
    } else {
      size.current = 25;
    }
  }, [size]);

  return (
    <React.Fragment>
      <div className="col s1">
        <SocialIcon
          id={props.icon}
          bgColor="#2C2C2C"
          fgColor="#ECCECE"
          network={props.icon}
          url={props.link}
        />
      </div>
    </React.Fragment>
  );
}

export default Socials;

I know i could get this to work by not making it into a component but that doesent look clean to me, id like to be able to use the map function if possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找我们的幸福 2025-02-13 11:56:08

看起来您正在使用Bootstrap库,但是package.json中没有依赖性。这意味着您应该安装此依赖关系

npm i react-bootstrap

:必须编辑小型错字:

<div clasName="row"> 

应该是:

<div className="row">

替代方法:

另一种方法是创建自己的样式。 可以在sandbox

您可以:

  1. 创建“ styles.css”

  2. 创建新类:

      .myrow {
         显示:Flex;
     }
     
  3. 包括在您的组件中:

     导入” ./styles.css”
     
  4. 为组件应用样式:

     &lt; div className =“ myrow”&gt;
       {socialmedia.map(((socials)=&gt;((
         &lt;社交
           getopacity = {null}
           getvisibility = {null}
           link = {socials.link}
           图标= {socials.icon}
         /&gt;
       )}}
     &lt;/div&gt;
     

It looks like you are using Bootstrap library, however there is no dependency in package.json. It means you should install this dependency:

npm i react-bootstrap

After installing bootstrap, it is necessary to edit small typo:

<div clasName="row"> 

should be:

<div className="row">

Alternative way:

Another way is to create own style. An example can be seen at sandbox

So you can:

  1. Create "styles.css"

  2. create new class:

     .myRow {
         display: flex;
     }
    
  3. include in your component:

     import "./styles.css"
    
  4. apply style for your component:

     <div className="myRow" >
       {socialMedia.map((socials) => (
         <Socials
           getOpacity={null}
           getVisibility={null}
           link={socials.link}
           icon={socials.icon}
         />
       ))}
     </div>
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文