css - 我如何使用 React Bootstrap 在导航栏中显示 Logo ?

标签 css reactjs react-bootstrap

我尝试为我的第一个网站制作一个带 Logo 的导航栏。我面临的问题是 Logo 根本不想显示。它以某种方式工作的唯一方法是使用 url 链接到来自互联网的一些标志。我在同一个文件夹中有一个 Logo 和 .js 文件。

我确实用过:

"src=/michelinlogo.png"

绝对路径: /home/goteii/reactprojects/xxx/xxxx/src/Components/michelinlogo.png

以及相对路径: src/组件/michelinlogo.png

export class NavBar extends Component {
render() {
    return (
        <>
<Navbar bg="dark" style = {{height: "5em"}}>
<Navbar.Brand href="#home">
  <img
    alt="Michelin_logo"
    src="/michelinlogo.png"
    width="150"
    height="30"
    className="d-inline-block align-top"
  />
  {' Michelin App'}
</Navbar.Brand>
<Nav>
<Navbar.Brand href="#login" style= {{float:"right"}}>Login
</Navbar.Brand>
</Nav>
</Navbar>

我希望 Logo 显示在我的导航栏中,但我看到了替代文本。

最佳答案

首先尝试导入 Logo :

import logo from './michelinlogo.png'; // If it's in the same folder as your component. Otherwise adjust the path

<Navbar.Brand href="#home">
  <img
    alt="Michelin_logo"
    src={logo}
    width="150"
    height="30"
    className="d-inline-block align-top"
  />
  {" Michelin App"}
</Navbar.Brand>

关于css - 我如何使用 React Bootstrap 在导航栏中显示 Logo ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57545813/

相关文章:

javascript - Flow 未捕获导入组件的类型错误

reactjs - 使用 React Router 锚定选项卡

css - 检查正在应用哪个 Bootstrap 类并根据使用 AngularJS 添加行为

javascript - 显示一些标记导致其他标记消失

css - 改变文本区域的大小

javascript - 这个 rxjs 合并逻辑可以简化吗?

javascript - 使用手机时如何隐藏一个 svg 并显示另一个?

javascript - React bootstrap - 无效的钩子(Hook)调用

CSS 宽度 : not working in label

java - css 子菜单在网站加载时保持刷新