Center
and Display on Same Line

后端 未结 3 1677
野趣味
野趣味 2020-12-11 05:46

I\'m trying to display two

elements on the same line, but in the center. To center them, I had to set margin:auto; However, in order to
相关标签:
3条回答
  • 2020-12-11 06:17

    You can do this, but you'll need an explicit width on your outter div.

    Try this example:

    .outer {
      width: 200px;
      margin: 0 auto;  
    }
    
    .inner1 {
      float: left;
      background-color:
        red; padding: 20px;
    }
    .inner2 {
      float: left;
      background-color: aqua;
      padding: 20px;
    }
    <div class="outer">
      <div class="inner1">Hi</div>
      <div class="inner2">Stackoverflow</div>
    </div>

    Hope this helps!

    0 讨论(0)
  • 2020-12-11 06:31

    Have you tried display: inline-block;? An example of the HTML you are working with would help... put one up at http://jsFiddle.net if inline-block doesn't solve your problem.

    0 讨论(0)
  • 2020-12-11 06:34

    Wrap the two elements in another element. Set display:inline-block; for the inner elements and margin:0 auto; for the outer one.

    0 讨论(0)
提交回复
热议问题