TheQuestioner
TheQuestioner

Reputation: 722

Center an element with a right-float element with it

My problem is as simple as stupid. I have a <div> that holds 2 <p> on it, where the 2nd <p> has a float: right; value on it.

How can I center align the first <p> with the 2nd <p> on it side-by-side?

How it Looks Like now:
How it Looks Like now

.bubble_text {
  display: inline-block;
  padding: 1vw 3vw;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 20vw;
  text-align: center;
}
<div class="container">
  <p class="bubble_text">Center me Please</p>
  <p style="float: right;">&#10006;</p>
</div>

Upvotes: 0

Views: 63

Answers (3)

Lewis Hai
Lewis Hai

Reputation: 1214

Try this

HTML

<div class = "container">
  <p class = "bubble_text">Center me Please</p>
  <p style = "float: right;">&#10006;</p>
 </div>

CSS

container{
  text-align:center;
 }
.bubble_text {
  display: inline-block;
  padding: 1vw 3vw;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 20vw;
  vertical-align:middle;
  margin:0 auto;
}

Demo https://jsfiddle.net/jr9s7ayf/

Upvotes: 0

Jakub Mańkowski
Jakub Mańkowski

Reputation: 15

Try margin-left: auto; and margin-right: auto;

Upvotes: 0

Leo
Leo

Reputation: 14860

Just add text-align:center to the container element and you're good to go

.container{
  text-align:center;
  }
.bubble_text {
    display: inline-block;
    padding: 1vw 3vw;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 20vw;
    text-align: center;
  margin:0 auto;
}
<div class = "container">
    <p class = "bubble_text">Center me Please</p>
    <p style = "float: right;">&#10006;</p>
</div>

Upvotes: 1

Related Questions