<分区>
我尝试使用 flex 布局来制作登录内容,它就像一个图标和一个输入排成一行。我用图标和输入的 width:100%
设置了 width:20px
和 height:20px
。我认为它将输入覆盖除特定值之外的所有剩余宽度。结果是图标的大小改变了。
随着对flex
的进一步了解,我知道了另一种实现方式,比如flex:1
with input or setting min-width/height
图标,但我只想知道为什么 width:100%
会影响同级图标的大小。
.parent {
width: 72%;
height: 100px;
border: 1px solid lightblue;
display: flex;
align-items: center;
}
.icon {
width: 20px;
height: 20px;
border: 2px solid green;
display: block;
}
.login {
width: 100%;
}
.login::placeholder {
width: 91px;
}
<div class="parent">
<div class="icon"></div>
<input class="login" placeholder="place input your invite code" />
</div>
此时.icon
的大小变成了23.33*24
,width
和height
都变了.