Detailed graphic explanation on how to center the li in ul horizontally and vertically

yulia
Release: 2018-09-25 11:23:12
Original
8620 people have browsed it

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;
        }
Copy after login

Effect:

Detailed graphic explanation on how to center the li in ul horizontally and vertically

##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;
            }
Copy after login
Effect:

Detailed graphic explanation on how to center the li in ul horizontally and vertically

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!