0

I have a button a div and a span adjacent to each other in a line

I need all of them to appear vertically aligned to the center like this

enter image description here

below is my code

button{
  height: 50px;
}

div{
  display: inline-block;
  height: 70px;
  border: 2px solid black;
  padding: 10px;
}
h1{
  display: inline-block;
}
<div></div>
<button>Button</button>
<span>Span</span>
<div>div</div>
Rahul Yadav
  • 2,627
  • 5
  • 30
  • 52

2 Answers2

1

I would suggest using flex for in this instance.

If you wrap a container around your elements, you can align the child elements to the center. See the snippet for an example.

button{
  height: 50px;
}

.container div{
  display: inline-block;
  height: 70px;
  border: 2px solid black;
  padding: 10px;
}
h1{
  display: inline-block;
}

.container {
display:flex;
align-items:center;
}
<div class="container"><div></div>
<button>Button</button>
<span>Span</span>
<div>div</div>
</div>

I hope this helps.

M. Ferguson
  • 1,331
  • 1
  • 10
  • 15
0

If you introduce a parent element you can use flexbox:

.wrapper {
  display: flex;
  align-items: center; /* vertical center */
  justify-content: center; /* horizontal center */
  border: 1px solid red;
}

button {
  height: 50px;
}

.wrapper>div {
  display: inline-block;
  height: 70px;
  border: 2px solid black;
  padding: 10px;
}

h1 {
  display: inline-block;
}
<div class="wrapper">
  <div></div>
  <button>Button</button>
  <span>Span</span>
  <div>div</div>
</div>
Turnip
  • 35,836
  • 15
  • 89
  • 111