inline-flex input element breaks to new line in IE11 - html

I have a few html elements next to each other in a container positioned with display:inline-flex.
This works well for button elements, but as soon as I try to add an input type="text" element, the textbox is placed below the buttons (only in Internet Explorer 11; not sure about IE10 or below).
It works as expected (textbox in same line as buttons) in Firefox, Chrome and even Edge.
How can I get IE to display this correctly?
See jsFiddle for full html and css code to illustrate the problem: https://jsfiddle.net/vm2kcwd9/1/
.container {
height: 2em;
}
.container>* {
height: 100%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
}
<div class="container">
<button>test</button>
<button>test 2</button>
<button>test 3</button>
<input type="text" value="hello" />
</div>

IE11 is known for having many flex-related bugs.
A simple and easy solution in this case would be to make the parent a flex container:
.container {
display: flex; /* new; forces all children into a single row */
height: 2em;
}
.container>* {
height: 100%;
display: inline-flex;
/* vertical-align: top; <--- not necessary anymore */
justify-content: center;
align-items: center;
margin: 5px; /* for demo only */
}
<div class="container">
<button>test</button>
<button>test 2</button>
<button>test 3</button>
<input type="text" value="hello" />
</div>
Also, since you're making button elements into flex containers, consider this:
Flexbox not working on <button> element in some browsers

Easy solution just add display:flex to parent instead
.container {
display: flex;
justify-content: center;
/* align-items: center; you might not need this */
height: 2em;
}
.container>* {
height: 100%;
margin: 10px;
}
<div class="container">
<button>test</button>
<button>test 2</button>
<button>test 3</button>
<input type="text" value="hello" />
</div>

Related

Right Aligned elements not staying on one line

I want to place some elements on the left and some the right. But the elements on the right are not staying on line, especially after addition of mat-form-field. I'm getting:
On the right side, the Right Button and the Icon are on the same line, but the mat-form-field does not stay with them on the same line.
My html is:
<div class="mat-table-container">
<div class="mat-table-button-wrapper">
<div id="left-aligned-wrapper">
<button class="btn btn-primary">
Left Button
</button>
</div>
<div id="right-aligned-wrapper">
<mat-form-field appearance="standard">
<input matInput placeholder="Placeholder">
</mat-form-field>
<button type="button" mat-button>
Right Button
</button>
<button class="btn btn-default">
<i class="my-icon my-icon-filter"></span>
</button>
</div>
</div>
</div>
My CSS is:
.mat-table-container {
position: relative;
.mat-table-button-wrapper {
height: 50px;
padding-left: 0em;
padding-top: 1em;
#left-aligned-wrapper {
float: left;
}
#right-aligned-wrapper {
float: right;
}
}
}
What could be going wrong here?
I would recommend you use flexbox instead of float in this situation.
This would result in your CSS looking something like this:
.mat-table-container {
position: relative;
.mat-table-button-wrapper {
height: 50px;
padding-left: 0em;
padding-top: 1em;
display: flex;
justify-content: space-between;
}
}
i.e. removing applying display: flex to your wrapper class and using justify-content: space-between to space your content accordingly.
This would also make sure your content doesn't jump to the next 'line'.
Please applied width: 50% in both elements.
Or use display: flex property.
.mat-table-button-wrapper {
display: flex;
align-item: center;
justify-content: space-between;
}

How do I prevent IE11 flexbox from having jumpy buttons on hover?

I have a flexbox layout with buttons. When a user moves the mouse over the buttons, their positions jump around.
My source code is quite simple:
.flexy {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
height: 200px;
}
<div class="flexy">
<div>
Content
</div>
<footer>
<button>Button 1</button> <button>Button 2</button><br/>
<button>Button 3</button> <button>Button 4</button><br/>
</footer>
</div>
Moving the mouse between the two rows of buttons causes a lot of movement. Is there a fix I can use to prevent this?
Give your footer a min-height or flex-basis with the value being the actual height of the footer. I tested this in IE11, Chrome, Firefox, Safari and they all get along with this fix.
Option 1
footer {
flex-basis: 46px;
}
Option 2
footer {
min-height: 46px;
}
I'm not really sure what's causing the problem. But I found that if you simply add a border to the button the shifting stops.
.flexy {
display:flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
height: 200px;
}
button {
border: 1px solid #777;
padding: 5px; /* optional */
margin: 5px; /* optional */
}
<div class='flexy'>
<div>
Content
</div>
<footer>
<button>Button 1</button> <button>Button 2</button><br/>
<button>Button 3</button> <button>Button 4</button><br/>
</footer>
</div>
Revised Demo

