The input with 100% width inside a div is overlapping the div - html

I'm having a problem with margin in the input with width 100%, because it is overlapping the div container.
I looked for solutions on the forum, and the possible solution was to apply box-sizing: border-box, but it is not working.
Solution not working to me: CSS - Input at 100% width overlaps div
jsfiddle: https://jsfiddle.net/igorac1999/fuovpkba/
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*, *::before, *::after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
body, pre {
margin: 0;
padding: 0;
}
.container {
width: 100%;
max-width: 980px;
margin: 0 auto;
}
.container_calculator {
width: 100%;
max-width: 400px;
background-color: tomato;
border-radius: 5px;
margin: 5px auto;
}
.container_calculator > label {
display: inline-block;
color: #fff;
margin: 10px 0 0 20px;
}
.container_calculator > input {
height: 20px;
border: 1px solid tomato;
border-radius: 5px;
width: 100%;
margin: 5px 20px;
}
div.result_bin2dec {
border: 1px solid #edf2f7;
background-color: #edf2f7;
border-radius: 10px;
margin-top: 30px;
height: 35px;
}
<div class="container">
<div class="container_calculator">
<label>Number</label>
<input type="text" id="number">
</div>
<div class="result_bin2dec">
<pre>
Dec: 10
Bin: 01
</pre>
</div>
</div>
enter image description here

instead margin on the children, you may use padding on the parent , so it can be included in box-sizing
as specified in the linked answer you said did not work for you , see below the link to specification of box-sizing to understand how it works and how to use it
possible example: https://jsfiddle.net/gr7cbevj/
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*,
*::before,
*::after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
body,
pre {
margin: 0;
padding: 0;
}
.container {
width: 100%;
max-width: 980px;
margin: 0 auto;
}
.container_calculator {
width: 100%;
max-width: 400px;
background-color: tomato;
border-radius: 5px;
margin: 5px auto;
padding: 0 20px;/* added */
box-sizing: border-box;/* added */
}
.container_calculator>label {
display: inline-block;
color: #fff;
margin: 10px 0 0 0px;/* modified */
}
.container_calculator>input {
height: 20px;
border: 1px solid tomato;
border-radius: 5px;
width: 100%;
margin: 5px 0px;/* modified */
}
div.result_bin2dec {
border: 1px solid #edf2f7;
background-color: #edf2f7;
border-radius: 10px;
margin-top: 30px;
height: 35px;
}
<div class="container">
<div class="container_calculator">
<label>Number</label>
<input type="text" id="number">
</div>
<div class="result_bin2dec">
<pre>
Dec: 10
Bin: 01
</pre>
</div>
</div>
see the use of box-sizing .
The box-sizing CSS property sets how the total width and height of an element is calculated.

You are adding 20px to the margin.
change your css for this element:
PREVIOUS:
.container_calculator > input {
height: 20px;
border: 1px solid tomato;
border-radius: 5px;
width: 100%;
margin: 5px 20px;
}
NEW:
.container_calculator input {
height: 20px;
border: 1px solid tomato;
border-radius: 5px;
width: 100%;
margin: 5px 0px;
}

Just insert padding to parent and remove margin in input and label.
.container_calculator {
padding: 5px 20px;<-------------insert this line
//Other codes...
}
.container_calculator > input {
margin: 5px 20px;<--------------remove this
//Other codes...
}
.container_calculator>label {
margin: 10px 0 0 20px;<---------remove this
//Other codes...
}
For space between input and label,you can use of :
.container_calculator>input{
margin-top:5px;
//Other codes...
}
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*,
*::before,
*::after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
body,
pre {
margin: 0;
padding: 0;
}
.container {
width: 100%;
max-width: 980px;
margin: 0 auto;
}
.container_calculator {
width: 100%;
max-width: 400px;
background-color: tomato;
border-radius: 5px;
margin: 5px auto;
padding: 5px 20px;
}
.container_calculator>label {
display: inline-block;
color: #fff;
}
.container_calculator>input {
height: 20px;
border: 1px solid tomato;
border-radius: 5px;
width: 100%;
}
div.result_bin2dec {
border: 1px solid #edf2f7;
background-color: #edf2f7;
border-radius: 10px;
margin-top: 30px;
height: 35px;
}
<div class="container">
<div class="container_calculator">
<label>Number</label>
<input type="text" id="number">
</div>
<div class="result_bin2dec">
<pre>
Dec: 10
Bin: 01
</pre>
</div>
</div>

