Reputation: 3051
I'm trying to assign a padding to a text field, but the right side overlays the main content. How can i fix it?
<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/
Upvotes: 0
Views: 276
Reputation: 1645
box-sizing: border-box; /Added this/
.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;
}
<div class='contenedor_section'>
<input type='text' placeholder='name' class='estilo_input_text'>
</div>
Upvotes: 0
Reputation: 11342
width: calc(100% - 24px);
to your .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>
Upvotes: 0
Reputation: 124
Negate the padding you applied. Or use border-box. calc function is very handy, and widely supported, use it!
.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>
Upvotes: 1
Reputation: 67768
Add box-sizing: border-box;
to .estilo_input_text
. This includes padding and borders in the width/height settings.
https://jsfiddle.net/k9at43zg/
Upvotes: 1