【问题标题】:Center text besides custom textbox自定义文本框之外的中心文本
【发布时间】:2017-01-27 23:45:09
【问题描述】:

我有一个自定义样式的复选框,请参阅此 JSFiddle:

https://jsfiddle.net/y58zrd4m/

我的 HTML 如下所示:

<label class="checkbox">
  <input type="checkbox" />
  <span>Lorem ipsum</span>
</label>

现在我希望我的文本相对于复选框垂直居中,我该如何实现?

【问题讨论】:

标签: html css web sass


【解决方案1】:

您的 CSS 中的一些更改将帮助您实现:

代码片段

.checkbox {
  cursor: pointer;
  position: relative;
}
.checkbox input[type="checkbox"] {
  display: none;
}
.checkbox span {
  font-size: 20px;
  display: inline-block;
  padding: 10px 0 0 40px;
}
.checkbox span:before {
  content: "";
  display: inline-block;
  width: 25px;
  height: 25px;
  border: 2px solid rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  margin: 0;
  position: absolute;
  left: 2px;
  top: -7px;
}
.checkbox span:after {
  content: "";
  display: none;
  position: absolute;
  left: 12px;
  top: -2px;
  width: 5px;
  height: 13px;
  border-bottom: 4px solid white;
  border-right: 4px solid white;
  border-radius: 1px;
  transform: rotate(30deg);
}
.checkbox input[type="checkbox"]:checked + span:before {
  border-color: #03a9f4;
  background-color: #03a9f4;
}
.checkbox input[type="checkbox"]:checked + span:after {
  display: inline-block;
}
<label class="checkbox">
  <input type="checkbox" />
  <span>Lorem ipsum</span>
</label>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 2013-06-29
    相关资源
    最近更新 更多