html - Bootstrap 列中的垂直对齐项目
问题描述
希望一个容易解决的问题。见下图,我无法让切换开关与引导按钮水平对齐。我怀疑这可能与此自定义切换开关的 CSS 有关。我在剃须刀页面上的代码中尝试过的任何操作都没有任何影响。谢谢
剃刀页面代码:
<div class="container" style="margin-top: 2em">
<div class="row align-items-center">
<div class="col-sm">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<div class="col-sm">
<button type="button" class="btn btn-secondary">
Button
<i class="fas fa-play"></i>
</button>
</div>
<div class="col-sm">
<button type="button" class="btn btn-secondary">
Button
<i class="fas fa-play"></i>
</button>
</div>
</div>
切换开关的自定义 CSS
.onoffswitch {
position: relative;
width: 70px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 0px;
}
.onoffswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block;
float: left;
width: 50%;
height: 24px;
padding: 0;
line-height: 20px;
font-size: 14px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
border: 2px solid transparent;
background-clip: padding-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 5px;
background-color: #383B40;
color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 5px;
background-color: #383B40;
color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 30px;
margin: 0px;
background: #FF0000;
position: absolute;
top: 0;
bottom: 0;
right: 40px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
background-color: #00FF00;
}
解决方案
你可以使用 css hack,看看下面的代码
html:
<div id="parent">
<div id="child">Content here</div>
</div>
css:
#parent {display: table}
#child {
display: table-cell;
vertical-align: middle;
}
推荐阅读
- facebook - 在 API 和应用程序中使用 Whatsapp Business API 编号
- python - 当迭代 for 循环与运行一次时,代码会产生不同的结果
- azure - Azure CDN 从后端获取数据
- deep-learning - 为什么 MSE 损失比分类交叉熵更适用于多类分类问题?
- github - 使用私钥/公钥对将 Netbeans 连接到 gitHub 时出现问题
- c# - 来自 intPtr 的 for 循环,如何?
- docker - 如何从 docker 容器内运行的服务中查找客户端源 IP 地址
- docker - Docker Swarm - 是否有只读模式?
- arrays - Perl:以分割线元素为键读取哈希
- java - 查找内部列表列表的平均值
- > 使用 Stream 并以 List 形式返回结果
由内部列表的平均值组成