0

Say I have the following code

p {
  display: inline;
}

div {
  display: inline-block;
  width: 100px;
  height: 50px;
  background: black;
}
 <p>
     Some  text
     <div>
     </div>
    </p>

What is created is this

enter image description here

Here the inline and inline-block elements are not vertically centered. How would I make it look like this :

enter image description here

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Jak
  • 162
  • 2
  • 11

2 Answers2

0

I have used flex css and also add one new div I hope this will help you.

p {
  display: inline;
  margin: 0;
}
.inner-div {
  display: inline-block;
  width: 100px;
  height: 50px;
  background: black;
}
.outer-div{
  display: flex;
  align-items: center;
  display: -webkit-flex;
  -webkit-align-items: center;
}
<div class="outer-div">
  <p>Some text</p>
    <div class="inner-div"></div>
</div>
Dharmesh Vekariya
  • 1,138
  • 2
  • 13
  • 31
Mohit Gupta
  • 739
  • 1
  • 5
  • 16
-1

just add float left to

tag

p{
display: inline;
float:left;
}

This will align both element properly