如何防止背景颜色绕过图例标签

How to prevent background colour going around the legend tag

我想设计我的注册表单,使背景色不覆盖注册表单内部的图例标签。

例如,这就是我要实现的目标:

这是我的结果:

我当前的代码:

#signupform {
  font-size: 2rem;
  margin: 30px;
  line-height: 50px;
  background-color: #f6f6f6;
}

#signupform legend {
  font-size: 3rem;
}
<section class="subscribe">
  <h2>SUBSCRIBE</h2>
  <p>Sign up to our newsletter and receive exclusive offers by email weekly.</p>
  <form id="signupform">
    <fieldset>
      <legend>SIGN UP NOW!</legend>

      <label for="name">Your name:</label>
      <input type="text" name="name" id="name">

      <label for="mail">Email address:</label>
      <input type="text" name="mail" id="mail">
      <button type="button" class="signupbutton">Sign up</button>
    </fieldset>
  </form>
</section>

您必须在 fieldset

中设置 background-color

#signupform {
  font-size: 2rem;
  margin: 30px;
  line-height: 50px;
}

fieldset {
  background-color: #f6f6f6;
}

#signupform legend {
  font-size: 3rem;
}
<section class="subscribe">
  <h2>SUBSCRIBE</h2>
  <p>Sign up to our newsletter and receive exclusive offers by email weekly.</p>
  <form id="signupform">
    <fieldset>
      <legend>SIGN UP NOW!</legend>
      <label for="name">Your name:</label>
      <input type="text" name="name" id="name">
      <label for="mail">Email address:</label>
      <input type="text" name="mail" id="mail">
      <button type="button" class="signupbutton">Sign up</button>
    </fieldset>
  </form>
</section>

看看我的代码
我想这是你要找的。

#signupform {
    font-size: 2rem;
    margin: 30px;
    line-height: 50px;
    background-color: #d4d4d4;
    padding: 1rem;
}

fieldset{
  background-color: #f6f6f6;
}

#signupform legend {
    font-size: 3rem;
}
<section class="subscribe">
            <h2>SUBSCRIBE</h2>
            <p>Sign up to our newsletter and receive exclusive offers by email weekly.</p>
            <form id="signupform">
                <fieldset>
                    <legend>SIGN UP NOW!</legend>
        
                    <label for="name">Your name:</label>
                    <input type="text" name="name" id="name">
                    <br />
                    <label for="mail">Email address:</label>
                    <input type="text" name="mail" id="mail">
                    <button type="button" class="signupbutton">Sign up</button>
                </fieldset>
            </form>
        </section>