【发布时间】:2018-01-12 00:18:00
【问题描述】:
Angular 项目
我有一个可在特定条件下工作的可调整大小的按钮。我的问题是我觉得我的代码应该可以工作,我会解释我有什么和预期什么。
app.component.ts
<button class="button button5"> </button>
app.component.css
.button {
background-color: #0066ff;
border: 1px solid #0066ff;
color: white;
height: 60%;
width: 60%;
margin-left: 20%;
margin-right: auto;
margin-top: 20%;
padding: 0;
}
.button5 {
border-radius: 50%;
}
index.html
<body>
<app-root>
</app-root>
</body>
index.html css
<style>
body, html {
height: 100%;
width: 100%;
margin: 0;
}
app-root {
display: block;
height: 100%;
width: 100%;
margin: 0;
}
</style>
我的目标是创建一个按钮,它始终是页面高度的 60%,距离顶部 20%。此外,宽度为 60%,距左侧 20%。
这在某些条件下非常有效,例如.Here is my goal, unresized,但是当我稍微调整它的大小时This happens。
如您所见,它不是 20%。我不知道为什么,我从来没有hard code values,而我一直是strictly using percentages,所以我认为这是万无一失的。为什么看起来顶部是 5%,底部是 35%
【问题讨论】:
-
% 总是依赖于宽度,即使是margin-top
-
为什么这被否决了这么多?我提供了代码、图片甚至是一个有效的问题。