how to put several buttons inline with responsive design?

Let i have a several number of buttons
<button ng-repeat="a in graphdata" class="inline">
I need to align all these buttons in a line, and all buttons should be visible, and it should adjust its width when new button is getting added.
Button should be attached to each other.
You can use flexbox
$('.new').click(function() {
$('.element').append('<button class="inline">Button</button>');
});
.element {
display: flex;
}
button {
flex: 1;
background: white;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="new">Add new Button</button>
<div class="element">
<button class="inline">Button</button>
</div>
You should wrap your buttons with flex container.
<style>
.wrapper {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap; /* if you want buttons in several lines */
}
button {
min-width: 50px;
}
</style>
<div class="wrapper">
<button ng-repeat="a in graphdata" class="inline"></button>
</div>

distributing differnet elements horizontally inside a div with CSS

Here's the jsFiddle
Suppose I have the following HTML:
<div class="Trigger">click here</div>
<div id="TheContainer">
<div class="One">this is some text</div>
<input type="button" class="Two" value="button 1" />
<input type="button" class="Three" value="button 2" />
</div>
and the following CSS:
#TheContainer{
width:500px;
height:40px;
padding:10px 30px;
display:none;
background:red;}
.One{float:left;}
.Two{float:left;}
.Three{float:left;}
I use the following javascript to show/hide the container:
$(document).ready(function () {
$('.Trigger').click(function () {
var TheContainer = $('#TheContainer');
if (TheContainer.is(':visible') === false) {
TheContainer.show();
} else {
TheContainer.hide();
}
});
});
As you can see, we have a container of fixed width that's hidden, and that contains 3 elements: 1 div and 2 buttons, all 3 of variable sizes because the text of these elements changes at runtime.
I'm looking to horizontally distribute the 3 children elements evenly inside the container. I've looked around and for various reasons, none of the existing solutions seem to work for this particular case.
How can I distribute these elements horizontally and evenly using just CSS?
Note: I know I can do it in jQuery by calculating widths and then setting positions absolutely but I'm looking to see if there's a CSS only solution.
Thanks
I believe this is what you're looking for: http://jsfiddle.net/gq8s4/5/
It involves creating a div around each button so the buttons themselves are not really wide.
<div id="button1"><input type="button" class="Two" value="button 1" /></div>
EDIT: Adjusted answer to new details.
http://jsfiddle.net/gq8s4/3/
.triple-container {
float: left;
width: 33.333333%;
text-align: center;
border: 1px solid yellow;
box-sizing: border-box;
}
.One{
text-align: center;
width: 60px;
margin: 0 auto;
}
.Two{
width: 20px;
}
.Three{
width: 20px;
}
Flexbox is about as close as you're going to get.
http://tinker.io/eb980
#TheContainer {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: justify;
-moz-box-pack: justify;
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
width: 100%; /* for old Firefox */
}
Support: Firefox, Safari, Chrome, Opera, IE10. http://caniuse.com/flexbox
If you're comfortable adding extra markup, you could fake this with display: table-cell but it won't be perfect:
http://tinker.io/eb980/2
#TheContainer {
width: 100%;
display: table;
}
div {
display: table-cell;
width: 33%;
}
div:nth-child(2) {
text-align: center;
}
div:last-child {
text-align: right;
}
<div id="TheContainer">
<div class="One">this is some text</div>
<div><input type="button" class="Two" value="button 1" /></div>
<div><input type="button" class="Three" value="button 2" /></div>
</div>

HTML|CSS: Space between input buttons

