填充在文本字段中溢出容器

时间:2017-04-23 22:38:22

标签: html css

我尝试将填充分配给文本字段,但右侧覆盖主要内容。我该如何解决?

     <div class='contenedor_section'>
      <input type='text' placeholder='name' class='estilo_input_text'>
     </div>


    .contenedor_section{
      padding: 20px;
      background:red;
    }
    .estilo_input_text {
        display: block;
        width: 100%;
        height: 34px;
        padding: 6px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        background-color: #fff;
        border: 1px solid #ccc;
        border-radius: 4px;
        -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        -webkit-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }

    ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
      font-style: italic;
      color: #999999 !important;
    }

https://jsfiddle.net/ys0yb15s/

4 个答案:

答案 0 :(得分:1)

box-sizing: border-box;添加到.estilo_input_text。这包括宽度/高度设置中的填充和边框。

https://jsfiddle.net/k9at43zg/

答案 1 :(得分:1)

取消您应用的填充。或使用边框。 calc函数非常方便,并得到广泛支持,请使用它!

.contenedor_section{
  padding: 20px;
  background:red;
}
.estilo_input_text {
    display: block;
    width: calc(100% - 24px);/* you have to negate the padding of 12px on each side */
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    -webkit-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  font-style: italic;
  color: #999999 !important;
}
  <div class='contenedor_section'>
    <input type='text' placeholder='name' class='estilo_input_text'>
  </div>

答案 2 :(得分:0)

解决方案:将width: calc(100% - 24px);添加到.estilo_input_text

.estilo_input_text {
    width: calc(100% - 24px);

}

link https://jsfiddle.net/dalinhuang/LLyhwr64/

.contenedor_section{
  padding: 20px;
  background:red;
}
.estilo_input_text {
    display: block;
    width: calc(100% - 24px);
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    -webkit-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  font-style: italic;
  color: #999999 !important;
}
  <div class='contenedor_section'>
    <input type='text' placeholder='name' class='estilo_input_text'>
  </div>

答案 3 :(得分:0)

box-sizing:border-box; / 添加了此 /

&#13;
&#13;
.contenedor_section{
  padding: 20px;
  background:red;
}
.estilo_input_text {
   box-sizing: border-box;/**Added this**/
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    -webkit-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  font-style: italic;
  color: #999999 !important;
 
}
&#13;
<div class='contenedor_section'>
    <input type='text' placeholder='name' class='estilo_input_text'>
  </div>
&#13;
&#13;
&#13;