[英]How to align <label> and text side by side in html
I have a label and a text. 我有一个标签和一个文本。 How can I align them side by side horizontally?
如何将它们水平并排对齐?
Currently is text is aligned at the bottom of label (as in the image). 当前文本在标签底部对齐(如图所示)。 I would like to align text to the center of the label.
我想对齐文本标签的中心。
My html code is 我的html代码是
<div>
<label class="switchnmn">
<input type="checkbox" checked>
<div class="slidernmn round"></div>
</label>
<b style="font-size:15px">I am able to accept customer's any request date.</b>
</dlv>
My css file is 我的css文件是
.switchnmn {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switchnmn input {display:none;}
.slidernmn {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slidernmn:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slidernmn {
background-color: #2196F3;
}
input:focus + .slidernmn {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slidernmn:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slidernmn.round {
border-radius: 34px;
}
.slidernmn.round:before {
border-radius: 50%;
}
Where should I change that? 我应该在哪里更改?
You can add vertical-align: middle
on label and b element. 您可以在标签和b元素上添加
vertical-align: middle
。
.switchnmn { position: relative; display: inline-block; width: 60px; height: 34px; } .switchnmn input {display:none;} .slidernmn { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; } .slidernmn:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; } input:checked + .slidernmn { background-color: #2196F3; } input:focus + .slidernmn { box-shadow: 0 0 1px #2196F3; } input:checked + .slidernmn:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px); } /* Rounded sliders */ .slidernmn.round { border-radius: 34px; } .slidernmn.round:before { border-radius: 50%; } label, b { vertical-align: middle; }
<div> <label class="switchnmn"> <input type="checkbox" checked> <div class="slidernmn round"></div> </label> <b style="font-size:15px">I am able to accept customer's any request date.</b> </div>
Define all three elements as display: inline-block;
将所有三个元素定义为
display: inline-block;
and vertical-align: middle;
vertical-align: middle;
as shown below: 如下所示:
.x > * { display: inline-block; vertical-align: middle; } .switchnmn { position: relative; display: inline-block; width: 60px; height: 34px; } .switchnmn input { display: none; } .slidernmn { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; } .slidernmn:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; } input:checked+.slidernmn { background-color: #2196F3; } input:focus+.slidernmn { box-shadow: 0 0 1px #2196F3; } input:checked+.slidernmn:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px); } /* Rounded sliders */ .slidernmn.round { border-radius: 34px; } .slidernmn.round:before { border-radius: 50%; }
<div class="x"> <label for="y" class="switchnmn"> <input type="checkbox" id="y" checked> <div class="slidernmn round"></div> </label> <b style="font-size:15px">I am able to accept customer's any request date.</b> </dlv>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.