Home > Web Front-end > CSS Tutorial > How to Horizontally Display `` List Items Using CSS?

How to Horizontally Display `` List Items Using CSS?

Linda Hamilton
Release: 2024-12-11 06:02:16
Original
354 people have browsed it

How to Horizontally Display `` List Items Using CSS?

How to Make a <ul> Display in a Horizontal Row

In HTML, list items are typically displayed as block elements, which means they appear one on top of the other. However, you can use CSS to change the display property of list items to inline, which will cause them to display side-by-side on the same line.

To change the display property of list items, you can use the following CSS rule:

li {
    display: inline;
}
Copy after login

You can also use a context selector to apply the inline display property to list items within a specific <ul> element, like this:

#ul-id li {
    display: inline;
}
Copy after login

Here is an example of how to use the inline display property to make a <ul> display in a horizontal row:

<ul>
Copy after login
#ul-id {
    display: inline;
}

#ul-id li {
    display: inline;
}
Copy after login

This code will result in the following output:

Item 1 Item 2 Item 3
Copy after login

As you can see, the list items are now displayed in a horizontal row.

The above is the detailed content of How to Horizontally Display `` List Items Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template