How to get a div centered with another div on the right of it?

前端 未结 4 1448
半阙折子戏
半阙折子戏 2020-12-22 13:38

I\'m trying to make a centered div with another div on the right of it. So the div on the left is horizontal centered. De div

4条回答
  •  时光取名叫无心
    2020-12-22 14:26

    This is using absolute positions. Please not that the amount of left:150px; is the half width of centered div + half width of left div. Also the style margin-left:200px; on the lef div, comes from the width of centered div.

    .container {
      position: relative;
    }
    
    .centered {
      width: 200px;
      background: #eeeeee;
      position: absolute;
      height: 100px;
      margin: auto;
      left: 0;
      right: 0;
    }
    
    .leftOf {
      background: #ff8800;
      position: absolute;
      left: 150px;
      margin-left: 200px;
      height: 100px;
      width: 100px
    }

提交回复
热议问题