2

I want to display four buttons, inline, without any spacing between them. I have a jsfiddle that shows the current behavior. In short, the following HTML/CSS:

<div>
    <input id="unconfirmedYes" type="button" value="10%" />
    <input id="confirmedYes" type="button" value="98% YES" />
    <input id="confirmedNo" type="button" value="2% NO" />
    <input id="unconfirmedNo" type="button" value="90%" />
</div>

div input[type=button] {
    display: inline;
    margin: 0;
    padding: 0;
}
#unconfirmedYes, #unconfirmedNo {
    width: 10%;
}
#confirmedYes, #confirmedNo {
    width: 40%;
}

will in fact line the buttons up, but there is still spacing between them. How do I get rid of that spacing so they stack up right against each other?

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232

4 Answers4

7

The whitespace between the <input/> elements is where the spacing is coming from. If you remove the line breaks and make the tags completely adjacent the space will disappear.

<div>
    <input id="unconfirmedYes" type="button" value="10%"
  /><input id="confirmedYes"   type="button" value="98% YES"
  /><input id="confirmedNo"    type="button" value="2% NO"
  /><input id="unconfirmedNo"  type="button" value="90%" />
</div>
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
2

Set float:left to button.

div input[type=button] {
    display: inline;
    margin: 0;
    padding: 0;
    float:left;
}
Kalpesh Patel
  • 2,772
  • 2
  • 25
  • 52
1

it is assuming that the there are whitespaces between the buttons. If you set font size to zero, the space will be removed.

div.give-it-a-class{
 font-size: 0;
}

Detail can be found in this question.

Community
  • 1
  • 1
Mohayemin
  • 3,841
  • 4
  • 25
  • 54
  • I think this is the best answer, as using float is not cross browser and removing the line breaks between button could be tricky because another programmer may want to format code to make it more readable and all the efforts will be gone... – Sara Nikta Yousefi Aug 31 '15 at 06:49
1

Simply use html comments to remove space between html tags.

<div>
    <input id="unconfirmedYes" type="button" value="10><!--
   --><input id="confirmedYes" type="button" value="98% YES" /><!--
   --><input id="confirmedNo" type="button" value="2% NO" /><!--
   --><input id="unconfirmedNo" type="button" value="90%" />
</div>
shakthydoss
  • 2,551
  • 6
  • 27
  • 36