Center
and Display on Same Line

后端 未结 3 1713
野趣味
野趣味 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;
    }
    Hi
    Stackoverflow

    Hope this helps!

提交回复
热议问题