为什么我的图标被放置为列而不是行?
我试图使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在使用Bootstrap库,但是
package.json
中没有依赖性。这意味着您应该安装此依赖关系:必须编辑小型错字:
应该是:
替代方法:
另一种方法是创建自己的样式。 可以在sandbox
您可以:
创建“ styles.css”
创建新类:
包括在您的组件中:
为组件应用样式:
It looks like you are using Bootstrap library, however there is no dependency in
package.json
. It means you should install this dependency:After installing
bootstrap
, it is necessary to edit small typo:should be:
Alternative way:
Another way is to create own style. An example can be seen at sandbox
So you can:
Create "styles.css"
create new class:
include in your component:
apply style for your component: