如何解决具有多行标签的垂直中间对齐复选框
我有一个长标签,上面有一个右浮动的复选框,该复选框需要在中间与标签垂直对齐,但是我似乎无法通过不同的方式使它工作。这就是我得到的:
HTML:
<label class="checkbox-label">I travel to multiple locations - at least 5 times a yea
<input class="check-input" type="checkbox" value="6"/>
</label>
CSS:
.checkbox-label {
padding: .7rem;
border: 1px solid #F5F5F6;
background-color: #F5F5F6;
border-radius: 4px;
font-weight: 900;
width: 100%;
text-align: start;
color: #525159;
font-size: 1rem;
}
.check-input {
float: right;
margin-top: 5px;
width: 20px;
height: 20px;
cursor: pointer;
}
我要实现的目标如下-复选框始终垂直居中对齐标签,无论它有多少行:
任何建议都值得赞赏...
解决方法
您只需将checkBox
和label
包裹在div
中,然后使用flex和其他flex properties
来确保其vertically
位于中间center
,位于内容(标签)大小的复选框regardless
上。
建议改用Flex
,而不是代替,将float
属性用作flex在现代浏览器和
实时演示:
responsive
.checkbox-label {
border-radius: 4px;
padding: .7rem;
font-weight: 900;
background-color: #F5F5F6;
text-align: start;
color: #525159;
font-size: 1rem;
}
.check-input {
margin-top: 5px;
cursor: pointer;
}
.checkboxxxxx {
display: flex;
justify-content: space-between;
align-items: center;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。