【问题标题】:I can't write on the full width of input on HTML我无法在 HTML 上输入全宽
【发布时间】:2018-05-18 19:11:03
【问题描述】:

我无法在所有输入空间上写字。当我创建行(不是一个框,因为我删除了左右上边框)并放置了填充时,我不能在整行上写,只能在一半上写,然后前面的文本会在左边消失一边。

.contato {
  background-color: white;
  width: 75%;
  height: 80%;
  margin-left: auto;
  margin-right: auto;
  margin-top: 10%;
}

.contato .header {
  background-color: #353E49;
  border-style: solid;
  border-color: lightgrey;
  border-bottom: none;
  border-width: 0.5px;
}

.contato h1 {
  margin-left: 10%;
  color: white;
  padding: 5% 0 5% 0;
  font-family: "lato regular";
  letter-spacing: 2px;
  font-size:
}

input,
textarea {
  display: block;
  background: transparent;
  border: none;
  border-bottom: 1px solid #CECFD3;
  padding: 1.5% 50% 2% 0;
  resize: vertical;
  width: auto;
  font-family: "Lato Regular";
  color: darkgray;
  font-size: 1.05 rem;
}

.preencher {
  border-style: solid;
  border-color: lightgrey;
  border-width: 0.5px;
  border-top: none;
  padding-top: 5%;
  margin-top: -5%;
}
<div class="contato">
  <form name="contato" method="POST" netlify>
    <div class="header">
      <h1>Contato</h1>
    </div>
    <div class="preencher">
      <p>
        <label>Nome: <input type="text" name="nome"></label>
      </p>
      <p>
        <label>E-mail: <input type="email" name="email"></label>
      </p>
      <p>
        <label>Empresa/site: <input cols="60" type="email" name="empresa"></label>
      </p>
      <p>
        <label>Mensagem: <textarea name="mensagem"></textarea></label>
      </p>
      <p>
        <button type="submit">Send</button>
      </p>
    </div>
  </form>
</div>

你可以在 jsfiddle 上看到结果,更好地理解我所说的:https://jsfiddle.net/cLsgL3d1/

有什么想法吗?

【问题讨论】:

    标签: html css forms input


    【解决方案1】:

    您的输入 padding 设置为 50%,宽度设置为 auto,这导致您的 width 为 50%,margin 填充其余空间。将左/右填充更改为零(或其他),并将宽度设置为 100% 而不是自动。

    .contato {
        background-color:white;
        width:75%;
        height:80%;
        margin-left:auto;
        margin-right:auto;
        margin-top:10%;
    }
    
    .contato .header {
        background-color: #353E49;
        border-style:solid;
        border-color:lightgrey;
        border-bottom:none;
        border-width: 0.5px;
    }
    
    .contato h1 {
        margin-left:10%;
        color:white;
        padding:5% 0 5% 0;
        font-family:"lato regular";
        letter-spacing: 2px;
        font-size:    
    }
    
    input,textarea {
        display:block;
        background: transparent;
        border: none;
        border-bottom: 1px solid #CECFD3;
        padding: 1.5% 0 2% 0;
        resize:vertical;
        width:100%;
        font-family:"Lato Regular";
        color:darkgray;
        font-size:1.05 rem;
    }
    
    .preencher {
        border-style: solid;
        border-color:lightgrey;
        border-width: 0.5px;
        border-top:none;
        padding-top:5%;
        margin-top:-5%;
    }
    <div class="contato">
        <form name="contato" method="POST" netlify>
         
            <div class="header">
               <h1>Contato</h1>
            </div>
    
            <div class="preencher">
                <p>
                    <label>Nome: <input type="text" name="nome"></label>
                </p>
                <p>
                    <label>E-mail: <input type="email" name="email"></label>
                    </p>
                    <p>
                       <label>Empresa/site: <input cols="60" type="email" name="empresa"></label>
                    </p>
                    <p>
                        <label>Mensagem: <textarea name="mensagem"></textarea></label>
                    </p>
                    <p>
                        <button type="submit">Send</button>
                    </p>
            </div>
        </form>
    </div>

    【讨论】:

    • 天哪,原来如此简单!谢谢!
    • 很高兴为您提供帮助!随意将我的答案标记为正确:D
    【解决方案2】:

    您需要在现有代码中添加/替换此 CSS:

    input { width: 100%; padding: 1.5% 5% 2% 0; box-sizing: border-box; }

    您的 50% 右填充是导致输入允许如此少量文本的原因。如果您希望输入在容器的右边缘之前停止,我建议向父级添加 padding-right

    标签。

    【讨论】:

      【解决方案3】:

      我刚刚修改了这段代码,现在可以正常工作了:

      input,textarea {
              display:block;
              background: transparent;
              border: none;
              border-bottom: 1px solid #CECFD3;
              padding: 1.5% 0 2% 0; // you have added 50% of right padding. which is the reason of the problem. 
              resize:vertical;
              width:100%;
              font-family:"Lato Regular";
              color:darkgray;
              font-size:1.05 rem;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-03-27
        • 2015-08-05
        • 1970-01-01
        • 2013-11-13
        • 1970-01-01
        • 2011-08-30
        • 2016-03-28
        相关资源
        最近更新 更多