Related

Tag div put some word will change the div position?

I use div to make layout .
The problem is <div class="c">1</div> ,
I put number 1 in it <div class="c">1</div>, The div will be below.
I remove number 1 <div class="c"></div>, The div will be up .
I am confused why text in div will change the place.
This is my code in given below:
div.content {
border: 5px solid black;
box-sizing: border-box;
font-size: 0;
width:1000px;
height: 800px;
}
div.a {
border: 5px solid rgb(212, 69, 69);
box-sizing: border-box;
width: 300px;
height: 600px;
font-size: 16px;
display: inline-block;
}
div.b {
border: 5px solid rgb(11, 141, 22);
box-sizing: border-box;
width: calc(100% - 300px);
height: 500px;
font-size: 16px;
display: inline-block;
}
div.c {
border: 5px solid rgb(219, 7, 209);
box-sizing: border-box;
}
<div class="content">
<div class="a"></div>
<div class="b">
<div class="c">1</div>
</div>
</div>
Depending on which you wanted.
position:absolute; will get your table to line up directly to the right of the green box. This happens because the default setting is for your boxes to be relative of their parent container. Changing this to absolute allows it to work almost independantly.
OR
Change your display: style to block; instead of in-line if you wanted to display your box underneath. This works as it's no longer forced to be in-line with the box above it and can now be displayed neatly below.
Here's a snippet of the absolute positioning:
div.content {
border: 5px solid black;
box-sizing: border-box;
font-size: 0;
width:1000px;
height: 800px;
}
div.a {
border: 5px solid rgb(212, 69, 69);
box-sizing: border-box;
width: 300px;
height: 600px;
font-size: 16px;
display: inline-block;
}
div.b {
border: 5px solid rgb(11, 141, 22);
box-sizing: border-box;
width: calc(100% - 300px);
position:Absolute;
height: 500px;
font-size: 16px;
display: inline-block;
}
div.c {
border: 5px solid rgb(219, 7, 209);
box-sizing: border-box;
}
<div class="content">
<div class="a"></div>
<div class="b">
<div class="c">1</div>
</div>
</div>
Just add float left to div.a and div.b will work for your current requirement.
If you have some specific requirements, do share.
div.content {
border: 5px solid black;
box-sizing: border-box;
font-size: 0;
width: 1000px;
height: 800px;
}
div.a {
float:left;
border: 5px solid rgb(212, 69, 69);
box-sizing: border-box;
width: 300px;
height: 600px;
font-size: 16px;
display: inline-block;
}
div.b {
float:left;
border: 5px solid rgb(11, 141, 22);
box-sizing: border-box;
width: calc(100% - 300px);
height: 500px;
font-size: 16px;
display: inline-block;
}
div.c {
border: 5px solid rgb(219, 7, 209);
box-sizing: border-box;
}
<div class="content">
<div class="a"></div>
<div class="b">
<div class="c">1</div>
</div>
</div>
If you needed the box to always be up just add a float: left; to .content > div like this to the css file.
div.content {
border: 5px solid black;
box-sizing: border-box;
font-size: 0;
width:1000px;
height: 800px;
}
div.a {
border: 5px solid rgb(212, 69, 69);
box-sizing: border-box;
width: 300px;
height: 600px;
font-size: 16px;
display: inline-block;
}
div.b {
border: 5px solid rgb(11, 141, 22);
box-sizing: border-box;
width: calc(100% - 300px);
height: 500px;
font-size: 16px;
display: inline-block;
}
div.c {
border: 5px solid rgb(219, 7, 209);
box-sizing: border-box;
}
.content > div{
float:left;
}
<div class="content">
<div class="a"></div>
<div class="b">
<div class="c">1</div>
</div>
</div>
In div class a & b you have to add "float: left;" in CSS. So this will set your div in proper relative place. While you can also add a css for content
/*use this css code*/
div.content {
/*use this if you need while you are adding more than one div */
/*float: left;*/
border: 5px solid black;
box-sizing: border-box;
font-size: 0;
width: 1000px;
height: 800px;
}
div.a {
border: 5px solid rgb(212, 69, 69);
box-sizing: border-box;
width: 300px;
height: 600px;
font-size: 16px;
display: inline-block;
float: left;
}
div.b {
float: left;
border: 5px solid rgb(11, 141, 22);
box-sizing: border-box;
width: calc(100% - 300px);
height: 500px;
font-size: 16px;
display: inline-block;
}
div.c {
border: 5px solid rgb(219, 7, 209);
box-sizing: border-box;
}
use this CSS in your code.

