如何在HTML和CSS中调整标签和输入字段之间的间距

cnh2zyt3  于 2023-07-01  发布在  其他
关注(0)|答案(2)|浏览(89)

我在尝试创造这样的设计

我试着添加一个边距和填充,但它不起作用。
我试图在标签和输入之间添加一个空格,但它也不起作用。

div.register {
  background-color: white;
  width: 100%;
  height: 400px;
  border-radius: .5rem;
  width: 300px;
}

.register input {
  width: 250px;
  border-radius: 1rem;
  margin-left: 8px;
}
<section class="home show-animate" id="home">
  <div class="content">
    <span>Take The Right Step <br>For Your Business</span>
    <p>Tax associate is a leading consultancy firm that provides <br> simple, effective company registration and accounting <br> solutions to enterprises in ireland.</p>
    <a href="#" class="btn">Get Started</a>
  </div>

  <div class="main">
    <div class="register">
      <h3>Apply for Tax Rebate Now</h3>
      <form action="" id="register" method="post">
        <div class="wrapper">
                    <label for="" >Name</label>
                    <div>
                      <input type="text" name="name" id="">
                    </div>

                    <label for="" > Email ID</label>
                    <div>
                        <input type="text" name="email">
                    </div>
                    <label for=""> PPS Number</label>
                    <div>
                        <input type="text" name="Email" id="">
                    </div>
                    <a href="#" class="btn">Get Started</a>
                </div>
      </form>
    </div>
  </div>
</section>
kqlmhetl

kqlmhetl1#

只需在每个输入中添加一个margin-bottom,除了最后一个:

div.register {
  background-color: white;
  width: 100%;
  height: 400px;
  border-radius: .5rem;
  width: 300px;
}

.register input {
  width: 250px;
  border-radius: 1rem;
  margin-left: 8px;
}

.register input:not(:last-child) {
  margin-bottom: 1em;
}
<section class="home show-animate" id="home">
  <div class="content">
    <span>Take The Right Step <br>For Your Business</span>
    <p>Tax associate is a leading consultancy firm that provides <br> simple, effective company registration and accounting <br> solutions to enterprises in ireland.</p>
    <a href="#" class="btn">Get Started</a>
  </div>

  <div class="main">
    <div class="register">
      <h3>Apply for Tax Rebate Now</h3>
      <form action="" id="register" method="post">
        <label for="name">Name</label>
        <input type="text" name="name" id="name">

        <label for="email" style="margin-bottom: 8px;"> Email</label>
        <input type="text" name="Email" id="email">
      </form>
    </div>
  </div>
</section>

注意,输入应该始终有一个id,这样您就可以将标签连接到它,除非您将输入嵌套在标签中。

luaexgnf

luaexgnf2#

您可以简单地将它们 Package 在一个<div>中,并根据您的需要为其给予一个类和样式。下面的例子
html

<div class="wrapper">
  <label for="name" >Name</label>
  <div>
    <input type="text" name="name" id="name">
  </div>
</div>

CSS

.wrapper {
  margin: 20px;
}

我还建议做两件事来改进这段代码。首先,也是最重要的,分别为label和input分配forid属性。其次,div Package 输入似乎不必要。

<div class="wrapper">
  <label for="name" >Name</label>
  <input type="text" name="name" id="name">
</div>

相关问题