html - 将 2 个输入文本框并排放置

标签 html css

我在网上找到了以下带有 css 的表单,我正在尝试对其进行修改,以便能够将 2 个输入框并排放置。我非常轻微地修改了代码并且它们彼此相邻但它们看起来没有对齐并且我无法弄清楚如何修复该部分。很感谢任何形式的帮助。我还附上了一张图片以显示我运行代码时的样子。 enter image description here

.form-style-5 {
  max-width: 900px;
  padding: 10px 20px;
  background: #f4f7f8;
  margin: 10px auto;
  padding: 20px;
  background: #f4f7f8;
  border-radius: 8px;
  font-family: Georgia, "Times New Roman", Times, serif;
}

.form-style-5 fieldset {
  border: none;
}

.form-style-5 legend {
  font-size: 1.4em;
  margin-bottom: 10px;
}

.form-style-5 label {
  display: block;
  margin-bottom: 8px;
}

.form-style-5 input[type="text"],
.form-style-5 input[type="date"],
.form-style-5 input[type="datetime"],
.form-style-5 input[type="email"],
.form-style-5 input[type="number"],
.form-style-5 input[type="search"],
.form-style-5 input[type="time"],
.form-style-5 input[type="url"],
.form-style-5 textarea,
.form-style-5 select {
  font-family: Georgia, "Times New Roman", Times, serif;
  background: rgba(255, 255, 255, .1);
  border: none;
  border-radius: 4px;
  font-size: 16px;
  margin: 0;
  outline: 0;
  padding: 7px;
  width: 50%;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  background-color: #e8eeef;
  color: #8a97a0;
  -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
  margin-bottom: 30px;
}

.form-style-5 input[type="text"]:focus,
.form-style-5 input[type="date"]:focus,
.form-style-5 input[type="datetime"]:focus,
.form-style-5 input[type="email"]:focus,
.form-style-5 input[type="number"]:focus,
.form-style-5 input[type="search"]:focus,
.form-style-5 input[type="time"]:focus,
.form-style-5 input[type="url"]:focus,
.form-style-5 textarea:focus,
.form-style-5 select:focus {
  background: #d2d9dd;
}

.form-style-5 select {
  -webkit-appearance: menulist-button;
  height: 35px;
}

.form-style-5 .number {
  background: #1abc9c;
  color: #fff;
  height: 30px;
  width: 30px;
  display: inline-block;
  font-size: 0.8em;
  margin-right: 4px;
  line-height: 30px;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
  border-radius: 15px 15px 15px 0px;
}

.form-style-5 input[type="submit"],
.form-style-5 input[type="button"] {
  position: relative;
  display: block;
  padding: 19px 39px 18px 39px;
  color: #FFF;
  margin: 0 auto;
  background: #1abc9c;
  font-size: 18px;
  text-align: center;
  font-style: normal;
  width: 100%;
  border: 1px solid #16a085;
  border-width: 1px 1px 3px;
  margin-bottom: 10px;
}

.form-style-5 input[type="submit"]:hover,
.form-style-5 input[type="button"]:hover {
  background: #109177;
}
<div class="form-style-5">
  <form>
    <fieldset>
      <legend><span class="number">1</span>Contact Info</legend>
      <input style="float:left;" type="text" name="field1" placeholder="Your Name *">
      <input style="float:right;" type="email" name="field2" placeholder="Your Email *">
      <textarea name="field3" placeholder="About yourself"></textarea>
      <label for="job">Interests:</label>
      <select id="job" name="field4">
<optgroup label="Indoors">
  <option value="fishkeeping">Fishkeeping</option>
  <option value="reading">Reading</option>
</optgroup>
</select>
    </fieldset>
    <input type="submit" value="Apply" />
  </form>
</div>

最佳答案

你可以这样使用:

Demo

HTML

<div>
    <label>Field 1</label>
    <input type="text" />
</div>
<div>
    <label>Field 2</label>
    <input type="text" />
</div>

CSS

div {
    display: inline-block;
}

div label {
    display: block;
}

通过使用此示例,您应该能够使用自己的代码执行相同的操作。

关于html - 将 2 个输入文本框并排放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51119025/

相关文章:

javascript - 以移动为中心的 Bootstrap 导航栏品牌

javascript - 突出显示滚动条上的菜单项

html - 使兄弟元素采用相同的宽度会破坏其中的文本

javascript - Ghost Blog 为页面的菜单项提供当前类

javascript - 根据可见程度更改 DIV 不透明度

html - 仅使用 .css 编辑更改 <div> 位置

javascript - 在输入字段中捕获 <Enter> 按下多次触发

html - 如何避免 Safari 将 -apple-system-blue 添加到我的按钮

javascript - 如何在每个用户每天点击 2 次后禁用 <div>

php - 在 php 中包含一个 flash 文件(.swf)