css - 如何使用 ReactBootstrap 在导航栏中显示徽标?
问题描述
我尝试为我的第一个网站制作带有徽标的导航栏。我面临的问题是徽标根本不想显示。它以某种方式起作用的唯一方法是使用来自互联网的某些徽标的 url 链接。我在同一个文件夹中有一个徽标和 .js 文件。
我确实使用过:
"src=/michelinlogo.png"
绝对路径:/home/goteii/reactprojects/xxx/xxxx/src/Components/michelinlogo.png
以及相对路径:src/Components/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>
我希望徽标显示在我的导航栏中,而不是我看到替代文本。
解决方案
尝试先导入徽标:
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>
推荐阅读
- python - Spyder没有找到pytrends
- reactjs - Expo,React Native:URL 和刷新问题
- python - 直接在数据库上从 python 执行 SQL Server 存储过程
- javascript - 在javascript中重叠旋转图像
- python - 我对平行四边形图案有问题,它从正到负
- javascript - Mongo CLI 与客户端速度
- jsp - pageContext.request.contextPath 适用于一台服务器,但不适用于 .jsp 文件中的另一台服务器
- sql - 在 PostgreSQL 数组字段上具有“或”功能的无序模式/规则匹配(?)
- java - 如何遍历哈希图中的哈希集?
- visual-studio-code - 在 Windows10 中安装完成后在 Visual Studio 中出现黑屏