使用右浮点元素将元素居中

时间:2015-12-18 07:44:17

标签: html css

我的问题就像愚蠢一样简单。我有一个<div>,其上有<p><p>,其中第二个float: right;上有<p>值。

如何将第一个<p>与第二个.bubble_text { display: inline-block; padding: 1vw 3vw; background-color: rgba(0, 0, 0, 0.1); border-radius: 20vw; text-align: center; }并排对齐?

现在看起来如何:
How it Looks Like now

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

3 个答案:

答案 0 :(得分:1)

只需将text-align:center添加到容器元素中,就可以了

.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>

答案 1 :(得分:0)

尝试margin-left:auto;和margin-right:auto;

答案 2 :(得分:0)

试试这个

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;
}

演示https://jsfiddle.net/jr9s7ayf/