I have a problem in which I have a space between these two buttons.
The code is as follows:
<input id="NeedBtn" class="PostBtn" type="button" />
<input id="ProvBtn" class="PostBtn" type="button" />
.PostBtn
{
background: url(../Images/Buttons/PostButtonF.png) no-repeat;
width: 50px;
height: 28px;
border: none;
margin: 0;
padding: 0;
}
#NeedBtn
{
background-position: 0 0;
}
#ProvBtn
{
background-position: -50px 0;
}
How do I remove that space?
Browser:
Firefox 3.5
IE8
The line feed between the two <input>s creates a space between them on the page. You have to remove the line feed, or use this trick :
<input id="NeedBtn" class="PostBtn" type="button" /><!--
--><input id="ProvBtn" class="PostBtn" type="button" />
Surprised no one mentioned this method yet:
The problem is the white-space between the two buttons is being rendered. Any white-space (line breaks, tabs, spaces) between the buttons will be rendered as a single space by the browser. To fix this, you can set the font-size to 0 on a parent element.
I've added DIV#button-container around the buttons and a style for it showing the font-size trick.
Note: I also had to change the positioning on the button background graphic you linked since it had some extra pixel space around it. Maybe this was part of the problem, maybe not.
Here's a link to the fiddle: http://jsfiddle.net/dHhnB/ and the code:
<style>
#button-container
{
font-size:0;
}
.PostBtn
{
background: url(http://img22.imageshack.us/img22/5066/capturebtn.png) no-repeat;
width: 50px;
height: 28px;
border: none;
margin: 0;
padding: 0;
}
#NeedBtn
{
background-position: -4px 0;
}
#ProvBtn
{
background-position: -59px 0px;
}
</style>
<div id="button-container">
<input id="NeedBtn" class="PostBtn" type="button" />
<input id="ProvBtn" class="PostBtn" type="button" />
</div>
As others have pointed out you can use floats to counter act the whitespace between elements
<input id="NeedBtn" class="PostBtn floated" type="button" />
<input id="ProvBtn" class="PostBtn floated" type="button" />
.floated {
float:left;
}
.floated {
float:left;
}
<input id="NeedBtn" class="PostBtn floated" value="Next" type="button" />
<input id="ProvBtn" class="PostBtn floated" value="Prev" type="button" />
As well as the various hacks for inline-block:
Using 0px font-size in parent and resetting the font-size in the child elements.
<div class="parent">
<div class="child">Some Text</div>
<div class="child">Some More Text</div>
</div>
.parent {
font-size:0px;
}
.parent > * {
display:inline-block;
font-size:14px;
}
Putting all the elements next to each other, ie: <div></div><div></div>
Putting the closing tag on the next line and next to the next element, ie:
<div>
</div><div>
</div>
Putting the closing bracket of the previous element on the next line and next to the next element, ie:
<div></div
><div></div>
Or using html comments
<div></div><!--
--><div></div>
And as stated by others this isn't an optimal solution.
With modern browsers Flexbox styles can now be used
<div class="flex">
<input id="NeedBtn" class="PostBtn flex-child" type="button" />
<input id="ProvBtn" class="PostBtn flex-child" type="button" />
</div>
.flex {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.flex-child {
-webkit-box-flex: 0 1 auto;
-moz-box-flex: 0 1 auto;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
}
.flex {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.flex-child {
-webkit-box-flex: 0 1 auto;
-moz-box-flex: 0 1 auto;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
}
<div class="flex">
<input type="button" class="flex-child" id="slide_start_button" value="Start">
<input type="button" class="flex-child" id="slide_stop_button" value="Stop">
</div>
A guide for flex can be found here, and support list here
You can use css to fix it. Set float:left or float:right on the input buttons. That fixed the problem for me.
Try using a CSS reset - it may solve the browser discrepancy : http://meyerweb.com/eric/tools/css/reset/reset.css
I see they have a set height and width. Adding overflow: hidden should hide the whitespace outside of your defined width. That is an alternative to eliminating the whitespace, as #Pikrass noted. Usually the whitespace is a IE problem, I've not noticed it in FF before.