html - 如何让输入框有一定的长度?

标签 html css alignment

所以我有这个 HTML/CSS,

input {
  box-shadow: 2px 4px 25px rgba(0, 0, 0, .1);
  height: 35px;
  width: 400px;
  overflow: hidden;
  border: none;
  padding-left: 10px;
  background-color: rgba(240, 240, 240);
  margin-right: 30px;
  overflow: hidden;
}
label {
  margin: 30px;
}
<p><label for="mobTag"><strong>Mob Tag</strong> = <input type="text" id="mobTag" placeholder="My Mob" name="mobTag"></label></p>

<p><label for="chestName"><strong>Chest Name</strong> = <input type="text" id="chestName" placeholder="empty" name="chestName"></label></p>
正如您所看到的,标签很好地对齐,但我试图让 input 的结尾也对齐。我尝试增加 width,希望 margin-right 会 overflow hidden ,但它只是将标签推到一行。 谁能帮忙?

最佳答案

使用 flex:

p {width:50%; margin:1rem auto}

input {
  box-shadow: 2px 4px 25px rgba(0, 0, 0, .1);
  height: 35px;
  border: none;
  margin-left:.5rem;
  padding-left: 10px;
  background-color: rgba(240, 240, 240);
  flex:1 0;
}

label {
  display: flex;
  align-items:center;
  margin: 30px;
}

strong {
  flex: 0 0 auto;
  margin-right:.5rem;
}
<p><label for="mobTag"><strong>Mob Tag</strong> = <input type="text" id="mobTag" placeholder="My Mob" name="mobTag"></label></p>

<p><label for="chestName"><strong>Chest Name</strong> = <input type="text" id="chestName" placeholder="empty" name="chestName"></label></p>

关于html - 如何让输入框有一定的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53451238/

相关文章:

css - 显示 : inline-block height

javascript - 如何在 AngularJS 的 HTML 中保留复杂的表达式?

javascript - 有 2 个粘性 header ,一个可以切换,一个不切换

javascript - 如何在 jquery 中重新启用按钮悬停

javascript - 图像在 IE8 中不渲染

javascript - 如何在用户单击饼图时隐藏其余区域?

html - 边界半径圆

javascript - 为什么 ContentEditable 在 Firefox 中很糟糕

Internet Explorer 中的 CSS 定位

html - li 和 p 水平对齐