可以使用React-Bootstrap在Navbar中的右侧对齐图像
无法以某种方式对齐此显示图像。遵循文档,并使用许多React-Bootstrap属性,例如正当权利,文本 - 单位,向右拉。但是无法做到这一点。
但是它没有显示图像。我尝试了相同的属性,但它粘在左侧。
我想将其移至右侧。
完整的Navbar代码
/* Display User Code starts here. I want to move it to right */
<Nav>
{user ? (
<>
{" "}
<NavDropdown
className="ms-auto"
eventKey={1}
title={
<img
className="user_image"
src="https://i.ibb.co/LJ2BGT2/121105442-creative-illustration-of-default-avatar-profile-placeholder-isolated-on-background-art-des.webp"
alt="user pic"
/>
}
id="basic-nav-dropdown"
>
<NavDropdown.Item to="/addproduct">
Add Product
</NavDropdown.Item>
<NavDropdown.Item to="/manageproduct">
Manage Product
</NavDropdown.Item>
<NavDropdown.Item
to="/order"
className="justify-content-center"
>
Order
<Badge className="mx-2 mt-2 " bg="dark">
9
</Badge>
<span className="visually-hidden">
unread messages
</span>
</NavDropdown.Item>
<NavDropdown.Item divider />
<NavDropdown.Item eventKey={1.3}>
<Button
variant="primary"
size="sm"
className="mx-2"
onClick={handleSignOut}
>
Sign Out
</Button>
</NavDropdown.Item>
</NavDropdown>{" "}
</>
) : (
<>
{" "}
<CustomLink to="/login">Login</CustomLink>
<CustomLink to="/register">Register</CustomLink>
</>
)}
</Nav>
Can't Align right this Display Image in the navbar somehow. Follow documents and use many react-bootstrap properties like justify-content-right, text-align, pull right. But can't manage to do it.
But it worked without display image. I tried same properties but it stick to the left.
I want to move it to the right side.
Full Navbar Code
/* Display User Code starts here. I want to move it to right */
<Nav>
{user ? (
<>
{" "}
<NavDropdown
className="ms-auto"
eventKey={1}
title={
<img
className="user_image"
src="https://i.ibb.co/LJ2BGT2/121105442-creative-illustration-of-default-avatar-profile-placeholder-isolated-on-background-art-des.webp"
alt="user pic"
/>
}
id="basic-nav-dropdown"
>
<NavDropdown.Item to="/addproduct">
Add Product
</NavDropdown.Item>
<NavDropdown.Item to="/manageproduct">
Manage Product
</NavDropdown.Item>
<NavDropdown.Item
to="/order"
className="justify-content-center"
>
Order
<Badge className="mx-2 mt-2 " bg="dark">
9
</Badge>
<span className="visually-hidden">
unread messages
</span>
</NavDropdown.Item>
<NavDropdown.Item divider />
<NavDropdown.Item eventKey={1.3}>
<Button
variant="primary"
size="sm"
className="mx-2"
onClick={handleSignOut}
>
Sign Out
</Button>
</NavDropdown.Item>
</NavDropdown>{" "}
</>
) : (
<>
{" "}
<CustomLink to="/login">Login</CustomLink>
<CustomLink to="/register">Register</CustomLink>
</>
)}
</Nav>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用略微剥离的代码,您可以通过两种方法来完成:
第一个:
在这种情况下,Navbar组件是完整的,我们将两个NAV包装在其自己的NAV组件中,并给出用户nav
className ='ms-auto '
将其推向右侧。第二个选项:
在这种情况下,您可以使用一个NAV组件,但是根据@JBatstone的评论,您需要通过给出
className ='Flex-Grow-1'来确保导航伸展到全宽度
和nav.item您要推到右侧的nav.Item获取className ='MS-AUTO'
。在这两种情况下,您都可以实现自己追随的结果,并且可以使用下拉菜单或任何您喜欢的东西!
Using slightly stripped down code, there's two ways you can do it:
The first:
In this instance the Navbar component is fullwidth and we wrap our two navs in their own Nav components and give the user nav
className='ms-auto'
to push it to the right.Second option:
In this scenario you use the one Nav component, but as per @JBatstone 's comment, you need to ensure the Nav is stretched to full-width by giving it a
className='flex-grow-1'
and the Nav.Item you want to push to the right gets aclassName='ms-auto'
.In both cases you'll achieve the result you're after, and can use Dropdown components or whatever you like!