有没有办法将Navbar中的三个项目对齐(左,右和中间)?

发布于 2025-02-12 04:50:07 字数 1747 浏览 2 评论 0原文

因此,我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

饭团 2025-02-19 04:50:08

我一直在做的是在纳维托中创建三个部分。
看起来像这样:

<div className={styles.container}>
    <div className={styles.left}>
       // Content here
    </div>
    <div className={styles.middle}>
       // Content here
    </div>
    <div className={styles.right}>
       // Content here
    </div>
</div>

您的CSS看起来像这样。

.container {
  display: flex;
}

.left {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.middle { 
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.right {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

通过使用flex:1,我们在容器内创建了三个同等大小的框。
您可以根据自己的喜好对所有盒子进行样式的样式。

What I always do is create three sections in the navbar.
This would look something like this:

<div className={styles.container}>
    <div className={styles.left}>
       // Content here
    </div>
    <div className={styles.middle}>
       // Content here
    </div>
    <div className={styles.right}>
       // Content here
    </div>
</div>

your CSS would look like this.

.container {
  display: flex;
}

.left {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.middle { 
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.right {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

By using flex: 1 we create three equally sized boxes inside the container.
You can style all boxes differently depending on your preferences.

够运 2025-02-19 04:50:08

只需添加Align-Items:Center;josify-content:Space-between; toemander

Just add align-items: center; and justify-content: space-between; to the container

咽泪装欢 2025-02-19 04:50:08
export default function Navbar() {
return (
    <div className={styles.container}>
        <div className={styles.navLogo}>shop</div>
        <div className={styles.navSearchBar}>
            <input type='text' className={styles.searchBarInput} />

        </div>
        <div className={styles.navProfileShoppingContainer}>
            <div><a>
                <Image
                src={ProfileIcon}
                height={35}
                width={35}
                alt="profileIcon" 
                />
            </a></div>
            <div><a>
                <Image
                src={ShoppingCartIcon}
                height={32}
                width={40}
                alt='searchIcon'
                />
            </a></div>
        </div>
    </div>
)

}

export default function Navbar() {
return (
    <div className={styles.container}>
        <div className={styles.navLogo}>shop</div>
        <div className={styles.navSearchBar}>
            <input type='text' className={styles.searchBarInput} />

        </div>
        <div className={styles.navProfileShoppingContainer}>
            <div><a>
                <Image
                src={ProfileIcon}
                height={35}
                width={35}
                alt="profileIcon" 
                />
            </a></div>
            <div><a>
                <Image
                src={ShoppingCartIcon}
                height={32}
                width={40}
                alt='searchIcon'
                />
            </a></div>
        </div>
    </div>
)

}

尐籹人 2025-02-19 04:50:08
.container {
    display: flex;
}
.navProfileShoppingContainer {
    display:flex;
    float: right;
    background-color: #E5B3B3;
    gap : 30px
    justify-content: center;
    border-radius: 10px;
    width: 130px;
    height: 50px;
}
.navLogo {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-size: 36px;
    line-height: 48px;
    color: #CF7E7E;
    
}

.container {
    display: flex;
}
.navProfileShoppingContainer {
    display:flex;
    float: right;
    background-color: #E5B3B3;
    gap : 30px
    justify-content: center;
    border-radius: 10px;
    width: 130px;
    height: 50px;
}
.navLogo {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-size: 36px;
    line-height: 48px;
    color: #CF7E7E;
    
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文