How do I center floated elements?

前端 未结 12 2578
谎友^
谎友^ 2020-11-22 00:16

I\'m implementing pagination, and it needs to be centered. The problem is that the links need to be displayed as block, so they need to be floated. But then, text-alig

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 00:56

    Using Flex

    .pagination {
      text-align: center;
      display:flex;
      justify-content:center;
    }
    .pagination a {
      display: block;
      width: 30px;
      height: 30px;
      float: left;
      margin-left: 3px;
      background: url(/images/structure/pagination-button.png);
    }
    .pagination a.last {
      width: 90px;
      background: url(/images/structure/pagination-button-last.png);
    }
    .pagination a.first {
      width: 60px;
      background: url(/images/structure/pagination-button-first.png);
    }
    
    

提交回复
热议问题