【问题标题】:How to prevent background colour going around the legend tag如何防止背景颜色围绕图例标签
【发布时间】:2021-05-25 19:04:10
【问题描述】:

我想设置我的注册表单的样式,使背景颜色不会仅覆盖注册表单内部的图例标记。

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

这是我的结果:

我当前的代码:

#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>

【问题讨论】:

    标签: html css html-input fieldset


    【解决方案1】:

    你必须在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>

    【讨论】:

      【解决方案2】:

      看看我的代码
      我想这就是你要找的。​​p>

      #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>

      【讨论】:

        猜你喜欢
        • 2021-04-22
        • 2022-09-27
        • 2016-10-04
        • 2013-06-19
        • 1970-01-01
        • 2022-01-26
        • 1970-01-01
        • 1970-01-01
        • 2019-10-14
        相关资源
        最近更新 更多