我目前的问题是,margin-right
不再适用于 width: 100%
。
我已经尝试过关闭 width: 100%
,更改位置等。
但没有任何效果。我在互联网上看到的所有问题和答案都没有帮助我。我试了很多。如果没有 width: 95%
之类的东西,它真的能工作吗?我错过了什么吗?
<body>
<div class="content" id="id_content">
<div class="topbar-header">
<input type="text" class="topbar-field" style="min-width: 300px; max-width: 600px; width: 30%;">
</div>
</div>
</body>
/* The header to search and navigate on. */
.topbar-header {
position: relative;
margin: 20px;
width: 100%;
height: var(--val-head-height);
background-color: var(--color-menu-background);
}
这发生了 here, 但我想要右边的空间。
最佳答案
或者,您可以使用 width: calc(100% - value)
或仅设置父元素的填充 (.content { padding-right: 32px; }
)
/* The header to search and navigate on. */
.topbar-header {
box-sizing: border-box;
position: relative;
width: calc(100% - 64px);
height: 48px;
margin-right: 256px;
background-color: tomato;
}
<body>
<div class="content" id="id_content">
<div class="topbar-header">
<input type="text" class="topbar-field" style="min-width: 300px; max-width: 600px; width: 30%;">
</div>
</div>
</body>
关于html - margin-right 不适用于相对元素? (宽度 100%),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57135462/