我在nav中的徽标iSNNENNENN'使用Flexbox响应迅速

发布于 2025-02-13 12:32:06 字数 1655 浏览 2 评论 0原文

我正在尝试使用NAV创建一个Flex标头。但是,我的形象似乎没有响应。当我最小化宽度时,菜单似乎响应迅速,但我的徽标图像却没有。

当我设置具有这些特定宽度和高度的图像时(不添加属性中的任何尺寸,我遇到相同的问题)时,该图像是一个假人

body {
    margin: 0;
    margin: 0;
    width: 100%;
    display: flex;
  }

header {
    width: 100%;
    height: 91px;
    background-color: #222222;
    position: relative;
}

a {
    text-decoration: none;
    color: #fff;
    font-size: 15px;
    line-height: 17.22px;
}

ul {
    list-style: none;
}

nav {
    display: flex;
    justify-content: space-between;
}

nav ul {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 280px;
}

li {
    margin-left: 35px;
}

 nav img {
    display: flex;
    margin-left: 254px;
    position: relative;
}
<body>
    <header>
        <nav>
            <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
        
            <ul>
                <li style="margin-left:0;"><a href="#">Hompage</a></li>
                <li><a href="#">About us</a></li>
                <li><a href="#">Our Services</a></li>
                <li><a href="#">Projects</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </header>
</body>

I'm trying to create a flex header with nav. However, my image doesn't seem to be responsive. As I'm minimizing the width the menu seems to act responsive but my logo image doesn't.

The image is a dummy one, when i set an image with these certain width and height (without adding any dimensions in property i have the same issue)

How can i solve this?

body {
    margin: 0;
    margin: 0;
    width: 100%;
    display: flex;
  }

header {
    width: 100%;
    height: 91px;
    background-color: #222222;
    position: relative;
}

a {
    text-decoration: none;
    color: #fff;
    font-size: 15px;
    line-height: 17.22px;
}

ul {
    list-style: none;
}

nav {
    display: flex;
    justify-content: space-between;
}

nav ul {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 280px;
}

li {
    margin-left: 35px;
}

 nav img {
    display: flex;
    margin-left: 254px;
    position: relative;
}
<body>
    <header>
        <nav>
            <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
        
            <ul>
                <li style="margin-left:0;"><a href="#">Hompage</a></li>
                <li><a href="#">About us</a></li>
                <li><a href="#">Our Services</a></li>
                <li><a href="#">Projects</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </header>
</body>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

沙与沫 2025-02-20 12:32:06

保留纵横比:

img {
  height: 91px;
  width: auto;
}

Preserve aspect ratio:

img {
  height: 91px;
  width: auto;
}
愿得七秒忆 2025-02-20 12:32:06

请检查您需要添加高度的代码:91px; object-fit:into logo image中的; in logo image and set max-width以响应您需要添加媒体查询我在代码中提到,以便您检查它。

body {
    margin: 0;
    margin: 0;
    width: 100%;
    display: flex;
    flex-direction:column;
  }

header {
    width: 100%;
    padding: 10px 0;
    background-color: #d2d2d2;
    position: relative;
}

a {
    text-decoration: none;
    color: #000;
    font-size: 15px;
}

ul {
    list-style: none;
  padding:0;
  margin:0;
}

nav {
    display: flex;
    justify-content: space-between;
  padding:0 5%;
}

nav ul {
    display: flex;
    justify-content: center;
    align-items: center;
}

li {
    margin-right: 35px;
}
li:last-child {
    margin-right:0px;
}

nav img {
    display: flex;
    position: relative;
    height: 91px;
    object-fit: contain;
    width: 100%;
    max-width: 100px;
}

@media screen and (max-width:575px){
  nav{flex-direction:column;}
  nav ul {
    display: flex;
    justify-content: left;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
}
}
<body>
    <header>
        <nav>
            <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
        
            <ul>
                <li style="margin-left:0;"><a href="#">Hompage</a></li>
                <li><a href="#">About us</a></li>
                <li><a href="#">Our Services</a></li>
                <li><a href="#">Projects</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </header>
</body>

please check the code you need to add height: 91px; object-fit: contain; in logo image and set max-width for responsive you need to add media query I have mention in code so you can check it.

body {
    margin: 0;
    margin: 0;
    width: 100%;
    display: flex;
    flex-direction:column;
  }

header {
    width: 100%;
    padding: 10px 0;
    background-color: #d2d2d2;
    position: relative;
}

a {
    text-decoration: none;
    color: #000;
    font-size: 15px;
}

ul {
    list-style: none;
  padding:0;
  margin:0;
}

nav {
    display: flex;
    justify-content: space-between;
  padding:0 5%;
}

nav ul {
    display: flex;
    justify-content: center;
    align-items: center;
}

li {
    margin-right: 35px;
}
li:last-child {
    margin-right:0px;
}

nav img {
    display: flex;
    position: relative;
    height: 91px;
    object-fit: contain;
    width: 100%;
    max-width: 100px;
}

@media screen and (max-width:575px){
  nav{flex-direction:column;}
  nav ul {
    display: flex;
    justify-content: left;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
}
}
<body>
    <header>
        <nav>
            <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
        
            <ul>
                <li style="margin-left:0;"><a href="#">Hompage</a></li>
                <li><a href="#">About us</a></li>
                <li><a href="#">Our Services</a></li>
                <li><a href="#">Projects</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </header>
</body>

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