5 px border added to button, Button size increases. Box-sizing not working

On button I am adding active class with 5px border-bottom. Button size increases by 5px. I dont want to get button size increased. Is there any simple way to do so? Box-sizing not working.
*,
*:after,
*::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 100%;
border: 2px solid blue;
}
.button {
background: black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
}
.active {
border-bottom: 5px solid yellow;
}
<div class="container">
<button class="button active">button active</button>
<button class="button">button</button>
</div>
With respect to border box-sizing: border-box will work if you are
giving a fixed height to the button element.
Solution1 with fixed height
*,
*:after,
*::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 100%;
border: 2px solid blue;
}
.button {
background: black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
height: 53px;
}
.button.active {
border-bottom: 5px solid yellow;
}
<div class="container">
<button class="button active">button active</button>
<button class="button">button</button>
</div>
Solution2 without fixed height(Using :before css pseudo selector)
*,
*:after,
*::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 100%;
border: 2px solid blue;
}
.button {
background: black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
position: relative;
}
.button.active:before {
content: "";
border-bottom: 5px solid yellow;
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
<div class="container">
<button class="button active">button active</button>
<button class="button">button</button>
</div>
So, Here is why box-sizing wont solve your problem.
You command css to add 20px of padding for both buttons and css obey! then you command css to add 5px of border to the active button and again css obey! then you want both button to be equal ? do you meant to reduce padding of the first one! because it is the only way to make them equal . here is a how:
.active {
border-bottom: 5px solid yellow;
padding:calc(20px - 5px);
}
i've used function calc() in case anyone is using rems or ems as unit.
Solution 1: box-shadow
*,
*:after,
*::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 100%;
border: 2px solid blue;
}
.button {
background: black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
}
.active {
box-shadow: 0 -5px 0 yellow inset
}
<div class="container">
<button class="button active">button active</button>
<button class="button">button</button>
</div>
Solution 2: pseudo-element ::after
*,
*:after,
*::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 100%;
border: 2px solid blue;
}
.button {
/* Add Position Relative for Button */
position: relative;
background: black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
}
.active::after {
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
height: 5px;
width: 100%;
background: yellow
}
<div class="container">
<button class="button active">button active</button>
<button class="button">button</button>
</div>
try to add a black 5px border on the default button style, and the yellow color for the active button
.button {
background: black;
border-bottom: 5px solid black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
}
.active {
border-bottom: 5px solid yellow;
}
As per my understanding you need shadow for the button.
Its better to use shadow on the button.
Use this
box-shadow: 10px 10px 5px #aaaaaa;
Then configure it as you want.
Declare your button height inside .active class and box-sizing: border-box. You are good to go ...... :)
*,
*:after,
*::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 100%;
border: 2px solid blue;
}
.button {
background: black;
width: 150px;
border: 0;
padding: 20px;
margin: 0;
color: white;
}
.active {
border-bottom: 5px solid yellow;
box-sizing: border-box;
height: 55px;
}
<div class="container">
<button class="button active">button active</button>
<button class="button">button</button>
</div>

