Flexbox only working in chrome - html

i'm trying to achieve a two column div where the one is fixed and the other one is stretched to fill rest. For this i've at the moment used a flexbox, however i've found out that it does not work in safari and IE 10. So how can i achieve the same result without flexbox?
http://jsfiddle.net/LLExL/4086/
.stat-result {
border: 1px solid #ddd;
width: 100%;
display: flex;
margin-bottom: 20px !important;
}
.stat-result .stat-meta {
float: left;
width: 100%;
min-height: 40px;
border-right: 1px solid #ddd;
}
.stat-result .result-meta {
float: left;
width: 100px;
height: 100%;
text-align: center;
}
.stat-result .result-meta i {
font-size: 50px;
line-height: 80px;
}
.stat-result .stat-meta .stat-row {
width: 100%;
height: 50%;
border-bottom: 1px solid #ddd;
padding-left: 10px;
padding-right: 10px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
}
.stat-result .stat-meta .stat-row span {
line-height: 40px;
font-weight: 700;
font-family: Oswald;
text-transform: uppercase;
}
.stat-result .stat-meta .stat-row1 {
width: 100%;
height: 50%;
padding-left: 10px;
padding-right: 10px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
}
.stat-result .stat-meta .stat-row1 span {
line-height: 40px;
}
<div class="stat-result">
<div class="stat-meta">
<div class="stat-row">
<span>Titan Vs. Mousesports</span>
</div>
<div class="stat-row1">
<span>1.35</span>
<span style="float: right;">Test</span>
</div>
</div>
<div class="result-meta">
<i class="fa fa-check-circle"></i>
</div>
</div>

You are lacking all the flexbox prefixes. According to caniuse you can actually use flexbox for safari and IE10.
Updated Fiddle http://jsfiddle.net/LLExL/4088/
And css
.stat-result {
border: 1px solid #ddd;
width: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
margin-bottom: 20px !important;
}
Edit: I'd like to recommend using gulp/grunt and an autoprefixer to automatically prefix your css.

If you don't want to use flexbox, you can use table-cell property to achieve the same.
.stat-result {
border: 1px solid #ddd;
width: 100%;
display: table;
margin-bottom: 20px !important;
}
.stat-result .stat-meta {
display:table-cell;
width:calc(100% - 100px);
min-height: 40px;
border-right: 1px solid #ddd;
}
.stat-result .result-meta {
display: table-cell;
width: 100px;
height: 100%;
text-align: center;
}
FIDDLE DEMO

Related

Why is my input element wider than the other elements even though I already applied "box-sizing: border-box"?

I have an input element which has a padding of 1em on both the left and the right side. But I have applied "box-sizing: border-box" to it. However, It's width is still more than the other elements. I think it might be because I need to remove some piece of code but I'm not sure. The input element is definitely the one issue as the other element is properly center aligned.
Below is the code:
:root {
--main-color: #00308f;
--secondary-color: #7cb9e8;
--dark-color: #444;
--light-color: #fafafa
}
body {
font-family: Montserrat, sans-serif;
background-color: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin-top: 70px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 1em
}
.my-contacts-div {
align-items: center
}
.contacts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center
}
.contact-card {
width: 288px;
margin: .5em;
border-radius: .5em;
box-shadow: var(--secondary-color) 1px 1px 10px;
padding: 0 .75em;
word-wrap: break-word
}
.contact-form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: grid;
align-self: center;
width: 350px;
z-index: 1;
background-color: var(--secondary-color);
border-radius: 1em;
padding: 1em;
box-shadow: 1px 1px 1.5em var(--main-color);
visibility: hidden
}
.contact-form:target {
visibility: visible
}
.input-field {
margin: .5em 0;
border: solid 1px var(--secondary-color);
border-radius: .5em;
padding: 0 1em;
height: 40px;
box-sizing: border-box
}
.searchbar {
margin: .5em;
width: 100%
}
#media screen and (max-width:687px) {
.my-contacts-div {
padding: 0
}
.contact-card {
width: 100%
}
}
#media screen and (max-width:614px) {
body {
margin-top: 130px
}
}
<div class="my-contacts-div">
<h2>Heading</h2>
<form><input class="input-field searchbar" type="text" placeholder="Search here..."></form>
<div class="contacts-list">
<div class="contact-card">
<h3>Other component</h3>
</div>
</div>
</div>
What is wrong with it?
The issue was most likely that when you were using '.input-field' in the CSS, it was maybe not correctly using it so I just put 'form input.input-field' and also added some CSS to the form element. Now it is looking completely aligned.
:root {
--main-color: #00308f;
--secondary-color: #7cb9e8;
--dark-color: #444;
--light-color: #fafafa
}
body {
font-family: Montserrat, sans-serif;
background-color: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin-top: 70px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 1em
}
.my-contacts-div {
align-items: center
}
.contacts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center
}
.contact-card {
width: 288px;
margin: .5em;
border-radius: .5em;
box-shadow: var(--secondary-color) 1px 1px 10px;
padding: 0 .75em;
word-wrap: break-word
}
.contact-form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: grid;
align-self: center;
width: 350px;
z-index: 1;
background-color: var(--secondary-color);
border-radius: 1em;
padding: 1em;
box-shadow: 1px 1px 1.5em var(--main-color);
visibility: hidden
}
.contact-form:target {
visibility: visible
}
form input.input-field {
margin: .5em 0;
border: solid 1px var(--secondary-color);
border-radius: .5em;
padding: 0 1em;
height: 40px;
box-sizing: border-box;
}
form {
box-sizing: border-box;
padding: 0 0.5em;
}
.searchbar {
margin: .5em;
width: 100%
}
#media screen and (max-width:687px) {
.my-contacts-div {
padding: 0
}
.contact-card {
width: 100%
}
}
#media screen and (max-width:614px) {
body {
margin-top: 130px
}
}
<div class="my-contacts-div">
<h2>Heading</h2>
<form><input class="input-field searchbar" type="text" placeholder="Search here..."></form>
<div class="contacts-list">
<div class="contact-card">
<h3>Other component</h3>
</div>
</div>
</div>
Add display: flex in the tag. It will solve the overflowing issue.
display: flex fills the entire container taking margin and padding into consideration. That's why it didn't overflow.
display: block is at 100% width by default and then adds margin and padding after causing the overflow.

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

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>

