ul The li tag is used a lot in pages. Today, this article will share with you a little trick in the li tag. How to center the li in ul horizontally and vertically, interested friends can refer to it, I hope it will be useful to you.
When we write carousel images, the small dots or numbers at the bottom will be placed in a ul lower li. At this time, the small dots or numbers are generally required to be vertically centered. Today we will write one Simple li centered horizontally and vertically in ul.
There are generally two types of carousel images, left and right carousel and up and down carousel. The corresponding li in ul is also divided into horizontal arrangement and vertical arrangement. The two situations are explained below.
1. Carousel images rotate left and right, li arranged horizontally:
<div class="box"> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </div> .box{ width: 100%; height: 200px; border: 1px solid red; } .box ul{ height: 200px; display: flex; flex-direction: row; justify-content: center; } .box ul li{ list-style: none; height: 200px; line-height: 200px; }
Effect:
##2. Carousel images rotate up and down, li arranged vertically:
<div class="box1"> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </div> .box1{ width: 100px; height: 300px; border: 1px solid red; } .box1 ul{ height: 300px; display: flex; flex-direction: column; justify-content: center; } .box1 ul li{ list-style: none; margin: 0 auto; }
The above is the detailed content of Detailed graphic explanation on how to center the li in ul horizontally and vertically. For more information, please follow other related articles on the PHP Chinese website!