0

I've seen a lot of answers online but they work only for text, here my problem is that the line break somehow creates a space between the boxes. In the snippet I removed the line break before the last input element, and it fixes it, but as I'm going to apply many properties to these input elements, the line would result too long and it would affect the code's legibility. How can I make it ignore the line break? Consider that putting them inside a div with nowrap didn't work, as it's not text.

.box {
  width: 1em;
  height: 1em;
  padding: 0px;
  margin: -1px;
  border: 2px solid black;
}
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" /><input type="text" class="box" />

2 Answers2

1

Option 1:

Make the inputs display:block and float:left

.box {
  width: 1em;
  height: 1em;
  padding: 0px;
  margin: -1px;
  border: 2px solid black;
  display: block;
  float: left;
}
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" />
<input type="text" class="box" /><input type="text" class="box" />

Option 2:

Make the inputs' container have font-size:0px but give the inputs a normal font-size

.box {
  width: 1em;
  height: 1em;
  padding: 0px;
  margin: -1px;
  border: 2px solid black;
  font-size: 16px;
}

.container {
  font-size: 0px;
}
<div class="container">
  <input type="text" class="box" />
  <input type="text" class="box" />
  <input type="text" class="box" />
  <input type="text" class="box" />
  <input type="text" class="box" />
  <input type="text" class="box" />
  <input type="text" class="box" /><input type="text" class="box" />
</div>
blex
  • 24,941
  • 5
  • 39
  • 72
Pershing
  • 406
  • 2
  • 10
  • you mist the `` ;) – G-Cyrillus Apr 07 '20 at 20:23
  • 2
    @G-Cyrillus the HTML comment method isn't one I would recommend, as in some IDEs (such as Visual Studio), when you format your code, it puts the comment on another line, defeating the purpose of the comment to eat up the white space – Pershing Apr 07 '20 at 20:24
1

I would recommend putting them into a div with display:flex; flex-direction:row;

Ceyhun Aslan
  • 152
  • 4