我尝试将填充分配给文本字段,但右侧覆盖主要内容。我该如何解决?
<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;
}
答案 0 :(得分:1)
将box-sizing: border-box;
添加到.estilo_input_text
。这包括宽度/高度设置中的填充和边框。
答案 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);
}
.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; / 添加了此 /
.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;