Search code examples
htmlcsshtml-listsimage-gallery

how to align center list images


I need to align my li images in center. I have tried style="text-align: center;" in ul component. but it did not work. Thanks in advance.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<ul class="portfolioContainer row" style="text-align: center;">

  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=1.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=1.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=2.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=2.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=3.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;">  </i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=3.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=4.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=4.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=5.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=5.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=6.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=6.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=7.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=7s.jpg" alt=""> </div>
  </li>
  <li class="za  col-xs-6 col-sm-6 col-md-6 col-lg-4">
    <div class="lightCon"> <span class="hoverBox"> <span class="smallIcon"> <a rel="lightbox-demo" href="https://via.placeholder.com/50x50.png?text=8.jpg" title=" " class="zoom lb lb_warsaw1"><i class="fa fa-plus fa-2x" style="display: block;"></i></a> </span> </span> <img src="https://via.placeholder.com/50x50.png?text=8.jpg" alt=""> </div>
  </li>
</ul>


Solution

  • you can use flex-box o grid

    ul {
      display: grid;
      place-items: center;
    }
    
    ul {
      display: flex;
      align-items: center;
      justify-content: center;
    }