css 在flexbox中时,input type=“number”未与input=“checkbox”对齐

vlju58qv  于 2023-04-08  发布在  其他
关注(0)|答案(3)|浏览(129)

目前,input=“number”位于flexbox的右上角。当我将它从input=“number”更改为input=“checkbox”时,它会对齐。如何使它在input=“number”时与其余复选框对齐?

body {
  background-color : #6d6875;
  font-family      : 'Open Sans', sans-serif;
  }
#options-div {
  background-color : #b5838d;
  margin           : 200px auto;
  padding          : 20px;
  width            : 350px;
  text-align       : center;
  border           : 2px solid white;
  }
#password-output {
  width  : 200px;
  }
#num-box {
  width  : 30px;
  height : 30px;
  }
.options {
  display         : flex;
  justify-content : space-between;
  border          : 2px solid black;
  }
<div id="options-div">
  <h1>Password generator</h1>
  <input id="password-output" type="number">
  <div class="options">
    <p>Password length</p>
    <input id="num-box" type="number">
  </div>
  <div class="options">
    <p>Include uppercase letters</p>
    <input type="checkbox">
  </div>
</div>
swvgeqrz

swvgeqrz1#

.options {
  display         : flex;
  justify-content : space-between;
  border          : 2px solid black;
  align-items     : center;
  }
yqyhoc1h

yqyhoc1h2#

这样,每个选项的输入框将位于文本的右侧。通过更改元素的宽度或添加填充或边距,您可以更改文本和输入框之间的距离。

#options-div {
 display: flex;
 justify-content: space-between;
 align-items: center; /* This line is optional and can be used to 
 vertically center the items */
 border: 2px solid black;
}
body {
  background-color : #6d6875;
  font-family      : 'Open Sans', sans-serif;
  }
#options-div {
  display: flex;
  justify-content: space-between;
  align-items: center; /* This line is optional and can be used to 
  vertically center the items */
  border: 2px solid black;
  }
#password-output {
  width  : 200px;
  }
#num-box {
  width  : 30px;
  height : 30px;
  }
.options {
  display         : flex;
  justify-content : space-between;
  border          : 2px solid black;
  }
<div id="options-div">
  <h1>Password generator</h1>
  <input id="password-output" type="number">
  <div class="options">
    <p>Password length</p>
    <input id="num-box" type="number">
  </div>
  <div class="options">
    <p>Include uppercase letters</p>
    <input type="checkbox">
  </div>
</div>
atmip9wb

atmip9wb3#

试着去做:将<p>更改为<label>,并在display: flex中添加justify-content: space-betweenalign-items: center
在这种情况下,align-items将对齐行center中的内容。

body {
  background-color : #6d6875;
  font-family      : 'Open Sans', sans-serif;
}
#options-div {
  background-color : #b5838d;
  margin           : 200px auto;
  padding          : 20px;
  width            : 350px;
  text-align       : center;
  border           : 2px solid white;
}
#password-output {
  width  : 200px;
}
#num-box {
  width  : 30px;
  height : 30px;
}
.options {
  width           : 100%;
  min-height      : 30px;
  display         : flex;
  align-items     : center;
  justify-content : space-between;
  border          : 2px solid black;
}
<div id="options-div">
  <h1>Password generator</h1>
  <input id="password-output" type="number">
  <div class="options">
    <label>Password length</label>
    <input id="num-box" type="number">
  </div>
  <div class="options">
    <label>Include uppercase letters</label>
    <input type="checkbox">
  </div>
</div>

希望我帮到你了!

相关问题