html - 更改图像的边距值未生效

标签 html css margin

问题:

  • 我让导航栏图片的边距值为 0px 8.14% 0px 8.14%
  • 现在我发现图片比我高 屏幕上,它在右侧制作了一个滚动条,出于某种原因 最后导航转到下一行。
  • 当我尝试将边距值更改为 0px 8% 0px 8% 时,它可以正常保存和上传,但是当 我检查检查菜单中的值(这就是所谓的吗?) 它仍然是旧值。

幻灯片中的图像只是用于测试功能的随机图像,而不是我正在使用的图像。 此外,不要做邪恶的 Stack 事情,你能告诉我我做错了什么吗?

我想我必须展示我的代码。

HTML:

<div id="nav">
    <a href=index.html>    
    <img class="navimg" id="homeimg" src=Images/Home.png alt="Home"></a>
<a href=Webpages/about.html>
    <img class="navimg" id="aboutimg" src=Images/About.png alt="About"></a>
<a href=Webpages/contact.html>
    <img class="navimg" id="contactimg" src=Images/Contact.png alt="Contact"></a>
<a href=Webpages/extlinks.html>
    <img class="navimg" id="extimg" src=Images/External.png alt="External"></a>
    </div>

CSS:

body {
    width: 100%;
    height: 100%;
    margin: 0%;
}
#nav {
    width: 100%;
    min-height: 6%;
    max-height: 6%;
    background-color: #3C3C8D;
.navimg {
    height:100%;
    float:left;
    margin: 0px 8% 0px 8%;
    padding: 0px 0px 0px 0px;
}

完整代码位于 http://jsfiddle.net/1s3byt56/我的网站是http://weeklyrandomthing.000webhostapp.com/ 非常感谢

编辑: 我正在使用 FileZilla 上传到 FTP 服务器 (files.000webhost.com:21) 和 Notepad++ 来编辑代码。当我上传时,所有传输都正常,但实际网站似乎没有更新,即使随着时间的推移也是如此。我应该问另一个问题来解决这个问题吗?

编辑 2: 是的,我现在准备删除这个问题,但我做不到。这里列出的问题甚至不是问题。我的网站只是没有更新。和平。

最佳答案

尝试使用 flexbox 并为 #nav 定义高度。这个地方的百分比值使结果不可预测。

body {
    width: 100%;
    height: 100%;
    margin: 0%;
}
#nav {
    display: flex;
    justify-content: space-around;
    width: 100%;
    height: 10em;
    background-color: #3C3C8D;
}
#nav a {
  display: flex;
  justify-content: center;
}
.navimg {
    display:block;
    height:100%;
    width: auto;
    margin: 0 auto;
}
<div id="nav">
    <a href=index.html>    
        <img class="navimg" id="homeimg" src="https://source.unsplash.com/400x300/?nature" alt="Home">
    </a>
    <a href=Webpages/about.html>
        <img class="navimg" id="aboutimg" src="https://source.unsplash.com/400x300/?urban" alt="About">
    </a>
    <a href=Webpages/contact.html>
        <img class="navimg" id="contactimg" src="https://source.unsplash.com/400x300/?animals" alt="Contact">
    </a>
    <a href=Webpages/extlinks.html>
        <img class="navimg" id="extimg" src="https://source.unsplash.com/400x3007?sea" alt="External">
    </a>
</div>

关于html - 更改图像的边距值未生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51783402/

相关文章:

javascript - 单击时折叠行

css - Internet Explorer 7 & 8 边距显示问题

css - 想要居中一个div

html - 宽屏幕上的 CSS float 对齐不均匀

javascript - 处理选择列表、单选按钮和复选框的 jQuery 方式

javascript - 保留点击功能以在稍后的事件中启动

javascript - 不显示时如何为div添加时间延迟

css - 如何在高度变化时调整 div 相对于其上方 div 的位置?

html - 简单的 100% CSS 高度示例不起作用,请有人帮忙

c# - 如何在 Silverlight 中动态设置复选框边距