Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove blank spaces between buttons in HTML, CSS

I want to remove blank spaces between the buttons, so that when I for example hover over the NORMAL button, there will be no blank space between it and the HARD button. How can I do that and where do these blank spaces come from?

body {
  margin: 0;
}
#stripe {
    background-color: white;
    text-align: center;
    height: 50px;
    color: black;
}

button {
    border: none;
    background: none;
    text-transform: uppercase;
    height: 100%;
    font-weight: 700;
    color: black;
    letter-spacing: 1px;
    font-size: inherit;
    transition: all 0.3s;
    outline: none;
}

button:hover {
    color: white;
    background: black;
}

.selected {
    color: white;
    background: black;
}
<div id="stripe">
    <button class="mode">Easy</button>
    <button class="mode">Normal</button>
    <button class="mode selected">Hard</button>
</div>
like image 892
Huy Tran Avatar asked Apr 15 '17 22:04

Huy Tran


People also ask

How do I reduce the space between two input fields in HTML?

Approach 1: We can remove space between any two tags by simply using margin-bottom property. The margin-bottom property sets the bottom margin of an element. We will assign a negative value to the margin-bottom of a particular tag to eliminate the extra space between the tags as shown.

How do you reduce space between label and input?

How to remove the space? Space between label and input. Use the element inspector in your browser's devtools to see that margin and/or padding are causing this. But basically setting the margin and padding of these elements to 0 should do the trick, I think..


1 Answers

Browsers always add spaces between some elements, including buttons. To remove these, you need to set font-size to zero for their parent container. Then, to restore text size inside buttons, set font-size for them.

#stripe {
  font-size: 0;
}

button {
  font-size: 14px; // Set font size that you need here
}
like image 107
ozma Avatar answered Sep 23 '22 15:09

ozma