Click here to Skip to main content
15,895,709 members
Articles / Web Development / HTML
Tip/Trick

List Item in Single Line

Rate me:
Please Sign up or sign in to vote.
3.69/5 (13 votes)
15 May 2017CPOL 54.2K   3   7
List item in single line

Introduction

Default HTML <ul></ul> is living some padding and display all items in different line with list-style disks. So, many people want to list time in the same line without any list style.

Today, I am going to explain some CSS trick to display all the lists into the one line, i.e., when you want to show menu in your HTML, then you will write the following HTML code.

HTML
<ul>
   <li>Home</li>
   <li>Blog</li>
   <li>Faq</li>
   <li>About Us</li>
   <li>Contact Us</li>
</ul?

This will display output like:

  • Home
  • Blog
  • FAQ
  • About us
  • Contact us

Background

To display all the lists in one line, follow the following CSS code:

Solution 1

CSS
ul { 
   padding: 0px;
}
li {
   float: left;
   width: auto;
   list-style: outside none none;
}

When using this code, all elements will display in one line with float left. We have set width: auto so now list item will take width as per the content.

Solution 2

CSS
ul { 
   padding: 0px
}
li {
   display: inline-block;
   width: auto;
   list-style: outside none none;
}

When using this code, all elements will display in one line with display inline-block. We have set width: auto so now list item will take width as per the content.

After applying one of the above solutions, your menu will display like this:

Home Blog FAQ Contact us About us

So, enjoy with this solution now.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionworking solution Pin
Member 295683814-May-17 19:02
Member 295683814-May-17 19:02 
QuestionSo many typos and syntax errors Pin
Ch Smrutiranjan11-May-17 22:48
Ch Smrutiranjan11-May-17 22:48 
So many typos and syntax errors. Please correct them.

modified 12-May-17 4:54am.

AnswerRe: So many typos and syntax errors Pin
Uday A. Navapara15-May-17 0:38
professionalUday A. Navapara15-May-17 0:38 
Questionneeds some work Pin
Richard MacCutchan11-May-17 1:03
mveRichard MacCutchan11-May-17 1:03 
AnswerRe: needs some work Pin
Uday A. Navapara11-May-17 1:23
professionalUday A. Navapara11-May-17 1:23 
GeneralRe: needs some work Pin
Richard MacCutchan11-May-17 1:35
mveRichard MacCutchan11-May-17 1:35 
GeneralRe: needs some work Pin
Uday A. Navapara11-May-17 1:49
professionalUday A. Navapara11-May-17 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.