0

How can i put i div between 2 inputs, having same heights, vertical aligned? It sounds simple, and i don't understand why the following code don't work:

input{
    width: 35%;
    border: 1px solid #A7A7A7;
    display: inline-block;
    font-size: 11px;
    padding: 0 5px;
    line-height: 18px;
}
input:first-child{
    border-right: none;
}
input:nth-child(3){
    border-left: none;
}
#between_inputs{
    width: 10px;
    height: 18px;
    display: inline-block;
    background-color: white;
    border-top: 1px solid #A7A7A7;
    border-bottom: 1px solid #A7A7A7;
    line-height: 18px;
}
<input type="text" name="min" placeholder="min."/><div id="between_inputs"></div><input type="text" name="max"  placeholder="max."/>

Somehow the div is placed above the inputs? What is wrong?

3 Answers3

4

You can do it with the Flexbox:

.flex {
  display: flex; /* displays flex-items (children) inline */
}

input {
  width: 35%;
  border: 1px solid #A7A7A7;
  display: inline-block;
  font-size: 11px;
  padding: 0 5px;
  line-height: 18px;
}

input:first-child {
  border-right: none;
}

input:nth-child(3) {
  border-left: none;
}

#between_inputs {
  /* flex-grow: 1; recommended, grows and takes the remaining horizontal space */
  width: 10px;
  /* height: 18px; not necessary, flex-items have the same height by default */
  display: inline-block;
  background: Lavender; /* just for demo */
  border-top: 1px solid #A7A7A7;
  border-bottom: 1px solid #A7A7A7;
  line-height: 18px;
}
<div class="flex">
  <input type="text" name="min" placeholder="min.">
  <div id="between_inputs"></div>
  <input type="text" name="max"  placeholder="max.">
</div>
VXp
  • 10,307
  • 6
  • 25
  • 40
3

Add vertical-align to input:

input{
    width: 35%;
    border: 1px solid #A7A7A7;
    display: inline-block;
    font-size: 11px;
    padding: 0 5px;
    line-height: 18px;
    vertical-align: top;/* <<<< this one */
}
evilReiko
  • 16,552
  • 21
  • 76
  • 90
0

You could add vertical-align: middle for both inputs and div , and decrease the height of div to make it 17px so they will be perfectly aligned.

input{
    width: 35%;
    border: 1px solid #A7A7A7;
    display: inline-block;
    font-size: 11px;
    padding: 0 5px;
    line-height: 18px;
    vertical-align: middle
}
input:first-child{
    border-right: none;
}
input:nth-child(3){
    border-left: none;
}
#between_inputs{
    width: 10px;
    height: 17px;
    display: inline-block;
    background-color: white;
    border-top: 1px solid #A7A7A7;
    border-bottom: 1px solid #A7A7A7;
    line-height: 18px;
    vertical-align: middle
}
<input type="text" name="min" placeholder="min."/><div id="between_inputs"></div><input type="text" name="max"  placeholder="max."/>
Mhd Alaa Alhaj
  • 2,330
  • 1
  • 9
  • 18