javascript - 如何对齐 CSS 和 HTML 中的垂直文本框?

标签 javascript html css

我是前端初学者(昨天开始),我正在通过 FreeCodeCamp 学习。我正在尝试建立一个调查网站。我想将底部文本框的左侧与顶部左侧文本框的左侧对齐。我尝试更改 text-align 元素的属性,但它并不公平。如果这个问题已经被问到,我深表歉意。我无法将以前的答案与我的联系起来。

这是我的代码:

body {background-color: #98AFC7;}

#title{
  text-align: center;
  font-family: Arial, Times, serif;
  font-style: oblique;
  color: white;
}

#screen-belly{
  background-color: rgb(250, 250, 250);
  margin: 0 auto;
  border-radius: 4px;
  width: 75%%;
  max-width: 1000px;
  padding: 10px;
  padding-top: 20px;
}

p{
  text-align: center;
  font-family: monospace, serif;
  font-size: 15px;
}

.rightTab {
  display: inline-block;
  text-align: left;
  width: 48%;
  vertical-align: middle;
}

.leftTab {
  display: inline-block;
  text-align: right;
  width: 48%;
  vertical-align: middle;
}

.eMailTab{
  display: inline;
  text-align: right;
  width: 48%;
}

.name-fields {
  height: 20px;
  width: 140px;
  padding: 5px;
  margin: 10px;
  border: 1px solid #c0c0c0;
  border-radius: 2px;
}

.input-field {
  height: 20px;
  width: 280px;
  padding: 5px;
  margin: 10px;
  border: 1px solid #c0c0c0;
  border-radius: 2px;
}
<h1 id="title">Survey Form</h1>

<div id="screen-belly">
  <p>Please take the short Survey to hep us improve our services</p>

  <div class="rowTab">
      <div class="leftTab">
        <input autofocus type="text" name="name" id="name" class="name-fields" placeholder="First name" required>
      </div>
      <div class="rightTab">
        <input autofocus type="text" name="name" id="name" class="name-fields" placeholder="Last Name" required>
      </div>
    </div>

      <div class="eMailTab">
        <input autofocus type="text" name="email" id="email" class="input-field" placeholder="e-Mail address" required>
      </div>
    </div>
</div>

   

这是我的 CodePen 链接,您可以看到我在说什么:

https://codepen.io/omaroz92/full/VBWbae/

最佳答案

您可以使用 flexbox轻松实现这一目标。我稍微更改了您的 HTML 和 CSS 以使其工作。

body {
  background-color: #98AFC7;
}

#title {
  text-align: center;
  font-family: Arial, Times, serif;
  font-style: oblique;
  color: white;
}

#screen-belly {
  background-color: rgb(250, 250, 250);
  margin: 0 auto;
  border-radius: 4px;
  width: 75%;
  max-width: 1000px;
  padding: 10px;
  padding-top: 20px;
}

p {
  text-align: center;
  font-family: monospace, serif;
  font-size: 15px;
}

.container {
  width: 75%;
  max-width: 600px;
  margin: 0 auto;
}

.row {
  display: flex;
}

input {
  flex: 1;
  height: 20px;
  min-width: 0;
  padding: 5px;
  margin: 10px;
  border: 1px solid #c0c0c0;
  border-radius: 2px;
}
<h1 id="title">Survey Form</h1>

<div id="screen-belly">
  <p>Please take the short Survey to hep us improve our services</p>

  <div class="container">
    <div class="row">
      <input autofocus type="text" name="name" id="name" placeholder="First name" required>
      <input type="text" name="name" id="name" placeholder="Last Name" required>
    </div>
    <div class="row">
      <input type="text" name="email" id="email" placeholder="e-Mail address" required>
    </div>
  </div>
</div>

关于javascript - 如何对齐 CSS 和 HTML 中的垂直文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51715696/

相关文章:

css - Html/Css 中 DIV 标签的问题

css - 缩放与变换比例

jquery - 无法使用 jQuery 删除 css 属性

css - 模糊网站背景的 mp4 视频

php - 使用 PHP 显示 Mysql 数据给我一个空白页面

javascript - 如何使用javascript获取所有HTML表单数据并将其保存为pdf格式?

javascript - 如何在一次查询中使用 .skip()、.limit() 和总匹配结果进行 MongoDB 文本搜索?

javascript - 在 jQuery Masked 输入中输入按键时,如何防止现有值向右移动?

javascript - 使用 jquery 悬停时显示文本

Gmail 以不同方式显示 HTML 电子邮件签名