how to place last div into right top corner of parent div? (css)

前端 未结 5 1055
迷失自我
迷失自我 2020-12-14 05:35

Can I somehow use CSS to place the block2 in top right corner of block1?


Context :

  • block2
5条回答
  •  心在旅途
    2020-12-14 06:02

    Displaying left middle and right of there parents. If you have more then 3 elements then use nth-child() for them.

    HTML sample:

    
        
    
    

    CSS sample:

    .nav-tabs{
      position: relative;
      padding-bottom: 50px;
    }
    .nav-tabs li {
      display: inline-block;  
      position: absolute;
      list-style: none;
    }
    .nav-tabs li:first-child{
      top: 0px;
      left: 0px;
    }
    .nav-tabs li:last-child{
      top: 0px;
      right: 0px;
    }
    .nav-tabs li:nth-child(2){
      top: 0px;
      left: 50%;
      transform: translate(-50%, 0%);
    }
    

提交回复
热议问题