0

enter image description here

I am trying to keep these two divs on the same line. But whenever I add a P element inside the first Div, it moves to the new line. I have tried assigning display property to "inline-block" to each element, but it doesn't work. Can you please help, I have the following code:

.tile {
  height: 100px;
  width: 100px;
  background-color: rgb(250, 250, 156);
  border: 5px solid red;
  display: inline-block;
  vertical-align:top
}

p {
  display: inline;
  margin:0;
}
<div class="tile">
  <p>Hello</p>
</div>
<div class="tile"></div>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
  • Use `vertical-align`. The two boxes are aligned on the baseline of the text by default. Also, please [validate your HTML](//html5.validator.nu/). – Sebastian Simon Jun 09 '21 at 10:14
  • 1
    [Duplicate](//google.com/search?q=site%3Astackoverflow.com+css+two+inline-blocks+misaligned+when+text+is+inserted) of [Why my inline-block divs are not aligned when only one of them has text?](/q/13548168/4642212). – Sebastian Simon Jun 09 '21 at 10:18

1 Answers1

0

you can use display flex

  <html>
    <head>
        <title>Experiment</title>
    </head>
    <style>
      .container {
        display: flex
      }
      .tile{
            height:100px;
            width:100px;
            background-color: rgb(250, 250, 156);
            border:5px solid red;
        }

    </style>
    <body>
      <div class="container">
        <div class="tile"><p>Hello</p></div>
        <div class="tile"></div>
      </div>
    </body>
</html>
tsu
  • 1,122
  • 1
  • 10
  • 22