【问题标题】:Placing checkbox below input box (styling)在输入框下方放置复选框(样式)
【发布时间】:2021-06-07 03:51:15
【问题描述】:

我试图在文本输入框下方放置一个复选框,但我的 InputBar 没有占据整个父宽度,并且复选框出现在 InputBar 的末尾。 我是前端newbea,有人可以建议我可以更改什么以将复选框放在输入栏下方。

我的样式代码:

.background {
  background-image: url("../Back.jpg");
  background-repeat: no-repeat;
  margin: -11px -16px 0 -16px;
  background-size: 100%;
  min-height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.inputBar {
  padding-left: 30%;
  width: 100%;
  .enterButton {
    background: url("../arrowNext.svg") no-repeat center white;
    height: 50px;
    width: 35px;
    border-top-right-radius: 100px;
    border-bottom-right-radius: 100px;
    vertical-align: top;
  }
  .enterText {
    color: $primary-text-color-light;
    width: 60%;
    height: 50px;
    border-top-left-radius: 100px;
    border-bottom-left-radius: 100px;
    display: inline-block;
    vertical-align: top;
    padding-left: 2%;
  }
}

.check {
  display: inline-block;
  .checkBox {
    width: 40px;
    height: 20px;
    background: #555;
    margin: 5px;
    border-radius: 3px;
    padding-left: 30%;
  }
  .checkBoxText {
    font-weight: bold;
    font-size: larger;
    color: grey;
    background-color: whitesmoke;
  }
}
<div class="background">
  <div class="inputBar">
    <input class="enterText" id="inputBox" type="text" placeholder="Enter something" />
    <button class="enterButton">Enter</button>
  </div>
  <div class="check">
    <input class="checkBox" type="checkbox" defaultChecked/>
    <span class="checkBoxText">Check this</span>
  </div>
</div>

【问题讨论】:

  • 可以在InputBar后面加一个
    吗?

标签: html css flexbox css-position


【解决方案1】:

默认情况下,flex 将方向设置为 row。
你可以设置flex-direction: column来实现你想要的。

.container {
  display: flex;
  flex-direction: column;
}
<div class="container">
  <div>
    <input type="text" />
    <button>Enter</button>
  </div>
  <div>
    <input type="checkbox" id="check-this" />
    <label for="check-this">Check this</label>
  </div>
</div>

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2017-05-08
    • 2014-03-04
    • 2014-07-14
    • 1970-01-01
    相关资源
    最近更新 更多