0

I am trying to display two buttons in a row with an image on them. I use:

.outer {
  background-color: gray;
  padding: 10px;
}

.inner {
  background-color: blue;
  padding: 10px;
}

.tab {
  background-color: red;
}
<div class="outer">
  <div class="tab">
    <button>
       <img src="http://www.insideredbox.com/images/ball_red.png">
      </button>
    <button>
       <img src="http://www.insideredbox.com/images/ball_red.png">
      </button>
  </div>
  <div class="inner">
    Test123
  </div>
</div>

Code works fine but why is there a space of 1px at the bottom line of red border? Moreover, how can I also erase the red space between the two buttons?

enter image description here

kukkuz
  • 41,512
  • 6
  • 59
  • 95
darkchampionz
  • 1,174
  • 5
  • 24
  • 47

3 Answers3

2

Just remove white spaces between buttons: https://jsfiddle.net/0ose31La/

<div class="outer">
    <div class="tab">
        <button>
            <img src="http://www.insideredbox.com/images/ball_red.png">
        </button><button>
            <img src="http://www.insideredbox.com/images/ball_red.png">
        </button>
    </div>
    <div class="inner">
        Test123
    </div>
</div>
Dariusz Majchrzak
  • 1,227
  • 2
  • 12
  • 22
0

There are a lot of tricks to remove space between elements with display: inline-block, but the most easy is "just float them".

Let's add float: left to buttons, put them into their own container: <div class="buttons">...</div> and apply clearfix trick to it.

.outer {
  background-color: gray;
  padding: 10px;
}

.inner {
  background-color: blue;
  padding: 10px;
}

.tab {
  background-color: red;
}

.buttons button {
  float: left;
}
 
.buttons:after {
  content: " ";
  display: table;
  clear: both;
}
<div class="outer">
  <div class="tab">
    <div class="buttons">
      <button>
      <img src="http://www.insideredbox.com/images/ball_red.png">
      </button>
      <button>
     <img src="http://www.insideredbox.com/images/ball_red.png">
      </button>
    </div>
    <div class="inner">
      Test123
    </div>
  </div>
</div>
Styx
  • 9,863
  • 8
  • 43
  • 53
0

You can give font-size:0; to .tab class because button tag take by default display:inline-block. and you can also use float:left and clearfix.

<html>
<head>
<style>
.outer {
    background-color: gray;
    padding: 10px;
}
.inner {
    background-color: blue;
    padding: 10px;
}
.tab {
    background-color: red;
    font-size:0;
}
</style>
</head>
<body>

<div class="outer">
    <div class="tab">
        <button>
            <img src="http://www.insideredbox.com/images/ball_red.png">
        </button>
        <button>
            <img src="http://www.insideredbox.com/images/ball_red.png">
        </button>
    </div>
    <div class="inner">
        Test123
    </div>
</div>

</body>
</html>
ankita patel
  • 4,201
  • 1
  • 13
  • 28