I have a problem in which I have a space between these two buttons.
The code is as follows:
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" />
Try using a CSS reset - it may solve the browser discrepancy : http://meyerweb.com/eric/tools/css/reset/reset.css
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:
<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;
}
<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
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>
You can use css to fix it. Set float:left or float:right on the input buttons. That fixed the problem for me.
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.