0

.right {
  float: right;
  border: 3px solid #73AD21;
}
<div>
  <div class="right">
    <p>testtesttest.</p>
  </div>
  <div style="text-align: center;">
    <h2>Middle</h2>
    <p>blablabla</p>
  </div>
</div>

I want that the Middle is centered and the other box is on the right. In my code the Middle is not centered. How can I do that?

Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49
SkullKid
  • 35
  • 5

2 Answers2

1

I hope this is what you are expecting.

.text {
  text-align: center;
  background-color: red;
}

.container {
  position: relative;
}

.right {
  position: absolute;
  right: 0;
  width: fit-content;
  text-align: center;
  top: 50%;
  transform: translateY(-50%);
  border: 3px solid #73AD21;
}
<div class="container">
  <div class="right">
    <p>testtesttest.</p>
  </div>
  <div class="text">
    <h2>Middle</h2>
    <p>blablabla</p>
  </div>
</div>
Amaresh S M
  • 2,936
  • 2
  • 13
  • 25
1

U mean to have it look something like this ? But this has BIG drawback, that if caption is too long it will overflow the div on the right.

.main {
  position: relative;
}

.right {
  //float: right;
  position: absolute;
  right: 0;
  border: 3px solid #73AD21;
}
<div class="main">
  <div class="right">
    <p>testtesttest.</p>
  </div>
  <div style="text-align: center;">
    <h2>Middle</h2>
    <p>blablabla</p>
  </div>
</div>
Kovo
  • 434
  • 4
  • 14