【问题标题】:Keeping `textarea` height as `100%` does not work [duplicate]将“textarea”高度保持为“100%”不起作用[重复]
【发布时间】:2021-01-07 16:07:41
【问题描述】:

我在左列中保留了一些输入元素,而在右列中只有textarea,我试图将高度添加到100% 等于左列。但由于某种原因它不起作用。

.popup {
  border: 1px solid red;
  background: rgba(000, 000, 000, 0.4);
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

form,
fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}

form {
  display: flex;
  flex-wrap: wrap;
  border: 1px dotted gray;
  width: 25rem;
}

fieldset {
  width: 50%;
  background: #333;
  padding: 0.5em;
  margin: 0;
  box-sizing: border-box;
}

form label {
  display: block;
  width: 100%;
  margin-bottom: 1rem;
}

form label input,
form label textarea {
  width: 100%;
  background: white;
  border: 1px solid gray;
}

textarea {
  border: 1px solid blue;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.submit-form {
  flex-basis: 100%;
  text-align: right;
  background: tan;
}
<div class="popup">
  <div class="pop-form">
    <form>
      <fieldset>
        <label htmlFor="name"><input type="text" name="name" id="name" /></label>
        <label htmlFor="email"><input type="email" name="email" id="email" /></label>
        <label htmlFor="phone"> 
          <input type="tel" name="phone" 
            autoComplete="off"
            placeholder="Phone" id="phone"/> </label>
      </fieldset>
      <fieldset>
        <label class="message" htmlFor="message">
          <textarea placeholder="Message" 
            autoComplete="off"
            name="message" id="message"></textarea></label>
      </fieldset>
      <div class="submit-form">
        <button>Submit</button>
      </div>
    </form>
  </div>
</div>

【问题讨论】:

    标签: javascript css flexbox


    【解决方案1】:

    将此添加到样式.message{ height:100% }。检查以下代码sn-p。

    .popup {
      border: 1px solid red;
      background: rgba(000, 000, 000, 0.4);
      position: fixed;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    form,
    fieldset {
      padding: 0;
      margin: 0;
      border: 0;
    }
    
    form {
      display: flex;
      flex-wrap: wrap;
      border: 1px dotted gray;
      width: 25rem;
    }
    
    fieldset {
      width: 50%;
      background: #333;
      padding: 0.5em;
      margin: 0;
      box-sizing: border-box;
    }
    
    form label {
      display: block;
      width: 100%;
      margin-bottom: 1rem;
    }
    
    form label input,
    form label textarea {
      width: 100%;
      background: white;
      border: 1px solid gray;
    }
    
    textarea {
      border: 1px solid blue;
      width: 100%;
      height: 100%;
      box-sizing: border-box;
    }
    
    .submit-form {
      flex-basis: 100%;
      text-align: right;
      background: tan;
    }
    
    .message {
      height: 100%
    }
    <div class="popup">
      <div class="pop-form">
        <form>
          <fieldset>
            <label htmlFor="name"><input type="text" name="name" id="name" /></label>
            <label htmlFor="email"><input type="email" name="email" id="email" /></label>
            <label htmlFor="phone"> 
              <input type="tel" name="phone" 
                autoComplete="off"
                placeholder="Phone" id="phone"/> </label>
          </fieldset>
          <fieldset>
            <label class="message" htmlFor="message">
              <textarea placeholder="Message" 
                autoComplete="off"
                name="message" id="message"></textarea></label>
          </fieldset>
          <div class="submit-form">
            <button>Submit</button>
          </div>
        </form>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2015-04-06
      • 2014-02-16
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 2022-08-18
      相关资源
      最近更新 更多