Margin right negative makes moves input to the right

I have the following HTML to place a button inside an input (JSFiffle Example):
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form {
border: 1px solid green;
max-width: 400px;
}
input {
border: 1px solid red;
background-color: white;
display: inline-block;
font-size: 18px;
line-height: 1;
margin: 0;
margin-right: -80px;
padding: 12px;
vertical-align: middle;
width: 100%;
}
button {
background-color: white;
border: none;
cursor: pointer;
display: inline-block;
font-size: 28px;
line-height: 1;
margin: 0;
outline: 0;
vertical-align: middle;
}
i {
display: block;
line-height: 1;
margin: 0;
padding: 0;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<form>
<input type="text">
<button><i class="fa fa-search"></i></button>
</form>
Problem
The JSFiddle Example I posted works great ...
But in my application when the negative margin right value is bigger then the icon width the input moves right and gets outside of the container with a space on the left:
I am not able to replicate this on JSFiddle but I wonder if someone has any idea what to look for because I have been trying everything and not able to solve it.
I'd suggest something more along these lines:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form {
border: 1px solid green;
max-width: 400px;
}
.search-input {
display: flex;
flex-flow: row nowrap;
height: 40px;
border: 1px solid red;
background-color: white;
font-size: 18px;
line-height: 1;
}
.search-field {
flex: auto;
border: none;
padding: 10px;
}
.search-button {
width: 40px;
height: 40px;
font-size: 24px;
cursor: pointer;
border: none;
background: transparent;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<form>
<div class="search-input">
<input class="search-field" type="text">
<button class="search-button" type="submit"><i class="fa fa-search"></i></button>
</div>
</form>
Since you said you didn't want a flex solution, how about removing the negative margin-right and replacing width: 100% with width: 88%.
That being said and since I'm a big fan of flexbox, the following is a different flex solution from James' offering:
form {
border: 1px solid green;
max-width: 400px;
display: flex; /* Added */
justify-content: flex-end; /* Added */
}
input {
border: 1px solid red;
background-color: white;
display: inline-block;
font-size: 18px;
line-height: 1;
margin: 0;
/* margin-right: -80px; */ /* Removed */
padding: 12px;
vertical-align: middle;
/* width: 100% */ /* Removed */
flex: 0 1 100%; /* Added */
}
You can make the input's container position: relative and the button position: absolute. Then you can move the button wherever you want relative to the container. I would suggest using something other than the form element, so that you can have more than one element in the form. I've added a simple wrapping div.
Then you set right to a little more than 0 so that the border(s) can be seen, and the top to half way down, less half the height of the button so it's centered vertically.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form {
border: 1px solid green;
max-width: 400px;
}
.search {
/* Making the container relative... */
position: relative;
}
input {
border: 1px solid red;
background-color: white;
display: inline-block;
font-size: 18px;
line-height: 1;
margin: 0;
padding: 12px;
vertical-align: middle;
width: 100%;
}
button {
background-color: white;
border: none;
cursor: pointer;
display: inline-block;
font-size: 28px;
line-height: 1;
margin: 0;
outline: 0;
vertical-align: middle;
/* means you can absolutely position the button relative to that */
position: absolute;
/* make it one pixel off the right for the border */
right: 1px;
/* make it 50% - half its height to center it vertically */
top: calc(50% - 14px);
}
i {
display: block;
line-height: 1;
margin: 0;
padding: 0;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<form>
<div class="search">
<input type="text">
<button><i class="fa fa-search"></i></button>
</div>
</form>

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

I need to figure out why this element is aligned differently in Chrome versus Internet Explorer

If you open this http://jaminweb.com/YoutubePlaylist.html in Chrome, you'll see that the red X is perfectly aligned with the text box to the left of it. If you open it in IE, on the other hand, it is misaligned. I'm trying to figure out why that is. Any help greatly appreciated.
Relevant code:
CSS
div.videl
{
width: 80%;
margin: 0 auto;
background-color: #39275b;
color: white;
padding: 5px;
border-bottom: 1px solid #fff;
}
textarea.vidtxt
{
resize: none;
width: 200px;
height: 20px;
overflow: auto;
}
img.rembtn
{
display: inline;
margin-left: 10px;
height: 24px;
width: 24px;
border: 1px solid #B43535;
padding: 0px;
}
img.rembtn:hover
{
display: inline;
margin-left: 10px;
height: 24px;
width: 24px;
border: 1px solid #B43535;
padding: 0px;
opacity: 0.4;
}
HTML
<div class="videl">
<p><textarea class="vidtxt"></textarea><img class="rembtn" src="xicon.jpg" width=20 height=20></img></p>
</div>
Try this
img.rembtn {
border: 1px solid #B43535;
display: inline-block;
height: 24px;
margin-left: 10px;
padding: 0;
vertical-align: middle;
width: 24px;
}
textarea.vidtxt {
display: inline-block;
height: 20px;
overflow: auto;
resize: none;
vertical-align: middle;
width: 200px;
}
By setting the vertical alignment to middle and making both items display inline-block should allow them to align perfectly
You should set them to the same height, currently they are different, and also add vertical-align: top;