有没有办法将Navbar中的三个项目对齐(左,右和中间)?
因此,我正在尝试在ReactJ和CSS中实现这种外观。这是代码:
export default function Navbar() {
return (
<div className={styles.container}>
<p className={styles.navLogo}>shopr</p>
<div className={styles.navSearchBar}>
<input type='text' className={styles.searchBarInput} />
</div>
<div className={styles.navProfileShoppingContainer}>
<a>
<Image
src={ProfileIcon}
height={35}
width={35}
alt="profileIcon"
/>
</a>
<a>
<Image
src={ShoppingCartIcon}
height={32}
width={40}
alt='searchIcon'
/>
</a>
</div>
</div>
)
}
这是CSS:
.container {
display: flex;
}
.navProfileShoppingContainer {
float: right;
background-color: #E5B3B3;
padding: 5px;
justify-content: center;
border-radius: 10px;
width: 130px;
height: 50px;
}
.navProfileShoppingContainer a {
margin: 10px;
}
.navLogo {
font-family: 'Inter';
font-style: normal;
font-weight: 500;
font-size: 36px;
line-height: 48px;
color: #CF7E7E;
}
这是看起来我正在尝试实现vs vs vs 看起来如何 我遇到的主要问题是Flex,因为Float在父级上无法使用它。 〜 任何帮助都将不胜感激。谢谢!
so I am trying to achieve this look in ReactJS and CSS. Here is the code:
export default function Navbar() {
return (
<div className={styles.container}>
<p className={styles.navLogo}>shopr</p>
<div className={styles.navSearchBar}>
<input type='text' className={styles.searchBarInput} />
</div>
<div className={styles.navProfileShoppingContainer}>
<a>
<Image
src={ProfileIcon}
height={35}
width={35}
alt="profileIcon"
/>
</a>
<a>
<Image
src={ShoppingCartIcon}
height={32}
width={40}
alt='searchIcon'
/>
</a>
</div>
</div>
)
}
Here is the css:
.container {
display: flex;
}
.navProfileShoppingContainer {
float: right;
background-color: #E5B3B3;
padding: 5px;
justify-content: center;
border-radius: 10px;
width: 130px;
height: 50px;
}
.navProfileShoppingContainer a {
margin: 10px;
}
.navLogo {
font-family: 'Inter';
font-style: normal;
font-weight: 500;
font-size: 36px;
line-height: 48px;
color: #CF7E7E;
}
And this is the look I'm trying to achieve vs how it looks
The main problem I'm having is with flex as float doesn't work with it on a parent div.
~
Any help would be much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我一直在做的是在纳维托中创建三个部分。
看起来像这样:
您的CSS看起来像这样。
通过使用
flex:1
,我们在容器内创建了三个同等大小的框。您可以根据自己的喜好对所有盒子进行样式的样式。
What I always do is create three sections in the navbar.
This would look something like this:
your CSS would look like this.
By using
flex: 1
we create three equally sized boxes inside the container.You can style all boxes differently depending on your preferences.
只需添加
Align-Items:Center;
和josify-content:Space-between;
toemanderJust add
align-items: center;
andjustify-content: space-between;
to the container}
}