How to automatically adjust the size of a parent box in css?

How can I make "cols_img" boxes to be inside the "col2" box in the code below? I know that if I increase padding for "col2" it will work, but is there a way to automatically do this?
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.col2 {
border: 2px solid black;
padding: 5px;
}
.cols_img {
width: 50%;
float: left;
padding: 10px 10px 5px 5px;
background-color: yellow;
border: 1px solid blue;
}
<div class=col2>
<div class="cols_img"></div>
<div class="cols_img"></div>
</div>
One way to do this is use the :after on your col2 class
.col2:after {
content: '';
display: block;
clear: both;
}
You can use display: inline-block instead of float.
.cols_img {
display: inline-block;
width: 40%;
padding: 10px 10px 5px 5px;
background-color: yellow;
border: 1px solid blue;
}
Check it out here: http://jsfiddle.net/97gq048L/

file upload button not supported in all the browsers

I have created a file upload with search button at the right side. This one is showing correctly in chrome only, but I need this to support all modern browsers. I have tried in Mozilla where this is not being supported. Can anybody please help me to solve this. Thank You.
#import url(https://fonts.googleapis.com/css?family=Roboto);
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html {
font-size: 16px
}
body {
background-color: #fff;
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
font-size: 1rem;
}
.container {
margin: 20px auto;
max-width: 1140px;
padding: 25px 25px;
border: 1px solid #000;
}
.row {
clear: both;
}
#myInput {
width: 85%;
border: 1px solid #000;
display: inline-block;
}
input[type=file]::-webkit-file-upload-button {
width: 0;
padding: 0;
margin: 0;
-webkit-appearance: none;
border: none;
border: 0px;
}
x::-webkit-file-upload-button,
input[type=file]:after {
-webkit-appearance: button;
border-collapse: separate;
border-radius: 7px;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
content: 'Search';
color: #080708;
background: #e3e3e3;
text-decoration: none;
display: inline-block;
left: 100%;
margin-left: 50px;
position: relative;
padding: 10px 46px 10px 40px;
}
#media only screen and (max-width: 767px) {
.container {
width: 100%;
padding: 15px;
}
#myInput {
width: 64%;
}
.btn-View {
width: 10%;
}
table td {
padding: 12px;
}
}
<div class="container">
<div class="row">
<input type="file" name="myInput" id="myInput">
</div>
</div>
You can make it work in many ways.
The simple way if you do not need the file name to be seen, using
the input file along with the label is the quickest way.
https://codepen.io/anupkumarmaharjan/pen/mWXbVj
Using the javascript can be handy. Go through these links for better understandings.
https://codepen.io/anupkumarmaharjan/pen/NpyKPm
https://tympanus.net/codrops/2015/09/15/styling-customizing-file-inputs-smart-way

How to Decrease HTML A4 size margin in CSS

I have a problem in CSS. I have a CSS code of A4 Size Page. I want to reduce top margin of my A4 size HTML page.
I tried too much time but I failed can anyone one please help me?
Please run the code snippet in full page view to see the correct result of the code.
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #F0F0F0;
font: 12pt "Times New Roman";
}
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.page {
width: 210mm;
min-height: 297mm;
padding: 18mm;
margin: 5mm auto;
border: 1px #D3D3D3 solid;
border-radius: 5px;
background: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.subpage {
padding: 1cm;
border: 5px solid;
height: 257mm;
outline: 2cm #FFEAEA solid;
}
#page {
size: A4;
margin: 0;
}
#media print {
html, body {
width: 210mm;
height: 297mm;
-webkit-print-color-adjust: exact
}
.page {
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
border-top: 2px solid #009;
}
a:link {
text-decoration: black;
}
a:visited {
text-decoration: black;
}
a:hover {
text-decoration: none;
}
<div class="page">
<div style=" margin:auto; width:60px; height:auto; align: middle">
Test Text
</div>
</div>
try by assigning margin at all side.
#page {
size: A4;
margin: 0 1em 1em 1em;
}
and remove margin and padding from other classes which may affect the page.