I have two div
tags and only one has input
tag; why output is in this way?
div.logo, div.form {
display: inline-block;
height: 200px;
width: 200px;
border: 1px dotted;
}
<div class="logo">
<input type="text">
</div>
<div class="form">
</div>
Can anyone explain this? Here is the fiddle: https://jsfiddle.net/ag487L5m/
To align things in the inline direction, use the properties which begin with justify- . Use justify-content to distribute space between grid tracks, and justify-items or justify-self to align items inside their grid area in the inline direction.
As a result, the elements can sit next to each other. The major difference between display: inline; and display: inline-block; is that, display: inline-block; also allows us to set the width and height of the element. We can prevent inline-block divs from wrapping by adding suitable Bootstrap classes.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
The problem of aligning 2 divs horizontally: Since <div> tag is a block element, only one div can be placed in a line, and all the space to the left and right is taken by it.
By default, inline
and inline-block
elements are set to vertical-align: baseline
.
Since your div.logo
has a text input, div.form
which is now an inline-block
element, aligns itself on the baseline of the input
.
Adding vertical-align: top
to the CSS should fix it. As in:
div.logo, div.form {
display: inline-block;
height: 200px;
width: 200px;
border: 1px dotted;
vertical-align: top;
}
div.logo, div.form {
display: inline-block;
height: 200px;
width: 200px;
border: 1px dotted;
vertical-align:top;
}
<div class="logo">
<input type="text">
</div>
<div class="form">
</div>
That's because the vertical alignment of inline elements defaults to baseline. Change it to top:
div.logo, div.form {
display: inline-block;
height: 200px;
width: 200px;
border: 1px dotted;
vertical-align:top;
}
div.logo, div.form {
display: inline-block;
height: 200px;
width: 200px;
border: 1px dotted;
vertical-align:top;
}
<div class="logo">
<input type="text">
</div>
<div class="form">
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With